From 9066690daf6cfaceed855aa25b2488f11db5a146 Mon Sep 17 00:00:00 2001
From: "Anderson, Craig (ca846m)" <ca846m@att.com>
Date: Fri, 19 Mar 2021 11:31:28 -0700
Subject: [PATCH] Streamline naming and fix qcow-bundle tag naming

Fix an issue with qcow-bundle naming that was causing docker registry
info to be dropped.

Dropped redundant "qcow" prefix for qcow-bundle subdirectories.

Use qcow-bundle subdirectory as image name.

Rename "config" directory as "manifests" per offline review request.

Change-Id: Ie110923b3c8d5a825dd7a199658722b853018d97
---
 image-builder/Makefile                        | 16 +++++------
 image-builder/config                          |  1 +
 .../qcow-bundle/qcow-control-plane/img_name   |  1 -
 .../qcow-bundle/qcow-data-plane/img_name      |  1 -
 .../qcow-control-plane-vars.yaml              |  1 -
 image-builder/{config => manifests}/README.md | 27 +++++++++----------
 .../{config => manifests}/iso/README.md       |  0
 .../iso/network_data.json                     |  0
 .../{config => manifests}/iso/user_data       |  0
 .../qcow-bundle/README.md                     |  0
 .../qcow-bundle/control-plane}/README.md      |  0
 .../control-plane/osconfig-vars.yaml}         |  0
 .../qcow-bundle/control-plane/qcow-vars.yaml} |  0
 .../qcow-bundle/data-plane}/README.md         |  0
 .../data-plane/osconfig-vars.yaml}            |  0
 .../qcow-bundle/data-plane/qcow-vars.yaml     |  1 +
 .../{config => manifests}/rootfs/README.md    |  0
 .../rootfs/livecdcontent-vars.yaml            |  0
 .../rootfs/multistrap-vars.yaml               |  0
 .../rootfs/osconfig-vars.yaml                 |  0
 .../scripts/common/README.md                  |  0
 .../scripts/qcow/README.md                    |  0
 image-builder/tools/cut_image.sh              |  4 +--
 image-builder/tools/multistrap.sh             |  2 +-
 24 files changed, 24 insertions(+), 30 deletions(-)
 create mode 120000 image-builder/config
 delete mode 100644 image-builder/config/qcow-bundle/qcow-control-plane/img_name
 delete mode 100644 image-builder/config/qcow-bundle/qcow-data-plane/img_name
 delete mode 120000 image-builder/config/qcow-bundle/qcow-data-plane/qcow-control-plane-vars.yaml
 rename image-builder/{config => manifests}/README.md (58%)
 rename image-builder/{config => manifests}/iso/README.md (100%)
 rename image-builder/{config => manifests}/iso/network_data.json (100%)
 rename image-builder/{config => manifests}/iso/user_data (100%)
 rename image-builder/{config => manifests}/qcow-bundle/README.md (100%)
 rename image-builder/{config/qcow-bundle/qcow-control-plane => manifests/qcow-bundle/control-plane}/README.md (100%)
 rename image-builder/{config/qcow-bundle/qcow-control-plane/osconfig-control-plane-vars.yaml => manifests/qcow-bundle/control-plane/osconfig-vars.yaml} (100%)
 rename image-builder/{config/qcow-bundle/qcow-control-plane/qcow-control-plane-vars.yaml => manifests/qcow-bundle/control-plane/qcow-vars.yaml} (100%)
 rename image-builder/{config/qcow-bundle/qcow-data-plane => manifests/qcow-bundle/data-plane}/README.md (100%)
 rename image-builder/{config/qcow-bundle/qcow-data-plane/osconfig-data-plane-vars.yaml => manifests/qcow-bundle/data-plane/osconfig-vars.yaml} (100%)
 create mode 120000 image-builder/manifests/qcow-bundle/data-plane/qcow-vars.yaml
 rename image-builder/{config => manifests}/rootfs/README.md (100%)
 rename image-builder/{config => manifests}/rootfs/livecdcontent-vars.yaml (100%)
 rename image-builder/{config => manifests}/rootfs/multistrap-vars.yaml (100%)
 rename image-builder/{config => manifests}/rootfs/osconfig-vars.yaml (100%)
 rename image-builder/{config => manifests}/scripts/common/README.md (100%)
 rename image-builder/{config => manifests}/scripts/qcow/README.md (100%)

