From 343866882326ce40f72259bd591fdac594441edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 17 Mar 2024 19:25:04 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20multiarch=20b?= =?UTF-8?q?uilds,=20including=20ARM=20(e.g.=20Mac=20M1)=20(#138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 45 ++++++++++++++++++++++-------------- .github/workflows/test.yml | 24 ++++++++++++++----- scripts/build-push-all.sh | 7 ------ scripts/build-push.sh | 15 ------------ scripts/build.sh | 12 ---------- scripts/docker-login.sh | 5 ---- scripts/test-all.sh | 4 ---- scripts/test.sh | 1 - 8 files changed, 46 insertions(+), 67 deletions(-) delete mode 100644 scripts/build-push-all.sh delete mode 100644 scripts/build-push.sh delete mode 100644 scripts/build.sh delete mode 100644 scripts/docker-login.sh delete mode 100644 scripts/test-all.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 041de60..08b1366 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,7 +9,7 @@ on: - cron: "0 0 * * 1" jobs: - build: + deploy: strategy: matrix: image: @@ -24,24 +24,35 @@ jobs: fail-fast: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - name: Set Dockerfile name + if: matrix.image.name != 'latest' + run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV + - name: Set Dockerfile name latest + if: matrix.image.name == 'latest' + run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 with: - python-version: "3.7" - - name: Install Dependencies - run: python3.7 -m pip install docker pytest - - name: Deploy Image - run: bash scripts/build-push.sh - env: - NAME: ${{ matrix.image.name }} - DOCKERFILE: ${{ matrix.image.dockerfile }} - PYTHON_VERSION: ${{ matrix.image.python_version }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Get date for tags + run: echo "DATE_TAG=$(date -I)" >> "$GITHUB_ENV" + - name: Build and push + uses: docker/build-push-action@v2 + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: | + tiangolo/meinheld-gunicorn-flask:${{ matrix.image.name }} + tiangolo/meinheld-gunicorn-flask:${{ matrix.image.name }}-${{ env.DATE_TAG }} + context: ./docker-images/ + file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile - name: Docker Hub Description uses: peter-evans/dockerhub-description@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} repository: tiangolo/meinheld-gunicorn-flask diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ac9f8d..e2c8337 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ on: - cron: "0 0 * * 1" jobs: - build: + test: strategy: matrix: image: @@ -28,23 +28,35 @@ jobs: fail-fast: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Set Dockerfile name + if: matrix.image.name != 'latest' + run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV + - name: Set Dockerfile name latest + if: matrix.image.name == 'latest' + run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV + - name: Build + uses: docker/build-push-action@v2 + with: + push: false + tags: tiangolo/meinheld-gunicorn-flask:${{ matrix.image.name }} + context: ./docker-images/ + file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.7" + python-version: "3.10" - name: Install Dependencies - run: python3.7 -m pip install docker pytest + run: python -m pip install docker pytest - name: Test Image run: bash scripts/test.sh env: NAME: ${{ matrix.image.name }} - DOCKERFILE: ${{ matrix.image.dockerfile }} PYTHON_VERSION: ${{ matrix.image.python_version }} check: if: always() needs: - - build + - test runs-on: ubuntu-latest steps: - name: Decide whether the needed jobs succeeded or failed diff --git a/scripts/build-push-all.sh b/scripts/build-push-all.sh deleted file mode 100644 index a18cab7..0000000 --- a/scripts/build-push-all.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -e - -bash scripts/docker-login.sh - -BUILD_PUSH=1 python scripts/process_all.py diff --git a/scripts/build-push.sh b/scripts/build-push.sh deleted file mode 100644 index da3882e..0000000 --- a/scripts/build-push.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -set -e - -use_tag="tiangolo/meinheld-gunicorn-flask:$NAME" -use_dated_tag="${use_tag}-$(date -I)" - -bash scripts/build.sh - -docker tag "$use_tag" "$use_dated_tag" - -bash scripts/docker-login.sh - -docker push "$use_tag" -docker push "$use_dated_tag" diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100644 index ab87ccc..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -use_tag="tiangolo/meinheld-gunicorn-flask:$NAME" - -DOCKERFILE="$NAME" - -if [ "$NAME" == "latest" ] ; then - DOCKERFILE="python3.9" -fi - -docker build -t "$use_tag" --file "./docker-images/${DOCKERFILE}.dockerfile" "./docker-images/" diff --git a/scripts/docker-login.sh b/scripts/docker-login.sh deleted file mode 100644 index d872c89..0000000 --- a/scripts/docker-login.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin diff --git a/scripts/test-all.sh b/scripts/test-all.sh deleted file mode 100644 index 89b34d3..0000000 --- a/scripts/test-all.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -python scripts/process_all.py diff --git a/scripts/test.sh b/scripts/test.sh index 693467a..22d68c6 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash set -e -bash scripts/build.sh pytest tests