From a005547cda0c9fd9139b08b3953e4ccf1182f542 Mon Sep 17 00:00:00 2001 From: Donal Byrne Date: Thu, 4 May 2023 20:38:38 +0200 Subject: [PATCH] Initial work to move to buildx --- .travis.yml | 91 ++++++++++++----------------- docker_build_and_push_flavor.sh | 6 +- docker_build_and_push_flavor_fat.sh | 7 +++ 3 files changed, 49 insertions(+), 55 deletions(-) diff --git a/.travis.yml b/.travis.yml index e75f772..e922420 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,12 @@ stages: before_script: - echo $DOCKER_PASSWORD > /tmp/docker.pass + - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) edge" + - sudo apt-get update + - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce + - mkdir -vp ~/.docker/cli-plugins/ + - curl --silent -L "https://github.com/docker/buildx/releases/download/v0.3.0/buildx-v0.3.0.linux-amd64" > ~/.docker/cli-plugins/docker-buildx + - chmod a+x ~/.docker/cli-plugins/docker-buildx jobs: include: @@ -48,72 +54,49 @@ jobs: # These take longer to build and are put in their own jobs ############################################################################### - - name: Build Docker image for build-from-source flavors -- alpine / aarch64 - stage: build - arch: arm64 - script: - - ./docker_build_and_push_flavor.sh alpine-aarch64 alpine/Dockerfile - - - name: Build Docker image for build-from-source flavors -- alpine / amd64 + - name: Build Docker image for build-from-source flavors -- alpine stage: build arch: amd64 script: - - ./docker_build_and_push_flavor.sh alpine-amd64 alpine/Dockerfile + - ./docker_build_and_push_flavor.sh alpine linux/arm/v7,linux/arm64/v8,linux/amd64 alpine/Dockerfile - - name: Build Docker image for build-from-source flavor -- bionic / aarch64 - arch: arm64 - stage: build - script: - - ./docker_build_and_push_flavor.sh bionic-aarch64 bionic/Dockerfile - - - name: Build Docker image for build-from-source flavor -- bionic / amd64 + - name: Build Docker image for build-from-source flavor -- bionic arch: amd64 stage: build script: - - ./docker_build_and_push_flavor.sh bionic-amd64 bionic/Dockerfile + - ./docker_build_and_push_flavor.sh bionic linux/arm/v7,linux/arm64/v8,linux/amd64 bionic/Dockerfile - name: Build Docker image for build-from-source flavor -- bionic / s390x - arch: s390x - stage: build - script: - - ./docker_build_and_push_flavor.sh bionic-s390x bionic/Dockerfile --build-arg RESTY_PCRE_BUILD_OPTIONS="" --build-arg RESTY_PCRE_OPTIONS="" - - - name: Build Docker image for build-from-source flavor -- focal / aarch64 - arch: arm64 + arch: amd64 stage: build script: - - ./docker_build_and_push_flavor.sh focal-aarch64 focal/Dockerfile + - ./docker_build_and_push_flavor.sh bionic s390x bionic/Dockerfile --build-arg RESTY_PCRE_BUILD_OPTIONS="" --build-arg RESTY_PCRE_OPTIONS="" - - name: Build Docker image for build-from-source flavor -- focal / amd64 + - name: Build Docker image for build-from-source flavor -- focal arch: amd64 stage: build script: - - ./docker_build_and_push_flavor.sh focal-amd64 focal/Dockerfile + - ./docker_build_and_push_flavor.sh focal linux/arm/v7,linux/arm64/v8,linux/amd64 focal/Dockerfile - name: Build Docker image for build-from-source flavor -- focal / s390x - arch: s390x - stage: build - script: - - ./docker_build_and_push_flavor.sh focal-s390x focal/Dockerfile --build-arg RESTY_PCRE_BUILD_OPTIONS="" --build-arg RESTY_PCRE_OPTIONS="" - - - name: Build Docker image for build-from-source flavor -- jammy / aarch64 - arch: arm64 + arch: amd64 stage: build script: - - ./docker_build_and_push_flavor.sh jammy-aarch64 jammy/Dockerfile + - ./docker_build_and_push_flavor.sh focal s390x focal/Dockerfile --build-arg RESTY_PCRE_BUILD_OPTIONS="" --build-arg RESTY_PCRE_OPTIONS="" - - name: Build Docker image for build-from-source flavor -- jammy / amd64 + - name: Build Docker image for build-from-source flavor -- jammy arch: amd64 stage: build script: - - ./docker_build_and_push_flavor.sh jammy-amd64 jammy/Dockerfile + - ./docker_build_and_push_flavor.sh jammy linux/arm/v7,linux/arm64/v8,linux/amd64 jammy/Dockerfile + # jammy / s390x disabled due to build issues (#209) # - name: Build Docker image for build-from-source flavor -- jammy / s390x # arch: s390x # stage: build # script: -# - ./docker_build_and_push_flavor.sh jammy-s390x jammy/Dockerfile --build-arg RESTY_PCRE_BUILD_OPTIONS="" --build-arg RESTY_PCRE_OPTIONS="" +# - ./docker_build_and_push_flavor.sh jammy s390x jammy/Dockerfile --build-arg RESTY_PCRE_BUILD_OPTIONS="" --build-arg RESTY_PCRE_OPTIONS="" ############################################################################### # Build From OpenResty Upstream Flavors @@ -121,30 +104,30 @@ jobs: ############################################################################### - name: Build Docker image for upstream flavors -- aarch64 - arch: arm64 + arch: amd64 stage: build script: - - ./docker_build_and_push_flavor.sh alpine-apk-aarch64 alpine-apk/Dockerfile - - ./docker_build_and_push_flavor.sh amzn2-aarch64 centos/Dockerfile --build-arg RESTY_IMAGE_BASE=amazonlinux --build-arg RESTY_IMAGE_TAG=2 --build-arg RESTY_YUM_REPO="https://openresty.org/package/amazon/openresty.repo" --build-arg RESTY_RPM_DIST="amzn2" --build-arg RESTY_RPM_ARCH="aarch64" - - ./docker_build_and_push_flavor.sh rocky-aarch64 fedora/Dockerfile --build-arg RESTY_IMAGE_BASE=rockylinux --build-arg RESTY_IMAGE_TAG=8.5 --build-arg RESTY_YUM_REPO="https://openresty.org/package/rocky/openresty.repo" --build-arg RESTY_RPM_DIST="el8" --build-arg RESTY_RPM_ARCH="aarch64" - - ./docker_build_and_push_flavor.sh centos-aarch64 centos/Dockerfile --build-arg RESTY_RPM_ARCH=aarch64 - - ./docker_build_and_push_flavor.sh centos7-aarch64 centos7/Dockerfile --build-arg RESTY_RPM_ARCH=aarch64 - # - ./docker_build_and_push_flavor.sh fedora-aarch64 fedora/Dockerfile --build-arg RESTY_RPM_ARCH=aarch64 - - ./docker_build_and_push_flavor.sh bullseye-aarch64 bullseye/Dockerfile --build-arg RESTY_APT_REPO="https://openresty.org/package/arm64/debian" - - ./docker_build_and_push_flavor.sh buster-aarch64 buster/Dockerfile --build-arg RESTY_APT_REPO="https://openresty.org/package/arm64/debian" + - ./docker_build_and_push_flavor.sh alpine-apk linux/arm64/v8 alpine-apk/Dockerfile + - ./docker_build_and_push_flavor.sh amzn2 linux/arm64/v8 centos/Dockerfile --build-arg RESTY_IMAGE_BASE=amazonlinux --build-arg RESTY_IMAGE_TAG=2 --build-arg RESTY_YUM_REPO="https://openresty.org/package/amazon/openresty.repo" --build-arg RESTY_RPM_DIST="amzn2" --build-arg RESTY_RPM_ARCH="aarch64" + - ./docker_build_and_push_flavor.sh rocky linux/arm64/v8 fedora/Dockerfile --build-arg RESTY_IMAGE_BASE=rockylinux --build-arg RESTY_IMAGE_TAG=8.5 --build-arg RESTY_YUM_REPO="https://openresty.org/package/rocky/openresty.repo" --build-arg RESTY_RPM_DIST="el8" --build-arg RESTY_RPM_ARCH="aarch64" + - ./docker_build_and_push_flavor.sh centos linux/arm64/v8 centos/Dockerfile --build-arg RESTY_RPM_ARCH=aarch64 + - ./docker_build_and_push_flavor.sh centos7 linux/arm64/v8 centos7/Dockerfile --build-arg RESTY_RPM_ARCH=aarch64 + # - ./docker_build_and_push_flavor.sh fedora linux/arm64/v8 fedora/Dockerfile --build-arg RESTY_RPM_ARCH=aarch64 + - ./docker_build_and_push_flavor.sh bullseye linux/arm64/v8 bullseye/Dockerfile --build-arg RESTY_APT_REPO="https://openresty.org/package/arm64/debian" + - ./docker_build_and_push_flavor.sh buster linux/arm64/v8 buster/Dockerfile --build-arg RESTY_APT_REPO="https://openresty.org/package/arm64/debian" - name: Build Docker image for upstream flavors -- amd64 arch: amd64 stage: build script: - - ./docker_build_and_push_flavor.sh alpine-apk-amd64 alpine-apk/Dockerfile - - ./docker_build_and_push_flavor.sh amzn2-amd64 centos/Dockerfile --build-arg RESTY_IMAGE_BASE=amazonlinux --build-arg RESTY_IMAGE_TAG=2 --build-arg RESTY_YUM_REPO="https://openresty.org/package/amazon/openresty.repo" --build-arg RESTY_RPM_DIST="amzn2" - - ./docker_build_and_push_flavor.sh rocky-amd64 fedora/Dockerfile --build-arg RESTY_IMAGE_BASE=rockylinux --build-arg RESTY_IMAGE_TAG=8.5 --build-arg RESTY_YUM_REPO="https://openresty.org/package/rocky/openresty.repo" --build-arg RESTY_RPM_DIST="el8" - - ./docker_build_and_push_flavor.sh centos-amd64 centos/Dockerfile - - ./docker_build_and_push_flavor.sh centos7-amd64 centos7/Dockerfile - - ./docker_build_and_push_flavor.sh fedora-amd64 fedora/Dockerfile - - ./docker_build_and_push_flavor.sh bullseye-amd64 bullseye/Dockerfile - - ./docker_build_and_push_flavor.sh buster-amd64 buster/Dockerfile + - ./docker_build_and_push_flavor.sh alpine-apk linux/amd64 alpine-apk/Dockerfile + - ./docker_build_and_push_flavor.sh amzn2 linux/amd64 centos/Dockerfile --build-arg RESTY_IMAGE_BASE=amazonlinux --build-arg RESTY_IMAGE_TAG=2 --build-arg RESTY_YUM_REPO="https://openresty.org/package/amazon/openresty.repo" --build-arg RESTY_RPM_DIST="amzn2" + - ./docker_build_and_push_flavor.sh rocky linux/amd64 fedora/Dockerfile --build-arg RESTY_IMAGE_BASE=rockylinux --build-arg RESTY_IMAGE_TAG=8.5 --build-arg RESTY_YUM_REPO="https://openresty.org/package/rocky/openresty.repo" --build-arg RESTY_RPM_DIST="el8" + - ./docker_build_and_push_flavor.sh centos linux/amd64 centos/Dockerfile + - ./docker_build_and_push_flavor.sh centos7 linux/amd64 centos7/Dockerfile + - ./docker_build_and_push_flavor.sh fedora linux/amd64 fedora/Dockerfile + - ./docker_build_and_push_flavor.sh bullseye linux/amd64 bullseye/Dockerfile + - ./docker_build_and_push_flavor.sh buster linux/amd64 buster/Dockerfile ############################################################################### # Multi-arch manifests diff --git a/docker_build_and_push_flavor.sh b/docker_build_and_push_flavor.sh index 937db7d..b959d20 100755 --- a/docker_build_and_push_flavor.sh +++ b/docker_build_and_push_flavor.sh @@ -11,13 +11,17 @@ set -e FLAVOR="$1" shift +PLATFORMS="$1" +shift DOCKERFILE_PATH=${1:-$FLAVOR/Dockerfile} shift DOCKER_BUILD_PARAMS="$@" cat /tmp/docker.pass | docker login -u="$DOCKER_USERNAME" --password-stdin -docker build --pull -t openresty:$FLAVOR -f $DOCKERFILE_PATH $DOCKER_BUILD_PARAMS . +docker buildx create --use + +docker buildx build --pull -t openresty:$FLAVOR --platform "${PLATFORMS}" -f $DOCKERFILE_PATH $DOCKER_BUILD_PARAMS . if [[ "$TRAVIS_BRANCH" == "master" ]] ; then cat /tmp/docker.pass | docker login -u="$DOCKER_USERNAME" --password-stdin && diff --git a/docker_build_and_push_flavor_fat.sh b/docker_build_and_push_flavor_fat.sh index 5ea98a9..2080925 100755 --- a/docker_build_and_push_flavor_fat.sh +++ b/docker_build_and_push_flavor_fat.sh @@ -13,10 +13,14 @@ set -e FLAVOR="$1" shift +PLATFORMS="$1" +shift DOCKERFILE_PATH=${1:-$FLAVOR/Dockerfile} shift DOCKER_BUILD_PARAMS="$@" +docker buildx create --use + # Compute RESTY_FAT_IMAGE_TAG FATLESS_FLAVOR=$(echo -n "$FLAVOR" | sed 's/-fat//g') RESTY_FAT_IMAGE_BASE="$DOCKER_ORG/openresty" @@ -31,9 +35,12 @@ fi cat /tmp/docker.pass | docker login -u="$DOCKER_USERNAME" --password-stdin +docker buildx create --use + docker pull "$RESTY_FAT_IMAGE_BASE:$RESTY_FAT_IMAGE_TAG" || true docker build --pull -t openresty:$FLAVOR -f $DOCKERFILE_PATH \ + --platform "${PLATFORMS}" \ --build-arg "RESTY_FAT_IMAGE_BASE=$RESTY_FAT_IMAGE_BASE" \ --build-arg "RESTY_FAT_IMAGE_TAG=$RESTY_FAT_IMAGE_TAG" \ $DOCKER_BUILD_PARAMS .