Skip to content

Commit e3613eb

Browse files
authored
feat: support building arm64 images
1 parent 3141713 commit e3613eb

1 file changed

Lines changed: 34 additions & 91 deletions

File tree

.github/workflows/docker.yml

Lines changed: 34 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
name: Docker
22

33
# This will run when:
4-
# - when new code is pushed to master/develop to push the tags
4+
# - when new code is pushed to main/develop to push the tags
55
# latest and develop
66
# - when a pull request is created and updated to make sure the
77
# Dockerfile is still valid.
8-
# To be able to push to dockerhub, this execpts the following
8+
# To be able to push to dockerhub, this expects the following
99
# secrets to be set in the project:
1010
# - DOCKERHUB_USERNAME : username that can push to the org
1111
# - DOCKERHUB_PASSWORD : password asscoaited with the username
1212
on:
13+
# Trigger a build for every new push to the main branch
1314
push:
1415
branches:
1516
- master
@@ -18,112 +19,54 @@ on:
1819

1920
pull_request:
2021

21-
# Trigger the workflow on release activity
22+
# Trigger a build for every new release
2223
release:
23-
# Only use the types keyword to narrow down the activity types that will trigger your workflow.
2424
types:
2525
- published
2626
- edited
2727
- created
2828

29-
# Certain actions will only run when this is the master repo.
29+
# Certain actions will only run when this is the main repo.
3030
env:
31-
MASTER_REPO: nds-org/workbench-apiserver-python
31+
MAIN_REPO: nds-org/workbench-apiserver-python
3232
DOCKERHUB_ORG: ndslabs
3333

3434
jobs:
3535
docker:
3636
runs-on: ubuntu-latest
37-
strategy:
38-
fail-fast: true
39-
matrix:
40-
name:
41-
- api
42-
include:
43-
- name: api
44-
FOLDER: .
45-
IMAGE: apiserver
46-
4737
steps:
48-
- uses: actions/checkout@v3
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v2
4940

50-
# calculate some variables that are used later
51-
- name: github branch
52-
run: |
53-
if [ "${{ github.event.release.target_commitish }}" != "" ]; then
54-
BRANCH="${{ github.event.release.target_commitish }}"
55-
else
56-
BRANCH=${GITHUB_REF##*/}
57-
fi
58-
echo "GITHUB_BRANCH=${BRANCH}" >> $GITHUB_ENV
59-
60-
# Commit was for main/release branch, build a new version
61-
if [ "$BRANCH" == "master" -o "$BRANCH" == "main" ]; then
62-
version="$(cat openapi/swagger-v1.yml | grep "^ version:" | awk '{print $2}')"
63-
echo "VERSION=$(version)" >> $GITHUB_ENV
64-
tags="latest"
65-
oldversion=""
66-
while [ "${oldversion}" != "${version}" ]; do
67-
oldversion="${version}"
68-
tags="${tags},${version}"
69-
version=${version%.*}
70-
done
71-
echo "TAGS=${tags}" >> $GITHUB_ENV
72-
else
73-
echo "VERSION=$BRANCH" >> $GITHUB_ENV
74-
echo "TAGS=$BRANCH" >> $GITHUB_ENV
75-
fi
76-
77-
# build the docker image, this will always run to make sure
78-
# the Dockerfile still works.
79-
- name: Build image
80-
uses: elgohr/Publish-Docker-Github-Action@2.22
81-
env:
82-
BRANCH: ${{ env.GITHUB_BRANCH }}
83-
VERSION: ${{ env.VERSION }}
84-
BUILDNUMBER: ${{ github.run_number }}
85-
GITSHA1: ${{ github.sha }}
86-
with:
87-
registry: docker.pkg.github.com
88-
name: ${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.IMAGE }}
89-
username: ${{ github.actor }}
90-
password: ${{ secrets.GITHUB_TOKEN }}
91-
context: ${{ matrix.FOLDER }}
92-
tags: "${{ env.TAGS }}"
93-
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1
94-
no_push: true
41+
- uses: actions/checkout@v3
9542

96-
# this will publish to github container registry
97-
- name: Publish to GitHub
98-
if: github.event_name != 'pull_request' && github.repository == env.MASTER_REPO
99-
uses: elgohr/Publish-Docker-Github-Action@2.22
100-
env:
101-
BRANCH: ${{ env.GITHUB_BRANCH }}
102-
VERSION: ${{ env.VERSION }}
103-
BUILDNUMBER: ${{ github.run_number }}
104-
GITSHA1: ${{ github.sha }}
43+
- name: Docker meta
44+
id: meta
45+
uses: docker/metadata-action@v4
10546
with:
106-
registry: ghcr.io
107-
name: ${{ github.repository_owner }}/${{ matrix.IMAGE }}
108-
username: ${{ secrets.GHCR_USERNAME }}
109-
password: ${{ secrets.GHCR_PASSWORD }}
110-
context: ${{ matrix.FOLDER }}
111-
tags: "${{ env.TAGS }}"
112-
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1
47+
images: |
48+
ndslabs/apiserver
49+
tags: |
50+
# set latest tag for default branch
51+
type=raw,value=latest,enable={{is_default_branch}}
52+
type=ref,event=branch
53+
type=ref,event=pr
54+
type=ref,event=tag
55+
type=semver,pattern={{version}}
56+
type=semver,pattern={{major}}.{{minor}}
57+
type=semver,pattern={{major}}
11358
114-
# this will publish to dockerhub
115-
- name: Publish to Docker Hub
116-
if: github.event_name != 'pull_request' && github.repository == env.MASTER_REPO
117-
uses: elgohr/Publish-Docker-Github-Action@2.22
118-
env:
119-
BRANCH: ${{ env.GITHUB_BRANCH }}
120-
VERSION: ${{ env.VERSION }}
121-
BUILDNUMBER: ${{ github.run_number }}
122-
GITSHA1: ${{ github.sha }}
59+
- name: Login to DockerHub
60+
uses: docker/login-action@v2
12361
with:
124-
name: ${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}
12562
username: ${{ secrets.DOCKERHUB_USERNAME }}
12663
password: ${{ secrets.DOCKERHUB_PASSWORD }}
127-
context: ${{ matrix.FOLDER }}
128-
tags: "${{ env.TAGS }}"
129-
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1
64+
65+
- name: Build and push
66+
uses: docker/build-push-action@v3
67+
with:
68+
context: .
69+
platforms: linux/amd64,linux/arm64
70+
push: true
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)