-
-
Save tonistiigi/024172617d8178e4f5a7665120397264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#syntax=docker/dockerfile:1.7.0 | |
# Example of Dockerfile that uses a custom command for Risc-V | |
# and different shared command for other architectures | |
ARG ARCH=${TARGETARCH#riscv64} | |
ARG ARCH=${ARCH:+"common"} | |
ARG ARCH=${ARCH:-$TARGETARCH} | |
FROM --platform=$BUILDPLATFORM alpine AS base-common | |
ARG TARGETARCH | |
RUN echo "Common build, I am $TARGETARCH" > /out | |
FROM --platform=$BUILDPLATFORM alpine AS base-riscv64 | |
ARG TARGETARCH | |
RUN echo "Riscv only special build, I am $TARGETARCH" > /out | |
FROM base-${ARCH} AS base | |
FROM scratch | |
COPY --from=base /out /out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
» docker buildx build --platform linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 -o out -f 1.Dockerfile . | |
» find . -type f -name out -exec sh -c 'echo "{}"; cat "{}"' \; | |
./out/linux_arm_v7/out | |
Common build, I am arm | |
./out/linux_arm64/out | |
Common build, I am arm64 | |
./out/linux_riscv64/out | |
Riscv only special build, I am riscv64 | |
./out/linux_s390x/out | |
Common build, I am s390x | |
./out/linux_amd64/out | |
Common build, I am amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#syntax=docker/dockerfile:1.7.0 | |
# Example of Dockerfile that uses a custom command for Risc-V and S390x | |
# and different shared command for the rest of the architectures | |
ARG ARCH=${TARGETARCH#riscv64} | |
ARG ARCH=${ARCH#s390x} | |
ARG ARCH=${ARCH:+"common"} | |
ARG ARCH=${ARCH:-$TARGETARCH} | |
FROM --platform=$BUILDPLATFORM alpine AS base-common | |
ARG TARGETARCH | |
RUN echo "Common build, I am $TARGETARCH" > /out | |
FROM --platform=$BUILDPLATFORM alpine AS base-riscv64 | |
ARG TARGETARCH | |
RUN echo "Riscv only special build, I am $TARGETARCH" > /out | |
FROM --platform=$BUILDPLATFORM alpine AS base-s390x | |
ARG TARGETARCH | |
RUN echo "IBM only special build, I am $TARGETARCH" > /out | |
FROM base-${ARCH} AS base | |
FROM scratch | |
COPY --from=base /out /out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
» docker buildx build --platform linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 -o out -f 2.Dockerfile . | |
» find . -type f -name out -exec sh -c 'echo "{}"; cat "{}"' \; | |
./out/linux_arm_v7/out | |
Common build, I am arm | |
./out/linux_arm64/out | |
Common build, I am arm64 | |
./out/linux_riscv64/out | |
Riscv only special build, I am riscv64 | |
./out/linux_s390x/out | |
IBM only special build, I am s390x | |
./out/linux_amd64/out | |
Common build, I am amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#syntax=docker/dockerfile:1.7.0 | |
# Example of Dockerfile that uses a custom command for Risc-V | |
# and for 32bit ARM but only if it is v5 variant and different | |
# shared command for the rest of the architectures | |
ARG ARCH=${TARGETARCH}${TARGETVARIANT} | |
ARG ARCH=${ARCH#riscv64} | |
ARG ARCH=${ARCH#armv5} | |
ARG ARCH=${ARCH:+common} | |
ARG ARCH=${ARCH:-$TARGETARCH$TARGETVARIANT} | |
FROM --platform=$BUILDPLATFORM alpine AS base-common | |
ARG TARGETPLATFORM | |
RUN echo "Common build, I am $TARGETPLATFORM" > /out | |
FROM --platform=$BUILDPLATFORM alpine AS base-riscv64 | |
ARG TARGETPLATFORM | |
RUN echo "Riscv only special build, I am $TARGETPLATFORM" > /out | |
FROM --platform=$BUILDPLATFORM alpine AS base-armv5 | |
ARG TARGETPLATFORM | |
RUN echo "Old arm only special build, I am $TARGETPLATFORM" > /out | |
FROM base-${ARCH} AS base | |
FROM scratch | |
COPY --from=base /out /out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
» docker buildx build --platform linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64,linux/arm/v5,linux/arm/v6 -o out -f 3.Dockerfile . | |
» find . -type f -name out -exec sh -c 'echo "{}"; cat "{}"' \; | |
./out/linux_arm_v7/out | |
Common build, I am linux/arm/v7 | |
./out/linux_arm_v6/out | |
Common build, I am linux/arm/v6 | |
./out/linux_arm64/out | |
Common build, I am linux/arm64 | |
./out/linux_riscv64/out | |
Riscv only special build, I am linux/riscv64 | |
./out/linux_s390x/out | |
Common build, I am linux/s390x | |
./out/linux_amd64/out | |
Common build, I am linux/amd64 | |
./out/linux_arm_v5/out | |
Old arm only special build, I am linux/arm/v5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment