Skip to content

Commit 43b6ede

Browse files
author
mstanescu
committed
Enable multi-arch builds
1 parent 3498e07 commit 43b6ede

File tree

3 files changed

+104
-24
lines changed

3 files changed

+104
-24
lines changed

Dockerfile

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
FROM python:3.12.3-alpine3.18 AS compile-image
2-
ARG TERRAFORM_VERSION="0.12.6"
2+
ARG TARGETARCH
3+
ARG TARGETPLATFORM
4+
ARG TERRAFORM_VERSION="0.12.31"
35
ARG AZURE_CLI_VERSION="2.0.67"
46

57
ENV BOTO_CONFIG=/dev/null
68
COPY . /sources/
79
WORKDIR /sources
810

9-
RUN wget -q -O terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
11+
# Install terraform (needed for tests in compile stage)
12+
RUN wget -q -O terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${TARGETARCH}.zip \
1013
&& unzip terraform.zip -d /usr/local/bin \
1114
&& rm -rf terraform.zip
1215
RUN apk add --virtual=build bash gcc libffi-dev musl-dev openssl-dev make git
@@ -17,19 +20,21 @@ RUN pip --no-cache-dir install virtualenv \
1720
&& python -m pip install --upgrade pip \
1821
&& env CRYPTOGRAPHY_DONT_BUILD_RUST=1 pip install azure-cli==${AZURE_CLI_VERSION} \
1922
&& deactivate
20-
RUN bash build_scripts/freeze_requirements.sh
23+
# RUN bash build_scripts/freeze_requirements.sh # Skip - requirements.txt already frozen
2124
RUN bash build_scripts/run_tests.sh
2225
RUN bash build_scripts/build_package.sh
2326
RUN apk del --purge build
2427

2528

2629
FROM python:3.12.3-alpine3.18
27-
ARG TERRAFORM_VERSION="0.12.6"
30+
ARG TARGETARCH
31+
ARG TARGETPLATFORM
32+
ARG TERRAFORM_VERSION="0.12.31"
2833
ARG VAULT_VERSION="1.1.3"
2934
ARG KUBECTL_VERSION="v1.17.0"
30-
ARG AWS_IAM_AUTHENTICATOR_VERSION="1.13.7/2019-06-11"
31-
ARG HELM_VERSION="v3.6.3"
32-
ARG HELM_FILE_VERSION="v0.81.3"
35+
ARG AWS_IAM_AUTHENTICATOR_VERSION="1.10.11/2018-12-06"
36+
ARG HELM_VERSION="v3.16.3"
37+
ARG HELM_FILE_VERSION="1.1.8"
3338
ARG HELM_DIFF_VERSION="2.11.0%2B5"
3439

3540

@@ -45,22 +50,26 @@ RUN adduser ops -Du 2342 -h /home/ops \
4550
&& rm -rf /dist \
4651
# Dry-run
4752
&& ops --verbose -h \
48-
&& apk del --purge build \
49-
&& wget -q https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -O /usr/local/bin/kubectl \
50-
&& chmod +x /usr/local/bin/kubectl \
51-
&& wget -q https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz -O - | tar -xzO linux-amd64/helm > /usr/local/bin/helm \
52-
&& chmod +x /usr/local/bin/helm \
53-
&& wget -q -O terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
53+
&& apk del --purge build
54+
55+
RUN wget -q https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl -O /usr/local/bin/kubectl \
56+
&& chmod +x /usr/local/bin/kubectl
57+
58+
RUN wget -q https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz -O - | tar -xzO linux-${TARGETARCH}/helm > /usr/local/bin/helm \
59+
&& chmod +x /usr/local/bin/helm
60+
61+
RUN wget -q -O terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${TARGETARCH}.zip \
5462
&& unzip terraform.zip -d /usr/local/bin \
55-
&& rm -rf terraform.zip \
56-
&& mkdir -p ~/.terraform.d/plugins && wget -q -O ~/.terraform.d/plugins/terraform-provider-vault https://github.com/amuraru/terraform-provider-vault/releases/download/vault-namespaces/terraform-provider-vault \
57-
&& chmod 0755 ~/.terraform.d/plugins/terraform-provider-vault \
58-
&& wget -q -O vault.zip https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip \
63+
&& rm -rf terraform.zip
64+
65+
RUN wget -q -O vault.zip https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_${TARGETARCH}.zip \
5966
&& unzip vault.zip -d /usr/local/bin \
60-
&& rm -rf vault.zip \
61-
&& wget -q https://amazon-eks.s3-us-west-2.amazonaws.com/${AWS_IAM_AUTHENTICATOR_VERSION}/bin/linux/amd64/aws-iam-authenticator -O /usr/local/bin/aws-iam-authenticator \
62-
&& chmod +x /usr/local/bin/aws-iam-authenticator \
63-
&& wget -q https://github.com/roboll/helmfile/releases/download/${HELM_FILE_VERSION}/helmfile_linux_amd64 -O /usr/local/bin/helmfile \
67+
&& rm -rf vault.zip
68+
69+
RUN wget -q https://amazon-eks.s3-us-west-2.amazonaws.com/${AWS_IAM_AUTHENTICATOR_VERSION}/bin/linux/${TARGETARCH}/aws-iam-authenticator -O /usr/local/bin/aws-iam-authenticator \
70+
&& chmod +x /usr/local/bin/aws-iam-authenticator
71+
72+
RUN wget -q https://github.com/helmfile/helmfile/releases/download/v${HELM_FILE_VERSION}/helmfile_${HELM_FILE_VERSION}_linux_${TARGETARCH}.tar.gz -O - | tar -xzO helmfile > /usr/local/bin/helmfile \
6473
&& chmod +x /usr/local/bin/helmfile
6574