diff --git a/image-builder/Makefile b/image-builder/Makefile
index d6c2fda..d8c61e6 100644
--- a/image-builder/Makefile
+++ b/image-builder/Makefile
@@ -22,7 +22,7 @@ IMAGE_TAG	?= latest
 IMAGE_TYPE	?= iso # iso | qcow
 PUSH_IMAGE	?= false
 DISTRO          ?= ubuntu_focal
-WORKDIR         ?= ./config
+WORKDIR         ?= ./manifests
 QCOW_BUNDLE     ?= ${WORKDIR}/qcow-bundle
 # Specify if you want to only build a certain subset of QCOW bundles
 QCOW_BUNDLE_DIRS  ?=
@@ -114,15 +114,11 @@ else
 	# Assemble all images based on configs defined in each subdirectory
 	iterDirs=`find $(QCOW_BUNDLE) -maxdepth 1 -mindepth 1 -type d -exec basename {} \;`
 	for subdir in $$iterDirs; do
-	    # ISO configs
-	    export user_data=$(QCOW_BUNDLE)/$$subdir/user_data
-	    export network_config=$(QCOW_BUNDLE)/$$subdir/network_data.json
 	    # QCOW configs
-	    qcow_type=$$(echo $$subdir | sed -e "s/^qcow-//")
-	    export osconfig_params="$(QCOW_BUNDLE)/$$subdir/osconfig-$$qcow_type-vars.yaml"
-	    export qcow_params="$(QCOW_BUNDLE)/$$subdir/qcow-$$qcow_type-vars.yaml"
-	    # Shared configs
-	    export img_name=$$(cat $(QCOW_BUNDLE)/$$subdir/img_name)
+	    export osconfig_params="$(QCOW_BUNDLE)/$$subdir/osconfig-vars.yaml"
+	    export qcow_params="$(QCOW_BUNDLE)/$$subdir/qcow-vars.yaml"
+	    # Image name
+	    export img_name=$$subdir.qcow2
 	    sudo -E tools/cut_image.sh $(IMAGE_TYPE) $(QCOW_BUNDLE) $(IMAGE) "$(PROXY)" "$(NO_PROXY)"
 	done
 endif
@@ -144,7 +140,7 @@ endif
 	for bundledir in $$bundleDirs; do
 	    export QCOW_BUNDLE="$(WORKDIR)/$$bundledir"
 	    sudo -E make cut_image
-	    sudo -E DOCKER_BUILDKIT=1 docker -D -l debug build --tag $$bundledir -f Dockerfile-qcow.$(DISTRO) $(WORKDIR)/$$bundledir \
+	    sudo -E DOCKER_BUILDKIT=1 docker -D -l debug build --tag $(DOCKER_REGISTRY)/$(IMAGE_PREFIX)/$$bundledir:$(IMAGE_TAG)-$(DISTRO) -f Dockerfile-qcow.$(DISTRO) $(WORKDIR)/$$bundledir \
 	    --label $(LABEL) \
 	    --label "org.opencontainers.image.revision=$(COMMIT)" \
 	    --label "org.opencontainers.image.created=\
diff --git a/image-builder/config b/image-builder/config
new file mode 120000
index 0000000..43c9134
--- /dev/null
+++ b/image-builder/config
@@ -0,0 +1 @@
+manifests/
\ No newline at end of file
diff --git a/image-builder/config/qcow-bundle/qcow-control-plane/img_name b/image-builder/config/qcow-bundle/qcow-control-plane/img_name
deleted file mode 100644
index bf1c531..0000000
--- a/image-builder/config/qcow-bundle/qcow-control-plane/img_name
+++ /dev/null
@@ -1 +0,0 @@
-control-plane.qcow2
diff --git a/image-builder/config/qcow-bundle/qcow-data-plane/img_name b/image-builder/config/qcow-bundle/qcow-data-plane/img_name
deleted file mode 100644
index 8783b83..0000000
--- a/image-builder/config/qcow-bundle/qcow-data-plane/img_name
+++ /dev/null
@@ -1 +0,0 @@
-data-plane.qcow2
diff --git a/image-builder/config/qcow-bundle/qcow-data-plane/qcow-control-plane-vars.yaml b/image-builder/config/qcow-bundle/qcow-data-plane/qcow-control-plane-vars.yaml
deleted file mode 120000
index bd56328..0000000
--- a/image-builder/config/qcow-bundle/qcow-data-plane/qcow-control-plane-vars.yaml
+++ /dev/null
@@ -1 +0,0 @@
-../qcow-control-plane/qcow-control-plane-vars.yaml
\ No newline at end of file
diff --git a/image-builder/config/README.md b/image-builder/manifests/README.md
similarity index 58%
rename from image-builder/config/README.md
rename to image-builder/manifests/README.md
index 36cbe8a..12dd4c5 100644
--- a/image-builder/config/README.md
+++ b/image-builder/manifests/README.md
@@ -1,29 +1,29 @@
 Directory structure:
 
