Skip to content

Commit 9f8f727

Browse files
authored
✨ Add support for multiarch builds, including ARM (e.g. Mac M1) (#347)
1 parent ec57495 commit 9f8f727

File tree

8 files changed

+45
-72
lines changed

8 files changed

+45
-72
lines changed

.github/workflows/deploy.yml

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- cron: "0 0 * * 1"
1010

1111
jobs:
12-
build:
12+
deploy:
1313
strategy:
1414
matrix:
1515
image:
@@ -29,23 +29,34 @@ jobs:
2929
runs-on: ubuntu-latest
3030
steps:
3131
- uses: actions/checkout@v4
32-
- name: Set up Python
33-
uses: actions/setup-python@v5.0.0
32+
- name: Set Dockerfile name
33+
if: matrix.image.name != 'latest'
34+
run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV
35+
- name: Set Dockerfile name latest
36+
if: matrix.image.name == 'latest'
37+
run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v1
40+
- name: Login to DockerHub
41+
uses: docker/login-action@v1
3442
with:
35-
python-version: "3.7"
36-
- name: Install Dependencies
37-
run: python3.7 -m pip install docker pytest
38-
- name: Deploy Image
39-
run: bash scripts/build-push.sh
40-
env:
41-
NAME: ${{ matrix.image.name }}
42-
DOCKERFILE: ${{ matrix.image.dockerfile }}
43-
PYTHON_VERSION: ${{ matrix.image.python_version }}
44-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
45-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
43+
username: ${{ secrets.DOCKERHUB_USERNAME }}
44+
password: ${{ secrets.DOCKERHUB_TOKEN }}
45+
- name: Get date for tags
46+
run: echo "DATE_TAG=$(date -I)" >> "$GITHUB_ENV"
47+
- name: Build and push
48+
uses: docker/build-push-action@v2
49+
with:
50+
push: true
51+
platforms: linux/amd64,linux/arm64
52+
tags: |
53+
tiangolo/uwsgi-nginx-flask:${{ matrix.image.name }}
54+
tiangolo/uwsgi-nginx-flask:${{ matrix.image.name }}-${{ env.DATE_TAG }}
55+
context: ./docker-images/
56+
file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile
4657
- name: Docker Hub Description
4758
uses: peter-evans/dockerhub-description@v4
4859
with:
49-
username: ${{ secrets.DOCKER_USERNAME }}
50-
password: ${{ secrets.DOCKER_PASSWORD }}
60+
username: ${{ secrets.DOCKERHUB_USERNAME }}
61+
password: ${{ secrets.DOCKERHUB_TOKEN }}
5162
repository: tiangolo/uwsgi-nginx-flask

.github/workflows/test.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
- cron: "0 0 * * 1"
1414

1515
jobs:
16-
build:
16+
test:
1717
strategy:
1818
matrix:
1919
image:
@@ -33,28 +33,34 @@ jobs:
3333
runs-on: ubuntu-latest
3434
steps:
3535
- uses: actions/checkout@v4
36+
- name: Set Dockerfile name
37+
if: matrix.image.name != 'latest'
38+
run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV
39+
- name: Set Dockerfile name latest
40+
if: matrix.image.name == 'latest'
41+
run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV
42+
- name: Build
43+
uses: docker/build-push-action@v2
44+
with:
45+
push: false
46+
tags: tiangolo/uwsgi-nginx-flask:${{ matrix.image.name }}
47+
context: ./docker-images/
48+
file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile
3649
- name: Set up Python
37-
uses: actions/setup-python@v5.0.0
50+
uses: actions/setup-python@v4
3851
with:
39-
python-version: "3.7"
40-
- name: Install poetry
41-
run: |
42-
python -m pip install --upgrade pip
43-
python -m pip install poetry
44-
- name: Configure poetry
45-
run: python -m poetry config virtualenvs.create false
52+
python-version: "3.10"
4653
- name: Install Dependencies
47-
run: python -m poetry install
54+
run: python -m pip install docker pytest
4855
- name: Test Image
4956
run: bash scripts/test.sh
5057
env:
5158
NAME: ${{ matrix.image.name }}
52-
DOCKERFILE: ${{ matrix.image.dockerfile }}
5359
PYTHON_VERSION: ${{ matrix.image.python_version }}
5460
check:
5561
if: always()
5662
needs:
57-
- build
63+
- test
5864
runs-on: ubuntu-latest
5965
steps:
6066
- name: Decide whether the needed jobs succeeded or failed

scripts/build-push-all.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

scripts/build-push.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/build.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

scripts/docker-login.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/test-all.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

scripts/test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
bash scripts/build.sh
54
SLEEP_TIME=5 pytest tests

0 commit comments

Comments
 (0)