6675
# install utils under `ops` user
@@ -69,9 +78,9 @@ ENV HOME=/home/ops
6978
WORKDIR /home/ops
7079

7180
USER root
72-
RUN helm plugin install https://github.com/databus23/helm-diff
81+
RUN helm plugin install https://github.com/databus23/helm-diff --version v3.9.11
7382
RUN helm plugin install https://github.com/jkroepke/helm-secrets --version v3.8.2
74-
RUN helm plugin install https://github.com/rimusz/helm-tiller
83+
RUN helm plugin install https://github.com/rimusz/helm-tiller # Obsolete in Helm 3
7584

7685

7786
COPY --from=compile-image /azure-cli /home/ops/.local/azure-cli

build_multiarch.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Multiarch Docker Build Script
5+
# This script builds the ops-cli Docker image for multiple architectures
6+
7+
IMAGE_NAME="${IMAGE_NAME:-ghcr.io/adobe/ops-cli}"
8+
IMAGE_TAG="${IMAGE_TAG:-latest}"
9+
PLATFORMS="${PLATFORMS:-linux/amd64,linux/arm64}"
10+
PUSH="${PUSH:-false}"
11+
12+
echo "Building multiarch Docker image..."
13+
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
14+
echo "Platforms: ${PLATFORMS}"
15+
echo "Push to registry: ${PUSH}"
16+
17+
# Login to GitHub Container Registry if pushing
18+
if [ "$PUSH" = "true" ]; then
19+
if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_TOKEN" ]; then
20+
echo "Error: GITHUB_USERNAME and GITHUB_TOKEN environment variables must be set when PUSH=true"
21+
exit 1
22+
fi
23+
24+
echo "Logging in to ghcr.io..."
25+
echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
26+
27+
if [ $? -ne 0 ]; then
28+
echo "Error: Failed to login to GitHub Container Registry"
29+
exit 1
30+
fi
31+
echo "Successfully logged in to ghcr.io"
32+
fi
33+
34+
# Build the image
35+
BUILD_ARGS=""
36+
if [ "$PUSH" = "true" ]; then
37+
BUILD_ARGS="--push"
38+
else
39+
BUILD_ARGS="--load"
40+
fi
41+
42+
# Note: --load only works for single platform builds
43+
# For multiplatform builds without pushing, use --output type=docker
44+
if [ "$PUSH" = "false" ] && [[ "$PLATFORMS" == *","* ]]; then
45+
echo "Warning: Cannot use --load with multiple platforms."
46+
echo "Building without --load (image will not be loaded to local docker)."
47+
echo "To load to local docker, specify a single platform or use --push to push to registry."
48+
BUILD_ARGS=""
49+
fi
50+
51+
docker buildx build \
52+
--platform ${PLATFORMS} \
53+
--tag ${IMAGE_NAME}:${IMAGE_TAG} \
54+
${BUILD_ARGS} \
55+
--file Dockerfile \
56+
.
57+
58+
echo "Build complete!"
59+
60+
if [ "$PUSH" = "true" ]; then
61+
echo "Image pushed to registry as ${IMAGE_NAME}:${IMAGE_TAG}"
62+
else
63+
if [[ "$PLATFORMS" == *","* ]]; then
64+
echo "Note: Multi-platform images were built but not loaded to local docker."
65+
echo "To use them, either:"
66+
echo " 1. Push to a registry: PUSH=true ./build_multiarch.sh"
67+
echo " 2. Build for single platform: PLATFORMS=linux/amd64 ./build_multiarch.sh"
68+
else
69+
echo "Image loaded to local docker as ${IMAGE_NAME}:${IMAGE_TAG}"
70+
fi
71+
fi

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ hvac==1.2.1
1414
passgen
1515
inflection==0.5.1
1616
kubernetes==33.1.0
17-
himl==0.16.4
17+
himl==0.18.0
1818
six
1919
GitPython==3.1.*

0 commit comments

Comments
 (0)