I’m trying to create a multi-architecture docker image via buildkit, using the predefined TARGETARCH
arg variable.
What I want to do is – I think – something like bash variable indirection, but I understand that’s not supported and I’m struggling to come up with an alternative.
Here’s what I’ve got:
FROM alpine:latest
# Buildkit should populate this on build with e.g. "arm64" or "amd64"
ARG TARGETARCH
# Set some temp variables via ARG... :/
ARG DOWNLOAD_amd64="x86_64"
ARG DOWNLOAD_arm64="aarch64"
ARG DOWNLOAD_URL="https://download.url/path/to/toolkit-${DOWNLOAD_amd64}"
# DOWNLOAD_URL must also be set in container as ENV var.
ENV DOWNLOAD_URL $DOWNLOAD_URL
RUN echo "Installing Toolkit" &&
curl -sSL ${DOWNLOAD_URL} -o /tmp/toolkit-${DOWNLOAD_amd64}
… which is a bit pseudo-code but hopefully illustrates what I’m trying to do: I want the value of either $DOWNLOAD_amd64
or $DOWNLOAD_arm64
dropped into $DOWNLOAD_URL
, depending on what $TARGETARCH
is set to.
This is probably a long-solved issue but either I’m googling the wrong stuff or just not getting it.
2
Answers
Ok, was not complete. Here a full working solution:
Dockerfile:
entrypoint.sh
Test:
Now for Alpine:
Dockerfile
Entrypoint.sh
Alpine does not accept
xargs -d
. But not that interesting here due to the fact URL does not contain any blank..Testing:
Alpine just uses that for login shells.. so:
I had a similar problem, and landed here for ideas to solve it. In the end, I used
uname -p