From c884a3de01ce3f8e9252008cc3b8bf8deb1d7640 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Thu, 14 Nov 2024 08:00:05 +0100 Subject: [PATCH] Add QEMU, buildx and Docker --- Dockerfile | 15 +++++++++++---- README.md | 1 + test/test_docker.py | 5 +++++ tests.sh | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 test/test_docker.py diff --git a/Dockerfile b/Dockerfile index 7477205..f867ff5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,23 +8,30 @@ USER root RUN (echo 'DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb || true";};' | tee /etc/apt/apt.conf.d/clean) &&\ apt-get update &&\ apt-get upgrade -y &&\ - apt-get install -y curl wget make git unzip gnupg software-properties-common jq &&\ - ## TerraForm + apt-get install -y curl wget make git unzip gnupg software-properties-common jq ca-certificates &&\ + ## TerraForm: Prep (wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null) &&\ gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint &&\ (echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hashicorp.list) &&\ + ## Docker + QEMU + buildx: Prep + install -m 0755 -d /etc/apt/keyrings &&\ + curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc &&\ + chmod a+r /etc/apt/keyrings/docker.asc &&\ + (echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null) &&\ + ## TerraForm: Prep + ## Docker + QEMU + buildx: Install apt-get update &&\ - apt-get install -y terraform &&\ + apt-get install -y terraform docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin qemu-user-static &&\ ## AWS CLI curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "/tmp/awscliv2.zip" &&\ unzip /tmp/awscliv2.zip &&\ ./aws/install &&\ rm /tmp/* -Rf &&\ + ## Helm curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 &&\ chmod 700 get_helm.sh &&\ ./get_helm.sh &&\ rm ./get_helm.sh &&\ - ## See https://github.com/actions/checkout/issues/956 groupmod -g 1000 runner && usermod -u 1000 runner diff --git a/README.md b/README.md index 8e7f83d..ee53729 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,6 @@ Also includes the following tools: * TerraForm * AWS CLI (v2) * Helm +* Docker + QEMU + BuildX Unlocks node v20 that is already available in the image diff --git a/test/test_docker.py b/test/test_docker.py new file mode 100644 index 0000000..b7d205c --- /dev/null +++ b/test/test_docker.py @@ -0,0 +1,5 @@ +import pytest + +def test_terraform(host): + assert 'Hello from Docker!' in host.run('docker run hello-world').stdout + assert 'This message shows that your installation appears to be working correctly.' in host.run('docker run hello-world').stdout diff --git a/tests.sh b/tests.sh index 16f03af..1570f54 100755 --- a/tests.sh +++ b/tests.sh @@ -13,7 +13,7 @@ declare -r DOCKER_TAG="$1" printf "Starting a container for '%s'\\n" "$DOCKER_TAG" -DOCKER_CONTAINER=$(docker run --rm -v "$(pwd)/test:/tests" -t -d "$DOCKER_TAG") +DOCKER_CONTAINER=$(docker run --rm -v "$(pwd)/test:/tests" -v /var/run/docker.sock:/var/run/docker.sock:ro -t -d "$DOCKER_TAG") readonly DOCKER_CONTAINER # Let's register a trap function, if our tests fail, finish or the script gets