-|-- config
+```
+|-- manifests
   |-- iso
     +-- network_data.json
     +-- user_data
   |-- qcow-bundle
-    |-- qcow-control-plane
-      +-- img_name
-      +-- osconfig-control-plane-vars.yaml
-      +-- qcow-control-plane-vars.yaml
-    |-- qcow-data-plane
-      +-- img_name
-      +-- osconfig-control-plane-vars.yaml
-      +-- qcow-control-plane-vars.yaml
+    |-- control-plane
+      +-- osconfig-vars.yaml
+      +-- qcow-vars.yaml
+    |-- data-plane
+      +-- osconfig-vars.yaml
+      +-- qcow-vars.yaml
+```
 
 The `generate_iso` and `package_qcow` make target can be used to build ISO and
 QCOW artifacts respectively, after the shared `image-builder` container is
 built (built with the `build` target).
 
-The ISO always builds out of the `config/iso` directory, because this is only
+The ISO always builds out of the `manifests/iso` directory, because this is only
 used for local testing. It is not an artifact that is promoted or published.
 
 QCOWs are grouped into publishable "bundles", i.e. a container image where all
 QCOWs needed for a given deployment are stored. A bundle will be built for each
-`config/qcow-bundle*` directory. Each `config/qcow-bundle*` directory contains
+`manifests/qcow-bundle*` directory. Each `manifests/qcow-bundle*` directory contains
 one subdirectory per QCOW that is part of that bundle, where overrides for
 those images can be placed.
 
@@ -32,6 +32,5 @@ The following items are expected in the `iso` directory:
 - `network_data.json` - JSON file containing cloud-init network data
 
 QCOWs expect the following files to be present in their directory:
