From c0bb4e3b2c3a547dfbbb34890a52f99fb12ebcd2 Mon Sep 17 00:00:00 2001
From: Maarten de Waard <maarten@greenhost.nl>
Date: Mon, 12 Apr 2021 11:47:46 +0200
Subject: [PATCH] try using my custom disk image for CI

TRIGGER_JOBS=ci-test-image-build
---
 .gitlab/ci_scripts/create_vps.sh | 1 +
 openappstack/__main__.py         | 8 ++++++++
 openappstack/cluster.py          | 4 +++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/.gitlab/ci_scripts/create_vps.sh b/.gitlab/ci_scripts/create_vps.sh
index ab6df85f5..55f058d18 100644
--- a/.gitlab/ci_scripts/create_vps.sh
+++ b/.gitlab/ci_scripts/create_vps.sh
@@ -16,4 +16,5 @@ python3 -m openappstack $HOSTNAME create \
   --ssh-key-id $SSH_KEY_ID \
   --create-domain-records \
   --subdomain $SUBDOMAIN \
+  --disk-image-id '-7121' \
   --truncate-subdomain
diff --git a/openappstack/__main__.py b/openappstack/__main__.py
index d68a9a9ba..70783f796 100755
--- a/openappstack/__main__.py
+++ b/openappstack/__main__.py
@@ -147,6 +147,11 @@ def main():  # pylint: disable=too-many-statements,too-many-branches,too-many-lo
         help=("Use this for development clusters. Uses an in-cluster "
               'auto-update feed'))
 
+    droplet_creation_group.add_argument(
+        '--disk-image-id',
+        help=("Custom disk image ID. Use negative value for a custom template "
+              "ID, use positive values for operating system IDs"))
+
     install_parser = subparsers.add_parser(
         'install',
         help=("Use this to run the ansible playbook that sets up your VPS to run "
@@ -312,6 +317,9 @@ def create(clus, args):  # pylint: disable=too-many-branches
 
     clus.domain = fqdn
 
+    if args.disk_image_id:
+        clus.disk_image_id = args.disk_image_id
+
     # Set acme_staging to False so we use Let's Encrypt's live environment
     if args.acme_staging:
         clus.acme_staging = True
diff --git a/openappstack/cluster.py b/openappstack/cluster.py
index d106dfff8..44cc0364b 100644
--- a/openappstack/cluster.py
+++ b/openappstack/cluster.py
@@ -65,6 +65,8 @@ class Cluster:
         # Load data from inventory.yml and settings.yml
         if load_data:
             self.load_data()
+        # Can be used to use a custom disk image.
+        self.disk_image_id = DEFAULT_IMAGE
 
     def load_data(self):
         """
@@ -119,7 +121,7 @@ class Cluster:
             region=DEFAULT_REGION,
             size=ram,
             disk=DEFAULT_DISK_SIZE_GB,
-            image=DEFAULT_IMAGE)
+            image=self.disk_image_id)
         droplet_id = droplet['droplet']['id']
         log.info('Created droplet id: %s', droplet_id)
         greenhost_cloud.wait_for_state(droplet_id, 'running')
-- 
GitLab