It’s possible to provision a custom image on GCE with Replicated and Swarm pre-installed to simplify or speed up instance creation. This example works with distributions that use SystemD such as CentOS 7 or Debian 9.
First start up the base image and ssh into it:
gcloud compute instances create base --image-family=centos-7 --image-project=centos-cloud
gcloud compute ssh base
On the instance, install replicated with swarm as usual:
curl -sSL -o install.sh https://get.replicated.com/swarm-init
sudo bash ./install.sh no-proxy public-address=' '
Create a script to update the local address in the Replicated and Replicated Operator services and save it to /usr/bin/replicated-startup
:
#!/bin/bash
LOCAL_ADDRESS=$(hostname --ip-address)
docker service update replicated_replicated --env-add LOCAL_ADDRESS=${LOCAL_ADDRESS}
docker service update replicated_replicated-operator --env-add DAEMON_REGISTRY_ENDPOINT=${LOCAL_ADDRESS}:9874
docker service update replicated_replicated-operator --image "${LOCAL_ADDRESS}:9874/replicated/replicated-operator:stable-$(replicatedctl version --quiet)"
Create a SystemD unit file that calls this script after Docker has started and save it as /etc/systemd/system/replicated-startup.service
:
[Unit]
Description=Rewrite local address in Replicated services
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
ExecStart=/usr/bin/replicated-startup
[Install]
WantedBy=multi-user.target
Enable the service with systemctl enable replicated-startup.service
.
Back on your dev machine, stop the instance and create an image from it:
gcloud compute instances stop base
gcloud compute images create swarm --image=base