Creating a GCE Image for Native


#1

It’s possible to provision a custom image on GCE with Replicated and Docker 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 as usual:

curl -sSL -o install.sh https://get.replicated.com/docker
sudo bash ./install.sh no-proxy

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)

sed -i -r 's/(\b[0-9]{1,3}\.){3}[0-9]{1,3}\b'/$LOCAL_ADDRESS/ /etc/sysconfig/replicated
sed -i -r 's/(\b[0-9]{1,3}\.){3}[0-9]{1,3}\b'/$LOCAL_ADDRESS/ /etc/sysconfig/replicated-operator
sed -i -r 's/\s?-e PUBLIC_ADDRESS=[^ "]+'// /etc/sysconfig/replicated-operator

Create a SystemD unit file that calls this script before Replicated starts and save it as /etc/systemd/system/replicated-startup.service:

[Unit]
Description=Rewrite local address in Replicated services
Before=replicated.service replicated-ui.service replicated-operator.service
Requires=replicated.service replicated-ui.service replicated-operator.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 replicated-native --image=base