From 7feb2c96b64fbba6614f4987f7066bab5e8fbafd Mon Sep 17 00:00:00 2001 From: Gavin Bunney Date: Tue, 26 Nov 2024 15:21:45 -0800 Subject: [PATCH] Support arm64/amd64 for k3s --- .github/workflows/docker.yml | 15 +++++++++++---- scripts/docker-compose.yaml | 6 +++--- scripts/start-k3s.sh | 5 +++-- scripts/stop-k3s.sh | 2 ++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c1202b9e..9f561666 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,4 @@ -name: Cache images for tests in GHCR +name: Cache Images on: push: @@ -42,7 +42,14 @@ jobs: for image in ${IMAGES//,/ }; do new_image="ghcr.io/gavinbunney/terraform-provider-kubectl/testacc-$(echo $image | sed 's/\//-/')" echo "Caching $image as $new_image" - docker pull $image - docker tag $image $new_image - docker push $new_image + docker rmi $image --force + docker pull $image --platform linux/amd64 + docker tag $image $new_image-amd64 + docker push $new_image-amd64 + docker tag $image $new_image-x86_64 + docker push $new_image-x86_64 + docker rmi $image --force + docker pull $image --platform linux/arm64 + docker tag $image $new_image-arm64 + docker push $new_image-arm64 done diff --git a/scripts/docker-compose.yaml b/scripts/docker-compose.yaml index fa7ce081..3cfba625 100644 --- a/scripts/docker-compose.yaml +++ b/scripts/docker-compose.yaml @@ -1,6 +1,6 @@ services: server: - image: ghcr.io/gavinbunney/terraform-provider-kubectl/testacc-rancher-k3s:v1.31.2-k3s1 + image: ghcr.io/gavinbunney/terraform-provider-kubectl/testacc-rancher-k3s:v1.31.2-k3s1-${ARCH:-amd64} command: server --disable-agent --tls-san 172.17.0.1 --agent-token somethingtotallyrandom privileged: true environment: @@ -20,7 +20,7 @@ services: - 6443:6443 node: - image: ghcr.io/gavinbunney/terraform-provider-kubectl/testacc-rancher-k3s:v1.31.2-k3s1 + image: ghcr.io/gavinbunney/terraform-provider-kubectl/testacc-rancher-k3s:v1.31.2-k3s1-${ARCH:-amd64} command: agent --token somethingtotallyrandom --server https://server:6443 privileged: true restart: always @@ -35,6 +35,6 @@ services: registry: platform: linux/amd64 - image: ghcr.io/gavinbunney/terraform-provider-kubectl/testacc-registry:2 + image: ghcr.io/gavinbunney/terraform-provider-kubectl/testacc-registry:2-amd64 ports: - 6500:5000 diff --git a/scripts/start-k3s.sh b/scripts/start-k3s.sh index 931cea0a..67b35154 100755 --- a/scripts/start-k3s.sh +++ b/scripts/start-k3s.sh @@ -6,14 +6,15 @@ cd ${DIR} export KUBECONFIG="${DIR}/kubeconfig.yaml" export COMPOSE_PROJECT_NAME=k3s -export DOCKER_DEFAULT_PLATFORM=linux/$(uname -m) +export ARCH=$(uname -m | tr '[:upper:]' '[:lower:]') +export DOCKER_DEFAULT_PLATFORM=linux/${ARCH} echo "--> Tearing down k3s in docker-compose" docker-compose down -v &>/dev/null || true rm -rf ${KUBECONFIG} sync; sync; -echo "--> Starting k3s in docker-compose" +echo "--> Starting k3s in docker-compose for arch ${ARCH}" docker-compose up -d --build --pull always echo "--> Allow insecure access to registry" diff --git a/scripts/stop-k3s.sh b/scripts/stop-k3s.sh index 7aaba4ad..928463a7 100755 --- a/scripts/stop-k3s.sh +++ b/scripts/stop-k3s.sh @@ -5,6 +5,8 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd ${DIR} export COMPOSE_PROJECT_NAME=k3s +export ARCH=$(uname -m | tr '[:upper:]' '[:lower:]') +export DOCKER_DEFAULT_PLATFORM=linux/${ARCH} echo "--> Stopping k3s in docker-compose" docker-compose down -v