4

I need to download and install a package directly from GitHub and I need to install some libraries I need for a build from source through pip down the line.

For that I use:

RUN apt-get update && apt-get install -y libavformat-dev libavdevice-dev libavfilter-dev libswscale-dev

and

RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz \
&& tar -xf geckodriver-v0.30.0-linux64.tar.gz \
&& mv geckodriver /usr/local/bin/ \
&& rm geckodriver-v0.30.0-linux64.tar.gz

I want to build for different platforms with buildx: docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 .

On amd64 I do not need to install the av libraries, as pip won't need to build anything, because wheels are provided. On arm64 and arm/v7 I need to install the libraries, and I need to download, extract and copy a different geckodriver package.

Is there a way to specify conditional statements based on CPU architecture?

Valentin Metz
  • 393
  • 6
  • 13

1 Answers1

0

Following this docker blog post you have some predefined ARG variables like BUILDPLATFORM that you can use to build your image.

Therefore, you can try something like this:

FROM alpine as arm64
RUN echo "arm64" > /version.txt

FROM alpine as amd64
RUN echo "amd64" > /version.txt

FROM $TARGETARCH as common
RUN date >> /version.txt

CMD ["cat", "/version.txt"]

And use docker buildx to compile the image for multiple platforms:

$ docker buildx build --platform linux/amd64 -t test .
$ docker run --rm test
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
amd64
Thu May 25 07:54:34 UTC 2023
$ docker buildx build --platform linux/arm64 -t test .
$ docker run --rm test
arm64
Thu May 25 07:53:09 UTC 2023

Daniel Argüelles
  • 2,229
  • 1
  • 33
  • 56