diff --git a/Makefile b/Makefile index 9690f6b..0f8d751 100644 --- a/Makefile +++ b/Makefile @@ -15,31 +15,31 @@ ubuntu-build: docker build . -f Dockerfile.ubuntu -t $(IMAGE_NAME):$(IMAGE_VERSION_LATEST) build-images: - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/base ; ./packer-build.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/docker; ./packer-build.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/base ; ./packer-build.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/docker ; ./packer-build.sh" + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/ubuntu/bionic/base " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/ubuntu/bionic/docker " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/centos/7/base " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/centos/7/docker " cleanup: - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/base ; ./packer-delete.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/docker; ./packer-delete.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/base ; ./packer-delete.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/docker ; ./packer-delete.sh" + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/ubuntu/bionic/base " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/ubuntu/bionic/docker" + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/centos/7/base " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/centos/7/docker " ubuntu-bionic-base: - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/base ; ./packer-build.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/base ; ./packer-delete.sh" + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/ubuntu/bionic/base " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/ubuntu/bionic/base " ubuntu-bionic-docker: - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/docker; ./packer-build.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/ubuntu/bionic/docker; ./packer-delete.sh" + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/ubuntu/bionic/docker " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/ubuntu/bionic/docker" centos-7-base: - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/base ; ./packer-build.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/base ; ./packer-delete.sh" + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/centos/7/base " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/centos/7/base " centos-7-docker: - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/docker ; ./packer-build.sh" - docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "cd packer/centos/7/docker ; ./packer-delete.sh" + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-build.sh packer/centos/7/docker " + docker run --privileged -v `pwd`:/ibmcloud-image-builder ${IMAGE_NAME}:${IMAGE_VERSION_LATEST} /bin/bash -c "./packer-delete.sh packer/centos/7/docker " .PHONY: all diff --git a/README.md b/README.md index 7ce6a17..02fa7e7 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,41 @@ https://hub.docker.com/r/syibm/ibmcloud-image-builder -# v0.1.0 Release Readiness: Planned to release on 07/06/2020 -The first official release: v0.1.0 -- [x] templates for base and docker per each OS : Ubuntu 18.04, CentOS 7 -- [x] CI build -- [x] github releases is ready -- [x] github packages is ready -- [x] DockerHub image repository: https://hub.docker.com/r/syibm/ibmcloud-image-builder +# Try it out + +This project is set up to run on Mac or Linux. + +## Dependencies + +Before you can build a custom image you must install the following dependencies: + +* [Docker](https://www.docker.com/products/docker-desktop) +* make + +### Installing make on macOS + +To install the `make` command on macOS, you need to install the Xcode command line tools by executing the following command in your terminal: + +``` +xcode-select --install +``` + +When the dialog pops up click on the *Install* button. + +## Building your first custom image + +Start by pulling an already built image from the Docker registry. This will download, encrypt, and package the image for deployment. + +``` +git clone git@github.com:IBM-Cloud/ibmcloud-image-builder.git +cd ibmcloud-image-builder +docker pull syibm/ibmcloud-image-builder +docker tag syibm/ibmcloud-image-builder ibmcloud-image-builder +make build-images +``` + + # Motivation @@ -102,7 +129,7 @@ $ docker tag syibm/ibmcloud-image-builder ibmcloud-image-builder $ make build-images ``` -With building the dev docker: +Or we can build the docker image(`make build`) locally as below: ``` $ git clone git@github.com:IBM-Cloud/ibmcloud-image-builder.git $ cd ibmcloud-image-builder @@ -115,16 +142,13 @@ The extra `docker` templates in addtion to `base` templates are for the informat 1. copy the existing folder and rename the directory 2. change either shell/user-data.sh or ansible/playbook.yml -3. change the image name in packer-builder.sh ... hmm, this needs to be refactored later. - # How to build an encrypted image with your DEK (Data Encryption Key) By default all the images will be encrypted with a given `encryption key`: `JustMySimpleSecret`. If the image required to be encrypted with a different encryption key, then attach to the build docker, and ``` -cd "proper directory" -./packer-build.sh "Your DEK here" +./packer-build.sh packer/os/platform "Your DEK here" ``` ``` @@ -135,19 +159,15 @@ $ tree -L 5 │ ├── base │ │ ├── ansible │ │ │ └── playbook.yml -│ │ ├── centos.json │ │ ├── http -│ │ ├── packer-build.sh -│ │ ├── packer-delete.sh +│ │ ├── packer.json │ │ └── shell │ │ └── user-data.sh │ └── docker │ ├── ansible │ │ └── playbook.yml -│ ├── centos.json │ ├── http -│ ├── packer-build.sh -│ ├── packer-delete.sh +│ ├── packer.json │ └── shell │ └── user-data.sh └── ubuntu @@ -156,24 +176,20 @@ $ tree -L 5 │ │ ├── ansible │ │ │ └── playbook.yml │ │ ├── http - │ │ ├── packer-build.sh - │ │ ├── packer-delete.sh - │ │ ├── shell - │ │ │ └── user-data.sh - │ │ └── ubuntu.json + │ │ ├── packer.json + │ │ └── shell + │ │ └── user-data.sh │ └── docker │ ├── ansible │ │ └── playbook.yml │ ├── http - │ ├── packer-build.sh - │ ├── packer-delete.sh - │ ├── shell - │ │ └── user-data.sh - │ └── ubuntu.json + │ ├── packer.json + │ └── shell + │ └── user-data.sh ├── focal └── xenial -22 directories, 20 files +22 directories, 12 files ``` # Example Virtual Server Instance created with the custom image generated with one of the templates diff --git a/packer/centos/7/base/packer-build.sh b/packer-build.sh similarity index 73% rename from packer/centos/7/base/packer-build.sh rename to packer-build.sh index 4c5e628..98cd903 100755 --- a/packer/centos/7/base/packer-build.sh +++ b/packer-build.sh @@ -1,7 +1,21 @@ #!/bin/bash set -ex + +# change directory +cd $1 + # prepare to build +DIR_TO_FILENAME=$(echo "$1" | sed 's#packer/##g' | tr '/' '-') +NEW_IMAGE="output-qemu/ibmcloud-$DIR_TO_FILENAME-amd64-100G.qcow2" +ENCRYPTED_IMAGE="output-qemu/ibmcloud-encrypted-$DIR_TO_FILENAME-amd64-100G.qcow2" + +if [ -n "$2" ]; then + SECRET="$2" +else + SECRET="JustMySimpleSecret" +fi +# prepare ssh keys if [[ -f "~/.ssh/id_rsa.pub" ]]; then export PACKER_PUBLIC_KEY=~/.ssh/id_rsa.pub export PACKER_PRIVATE_KEY=~/.ssh/id_rsa @@ -29,25 +43,16 @@ cloud-localds disk-ssh-pub.img user-data ansible-galaxy install geerlingguy.docker # build the images -# base -PACKER_LOG=0 packer build centos.json +PACKER_LOG=0 packer build packer.json -# Time to make the below as a function at the next PR -NEW_IMAGE="output-qemu/ibmcloud-centos-7-cloudimg-amd64-100G.qcow2" -ENCRYPTED_IMAGE="output-qemu/ibmcloud-centos-7-cloudimg-amd64-100G-encrypted.qcow2" - -qemu-img resize output-qemu/centos-7.qcow2 100G -qemu-img convert -f qcow2 -O qcow2 output-qemu/centos-7.qcow2 ${NEW_IMAGE} +qemu-img resize output-qemu/packer.qcow2 100G +qemu-img convert -f qcow2 -O qcow2 output-qemu/packer.qcow2 ${NEW_IMAGE} qemu-img info ${NEW_IMAGE} -rm output-qemu/centos-7.qcow2 +rm output-qemu/packer.qcow2 # create an example encrypted image -if [ -n "$1" ]; then - SECRET="$1" -else - SECRET="JustMySimpleSecret" -fi + BASE64_ENCODED_SECRET=$(echo -n $SECRET | base64) qemu-img convert -O qcow2 \ diff --git a/packer/centos/7/docker/packer-delete.sh b/packer-delete.sh similarity index 95% rename from packer/centos/7/docker/packer-delete.sh rename to packer-delete.sh index 24b7b5b..170d3c1 100755 --- a/packer/centos/7/docker/packer-delete.sh +++ b/packer-delete.sh @@ -1,6 +1,6 @@ #!/bin/bash set -ex - +cd $1 # delete the images and cleanup rm -rf output-qemu rm -rf packer_cache diff --git a/packer/centos/7/base/packer-delete.sh b/packer/centos/7/base/packer-delete.sh deleted file mode 100755 index 24b7b5b..0000000 --- a/packer/centos/7/base/packer-delete.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -ex - -# delete the images and cleanup -rm -rf output-qemu -rm -rf packer_cache -rm -rf ./ssh -rm -f user-data -rm -f disk-ssh-pub.img diff --git a/packer/centos/7/base/centos.json b/packer/centos/7/base/packer.json similarity index 97% rename from packer/centos/7/base/centos.json rename to packer/centos/7/base/packer.json index 0bef593..4706ed1 100644 --- a/packer/centos/7/base/centos.json +++ b/packer/centos/7/base/packer.json @@ -2,7 +2,7 @@ "variables": { "image_url": "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2003.qcow2", "image_checksum_url": "https://cloud.centos.org/centos/7/images/sha256sum.txt", - "image_name": "centos-7", + "image_name": "packer", "ssh_private_key_file": "{{env `PACKER_PRIVATE_KEY`}}" }, "builders": [ diff --git a/packer/centos/7/docker/packer-build.sh b/packer/centos/7/docker/packer-build.sh deleted file mode 100755 index dcdc374..0000000 --- a/packer/centos/7/docker/packer-build.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -set -ex -# prepare to build - -if [[ -f "~/.ssh/id_rsa.pub" ]]; then - export PACKER_PUBLIC_KEY=~/.ssh/id_rsa.pub - export PACKER_PRIVATE_KEY=~/.ssh/id_rsa -else - mkdir -p ./ssh - chmod 0700 ./ssh - ssh-keygen -q -t rsa -b 4096 -C "travis+syyang@ibm.com" -N '' -f ./ssh/id_rsa <<< y - export PACKER_PUBLIC_KEY=./ssh/id_rsa.pub - export PACKER_PRIVATE_KEY=./ssh/id_rsa -fi - -sudo rm -rf output-qemu - -# prepare public key image -public_key=$(cat ${PACKER_PUBLIC_KEY}) -cat < user-data -#cloud-config -ssh_authorized_keys: - - "${public_key}" -EOF - -cloud-localds disk-ssh-pub.img user-data - -# ansible-galaxy install -ansible-galaxy install geerlingguy.docker - -# build the images -# base - -PACKER_LOG=0 packer build centos.json - -# Time to make the below as a function at the next PR -NEW_IMAGE="output-qemu/ibmcloud-centos-7-docker-cloudimg-amd64-100G.qcow2" -ENCRYPTED_IMAGE="output-qemu/ibmcloud-centos-7-docker-cloudimg-amd64-100G-encrypted.qcow2" - -qemu-img resize output-qemu/centos-7.qcow2 100G -qemu-img convert -f qcow2 -O qcow2 output-qemu/centos-7.qcow2 ${NEW_IMAGE} -qemu-img info ${NEW_IMAGE} -rm output-qemu/centos-7.qcow2 - -# create an example encrypted image -if [ -n "$1" ]; then - SECRET="$1" -else - SECRET="JustMySimpleSecret" -fi -BASE64_ENCODED_SECRET=$(echo -n $SECRET | base64) - -qemu-img convert -O qcow2 \ - --object secret,id=sec0,format=base64,data=${BASE64_ENCODED_SECRET} \ - -o encrypt.format=luks,encrypt.key-secret=sec0 \ - ${NEW_IMAGE} ${ENCRYPTED_IMAGE} - -qemu-img compare \ - --object secret,id=sec0,format=base64,data=${BASE64_ENCODED_SECRET} \ - --image-opts \ - driver=qcow2,file.filename=${NEW_IMAGE} \ - driver=qcow2,encrypt.key-secret=sec0,file.filename=${ENCRYPTED_IMAGE} - -# upload to COS - - #TBD - -# import as custom images - - #TBD diff --git a/packer/centos/7/docker/centos.json b/packer/centos/7/docker/packer.json similarity index 97% rename from packer/centos/7/docker/centos.json rename to packer/centos/7/docker/packer.json index 0bef593..4706ed1 100644 --- a/packer/centos/7/docker/centos.json +++ b/packer/centos/7/docker/packer.json @@ -2,7 +2,7 @@ "variables": { "image_url": "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2003.qcow2", "image_checksum_url": "https://cloud.centos.org/centos/7/images/sha256sum.txt", - "image_name": "centos-7", + "image_name": "packer", "ssh_private_key_file": "{{env `PACKER_PRIVATE_KEY`}}" }, "builders": [ diff --git a/packer/ubuntu/bionic/base/packer-build.sh b/packer/ubuntu/bionic/base/packer-build.sh deleted file mode 100755 index 63485c9..0000000 --- a/packer/ubuntu/bionic/base/packer-build.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -set -ex -# prepare to build - -if [[ -f "~/.ssh/id_rsa.pub" ]]; then - export PACKER_PUBLIC_KEY=~/.ssh/id_rsa.pub - export PACKER_PRIVATE_KEY=~/.ssh/id_rsa -else - mkdir -p ./ssh - chmod 0700 ./ssh - ssh-keygen -q -t rsa -b 4096 -C "travis+syyang@ibm.com" -N '' -f ./ssh/id_rsa <<< y - export PACKER_PUBLIC_KEY=./ssh/id_rsa.pub - export PACKER_PRIVATE_KEY=./ssh/id_rsa -fi - -rm -rf output-qemu - -# prepare public key image -public_key=$(cat ${PACKER_PUBLIC_KEY}) -cat < user-data -#cloud-config -ssh_authorized_keys: - - "${public_key}" -EOF - -cloud-localds disk-ssh-pub.img user-data - -# ansible-galaxy install -ansible-galaxy install geerlingguy.docker - -# build the images -# base - -PACKER_LOG=0 packer build ubuntu.json - -# Time to make the below as a function at the next PR -NEW_IMAGE="output-qemu/ibmcloud-ubuntu-bionic-cloudimg-amd64-100G.qcow2" -ENCRYPTED_IMAGE="output-qemu/ibmcloud-ubuntu-bionic-cloudimg-amd64-100G-encrypted.qcow2" - -qemu-img resize output-qemu/ubuntu-bionic.qcow2 100G -qemu-img convert -f qcow2 -O qcow2 output-qemu/ubuntu-bionic.qcow2 ${NEW_IMAGE} -qemu-img info ${NEW_IMAGE} -rm output-qemu/ubuntu-bionic.qcow2 - -# create an example encrypted image -if [ -n "$1" ]; then - SECRET="$1" -else - SECRET="JustMySimpleSecret" -fi -BASE64_ENCODED_SECRET=$(echo -n $SECRET | base64) - -qemu-img convert -O qcow2 \ - --object secret,id=sec0,format=base64,data=${BASE64_ENCODED_SECRET} \ - -o encrypt.format=luks,encrypt.key-secret=sec0 \ - ${NEW_IMAGE} ${ENCRYPTED_IMAGE} - -qemu-img compare \ - --object secret,id=sec0,format=base64,data=${BASE64_ENCODED_SECRET} \ - --image-opts \ - driver=qcow2,file.filename=${NEW_IMAGE} \ - driver=qcow2,encrypt.key-secret=sec0,file.filename=${ENCRYPTED_IMAGE} - -# upload to COS - - #TBD - -# import as custom images - - #TBD diff --git a/packer/ubuntu/bionic/base/packer-delete.sh b/packer/ubuntu/bionic/base/packer-delete.sh deleted file mode 100755 index 24b7b5b..0000000 --- a/packer/ubuntu/bionic/base/packer-delete.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -ex - -# delete the images and cleanup -rm -rf output-qemu -rm -rf packer_cache -rm -rf ./ssh -rm -f user-data -rm -f disk-ssh-pub.img diff --git a/packer/ubuntu/bionic/base/ubuntu.json b/packer/ubuntu/bionic/base/packer.json similarity index 95% rename from packer/ubuntu/bionic/base/ubuntu.json rename to packer/ubuntu/bionic/base/packer.json index 3c227eb..bc1c4be 100644 --- a/packer/ubuntu/bionic/base/ubuntu.json +++ b/packer/ubuntu/bionic/base/packer.json @@ -2,7 +2,7 @@ "variables": { "image_url": "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img", "image_checksum_url": "https://cloud-images.ubuntu.com/bionic/current/SHA256SUMS", - "image_name": "ubuntu-bionic", + "image_name": "packer", "ssh_private_key_file": "{{env `PACKER_PRIVATE_KEY`}}" }, "builders": [ @@ -12,7 +12,7 @@ "iso_checksum": "file:{{user `image_checksum_url`}}", "shutdown_command": "rm -f /home/ubuntu/.ssh/authorized_keys && sudo rm -f /root/.ssh/authorized_keys && echo 'packer' | sudo -S shutdown -P now", "output_directory": "output-qemu", - "disk_size": "5120M", + "disk_size": "100G", "format": "qcow2", "http_directory": "http", "communicator": "ssh", diff --git a/packer/ubuntu/bionic/docker/packer-build.sh b/packer/ubuntu/bionic/docker/packer-build.sh deleted file mode 100755 index ad885a3..0000000 --- a/packer/ubuntu/bionic/docker/packer-build.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash -set -ex -# prepare to build - -if [[ -f "~/.ssh/id_rsa.pub" ]]; then - export PACKER_PUBLIC_KEY=~/.ssh/id_rsa.pub - export PACKER_PRIVATE_KEY=~/.ssh/id_rsa -else - mkdir -p ./ssh - chmod 0700 ./ssh - ssh-keygen -q -t rsa -b 4096 -C "travis+syyang@ibm.com" -N '' -f ./ssh/id_rsa <<< y - export PACKER_PUBLIC_KEY=./ssh/id_rsa.pub - export PACKER_PRIVATE_KEY=./ssh/id_rsa -fi - -sudo rm -rf output-qemu - -# prepare public key image -public_key=$(cat ${PACKER_PUBLIC_KEY}) -cat < user-data -#cloud-config -ssh_authorized_keys: - - "${public_key}" -EOF - -cloud-localds disk-ssh-pub.img user-data - -# ansible-galaxy install -ansible-galaxy install geerlingguy.docker - -# base+docker -PACKER_LOG=0 packer build ubuntu.json - -NEW_IMAGE="output-qemu/ibmcloud-ubuntu-bionic-cloudimg-docker-amd64-100G.qcow2" -ENCRYPTED_IMAGE="output-qemu/ibmcloud-ubuntu-bionic-cloudimg-docker-amd64-100G-encrypted.qcow2" - -qemu-img resize output-qemu/ubuntu-bionic.qcow2 100G -qemu-img convert -f qcow2 -O qcow2 output-qemu/ubuntu-bionic.qcow2 ${NEW_IMAGE} -qemu-img info ${NEW_IMAGE} -rm output-qemu/ubuntu-bionic.qcow2 - -# create an example encrypted image -if [ -n "$1" ]; then - SECRET="$1" -else - SECRET="JustMySimpleSecret" -fi -BASE64_ENCODED_SECRET=$(echo -n $SECRET | base64) - -qemu-img convert -O qcow2 \ - --object secret,id=sec0,format=base64,data=${BASE64_ENCODED_SECRET} \ - -o encrypt.format=luks,encrypt.key-secret=sec0 \ - ${NEW_IMAGE} ${ENCRYPTED_IMAGE} - -qemu-img compare \ - --object secret,id=sec0,format=base64,data=${BASE64_ENCODED_SECRET} \ - --image-opts \ - driver=qcow2,file.filename=${NEW_IMAGE} \ - driver=qcow2,encrypt.key-secret=sec0,file.filename=${ENCRYPTED_IMAGE} - -# upload to COS - - #TBD - -# import as custom images - - #TBD diff --git a/packer/ubuntu/bionic/docker/packer-delete.sh b/packer/ubuntu/bionic/docker/packer-delete.sh deleted file mode 100755 index 24b7b5b..0000000 --- a/packer/ubuntu/bionic/docker/packer-delete.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -ex - -# delete the images and cleanup -rm -rf output-qemu -rm -rf packer_cache -rm -rf ./ssh -rm -f user-data -rm -f disk-ssh-pub.img diff --git a/packer/ubuntu/bionic/docker/ubuntu.json b/packer/ubuntu/bionic/docker/packer.json similarity index 95% rename from packer/ubuntu/bionic/docker/ubuntu.json rename to packer/ubuntu/bionic/docker/packer.json index 3c227eb..bc1c4be 100644 --- a/packer/ubuntu/bionic/docker/ubuntu.json +++ b/packer/ubuntu/bionic/docker/packer.json @@ -2,7 +2,7 @@ "variables": { "image_url": "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img", "image_checksum_url": "https://cloud-images.ubuntu.com/bionic/current/SHA256SUMS", - "image_name": "ubuntu-bionic", + "image_name": "packer", "ssh_private_key_file": "{{env `PACKER_PRIVATE_KEY`}}" }, "builders": [ @@ -12,7 +12,7 @@ "iso_checksum": "file:{{user `image_checksum_url`}}", "shutdown_command": "rm -f /home/ubuntu/.ssh/authorized_keys && sudo rm -f /root/.ssh/authorized_keys && echo 'packer' | sudo -S shutdown -P now", "output_directory": "output-qemu", - "disk_size": "5120M", + "disk_size": "100G", "format": "qcow2", "http_directory": "http", "communicator": "ssh",