-- `img_name` - text file containing the desired name for the image
-- `osconfig-*-vars.yaml` - YAML file containing `osconfig` playbook overrides
-- `qcow-*-vars.yaml` - YAML file containing `qcow` playboook overrides
+- `osconfig-vars.yaml` - YAML file containing `osconfig` playbook overrides
+- `qcow-vars.yaml` - YAML file containing `qcow` playboook overrides
diff --git a/image-builder/config/iso/README.md b/image-builder/manifests/iso/README.md
similarity index 100%
rename from image-builder/config/iso/README.md
rename to image-builder/manifests/iso/README.md
diff --git a/image-builder/config/iso/network_data.json b/image-builder/manifests/iso/network_data.json
similarity index 100%
rename from image-builder/config/iso/network_data.json
rename to image-builder/manifests/iso/network_data.json
diff --git a/image-builder/config/iso/user_data b/image-builder/manifests/iso/user_data
similarity index 100%
rename from image-builder/config/iso/user_data
rename to image-builder/manifests/iso/user_data
diff --git a/image-builder/config/qcow-bundle/README.md b/image-builder/manifests/qcow-bundle/README.md
similarity index 100%
rename from image-builder/config/qcow-bundle/README.md
rename to image-builder/manifests/qcow-bundle/README.md
diff --git a/image-builder/config/qcow-bundle/qcow-control-plane/README.md b/image-builder/manifests/qcow-bundle/control-plane/README.md
similarity index 100%
rename from image-builder/config/qcow-bundle/qcow-control-plane/README.md
rename to image-builder/manifests/qcow-bundle/control-plane/README.md
diff --git a/image-builder/config/qcow-bundle/qcow-control-plane/osconfig-control-plane-vars.yaml b/image-builder/manifests/qcow-bundle/control-plane/osconfig-vars.yaml
similarity index 100%
rename from image-builder/config/qcow-bundle/qcow-control-plane/osconfig-control-plane-vars.yaml
rename to image-builder/manifests/qcow-bundle/control-plane/osconfig-vars.yaml
diff --git a/image-builder/config/qcow-bundle/qcow-control-plane/qcow-control-plane-vars.yaml b/image-builder/manifests/qcow-bundle/control-plane/qcow-vars.yaml
similarity index 100%
rename from image-builder/config/qcow-bundle/qcow-control-plane/qcow-control-plane-vars.yaml
rename to image-builder/manifests/qcow-bundle/control-plane/qcow-vars.yaml
diff --git a/image-builder/config/qcow-bundle/qcow-data-plane/README.md b/image-builder/manifests/qcow-bundle/data-plane/README.md
similarity index 100%
rename from image-builder/config/qcow-bundle/qcow-data-plane/README.md
rename to image-builder/manifests/qcow-bundle/data-plane/README.md
diff --git a/image-builder/config/qcow-bundle/qcow-data-plane/osconfig-data-plane-vars.yaml b/image-builder/manifests/qcow-bundle/data-plane/osconfig-vars.yaml
similarity index 100%
rename from image-builder/config/qcow-bundle/qcow-data-plane/osconfig-data-plane-vars.yaml
rename to image-builder/manifests/qcow-bundle/data-plane/osconfig-vars.yaml
diff --git a/image-builder/manifests/qcow-bundle/data-plane/qcow-vars.yaml b/image-builder/manifests/qcow-bundle/data-plane/qcow-vars.yaml
new file mode 120000
index 0000000..b53e28d
--- /dev/null
+++ b/image-builder/manifests/qcow-bundle/data-plane/qcow-vars.yaml
@@ -0,0 +1 @@
+../control-plane/qcow-vars.yaml
\ No newline at end of file
diff --git a/image-builder/config/rootfs/README.md b/image-builder/manifests/rootfs/README.md
similarity index 100%
rename from image-builder/config/rootfs/README.md
rename to image-builder/manifests/rootfs/README.md
diff --git a/image-builder/config/rootfs/livecdcontent-vars.yaml b/image-builder/manifests/rootfs/livecdcontent-vars.yaml
similarity index 100%
rename from image-builder/config/rootfs/livecdcontent-vars.yaml
rename to image-builder/manifests/rootfs/livecdcontent-vars.yaml
diff --git a/image-builder/config/rootfs/multistrap-vars.yaml b/image-builder/manifests/rootfs/multistrap-vars.yaml
similarity index 100%
rename from image-builder/config/rootfs/multistrap-vars.yaml
rename to image-builder/manifests/rootfs/multistrap-vars.yaml
diff --git a/image-builder/config/rootfs/osconfig-vars.yaml b/image-builder/manifests/rootfs/osconfig-vars.yaml
similarity index 100%
rename from image-builder/config/rootfs/osconfig-vars.yaml
rename to image-builder/manifests/rootfs/osconfig-vars.yaml
diff --git a/image-builder/config/scripts/common/README.md b/image-builder/manifests/scripts/common/README.md
similarity index 100%
rename from image-builder/config/scripts/common/README.md
rename to image-builder/manifests/scripts/common/README.md
diff --git a/image-builder/config/scripts/qcow/README.md b/image-builder/manifests/scripts/qcow/README.md
similarity index 100%
rename from image-builder/config/scripts/qcow/README.md
rename to image-builder/manifests/scripts/qcow/README.md
diff --git a/image-builder/tools/cut_image.sh b/image-builder/tools/cut_image.sh
index 6c212c9..8cf49cc 100755
--- a/image-builder/tools/cut_image.sh
+++ b/image-builder/tools/cut_image.sh
@@ -12,7 +12,7 @@ BASEDIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
 # Whether to build an 'iso' or 'qcow'
 build_type="${1:-qcow}"
 # The host mount to use to exchange data with this container
-host_mount_directory="${2:-$BASEDIR/../config}"
+host_mount_directory="${2:-$BASEDIR/../manifests}"
 # Docker image to use when launching this container
 image="${3:-port/image-builder:latest-ubuntu_focal}"
 # proxy to use, if applicable
@@ -89,7 +89,7 @@ outputFileName: $img_name" > ${iso_config}
   disk1="--disk path=${workdir}/${img_name},device=cdrom"
   network='--network network=default,mac=52:54:00:6c:99:85'
 elif [[ $build_type == qcow ]]; then
-  : ${img_name:=$(cat $(dirname ${osconfig_params})/img_name)}
+  : ${img_name:=airship-ubuntu.qcow}
   if sudo virsh list | grep ${img_name}; then
     sudo virsh destroy ${img_name}
   fi
diff --git a/image-builder/tools/multistrap.sh b/image-builder/tools/multistrap.sh
index 3922a10..3e2ae9a 100755
--- a/image-builder/tools/multistrap.sh
+++ b/image-builder/tools/multistrap.sh
@@ -12,7 +12,7 @@ BASEDIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
 
 build_dir=assets/playbooks/build
 osconfig_build_dir=$(basename $build_dir)
-host_mount_directory="${1:-$BASEDIR/../config}"
+host_mount_directory="${1:-$BASEDIR/../manifests}"
 workdir="$(realpath ${host_mount_directory})"
 
 install_pkg(){