1+ # based on https://blog.oddbit.com/post/2020-09-25-building-multi-architecture-im/
2+ ---
3+ # Interlisp workflow to build Docker Image that support multiple architectures
4+ name : ' Build Medley Docker image'
5+
6+ # Run this workflow on push to master
7+ on :
8+ push :
9+ branches :
10+ - master
11+
12+ # Jobs that compose this workflow
13+ jobs :
14+ # Job to build the docker image
15+ docker :
16+ runs-on : ubuntu-latest
17+ steps :
18+ # Checkout the branch
19+ - name : Checkout
20+ uses : actions/checkout@v2
21+
22+ # Setup needed environment variables
23+ - name : Prepare
24+ id : prep
25+ run : |
26+ DOCKER_IMAGE=interlisp/${GITHUB_REPOSITORY#*/}
27+ VERSION=latest
28+ SHORTREF=${GITHUB_SHA::8}
29+
30+ # If this is git tag, use the tag name as a docker tag
31+ if [[ $GITHUB_REF == refs/tags/* ]]; then
32+ VERSION=${GITHUB_REF#refs/tags/v}
33+ fi
34+ TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}"
35+
36+ # If the VERSION looks like a version number, assume that
37+ # this is the most recent version of the image and also
38+ # tag it 'latest'.
39+ if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
40+ TAGS="$TAGS,${DOCKER_IMAGE}:latest"
41+ fi
42+
43+ # Set output parameters.
44+ echo ::set-output name=tags::${TAGS}
45+ echo ::set-output name=docker_image::${DOCKER_IMAGE}
46+ echo ::set-output name=build_time::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
47+
48+ # Setup Docker Machine Emulation environment
49+ - name : Set up QEMU
50+ uses : docker/setup-qemu-action@master
51+ with :
52+ platforms : all
53+
54+ # Setup Docker Buildx function
55+ - name : Set up Docker Buildx
56+ id : buildx
57+ uses : docker/setup-buildx-action@master
58+
59+ # Login to DockerHub - required to store the image
60+ - name : Login to DockerHub
61+ if : github.event_name != 'pull_request'
62+ uses : docker/login-action@v1
63+ with :
64+ username : ${{ secrets.DOCKER_USERNAME }}
65+ password : ${{ secrets.DOCKER_PASSWORD }}
66+
67+ # Start the Docker Build using the Dockerfilein the repository
68+ - name : Build
69+ uses : docker/build-push-action@v2
70+ with :
71+ builder : ${{ steps.buildx.outputs.name }}
72+ context : .
73+ file : ./Dockerfile
74+ # Platforms
75+ # linux/amd64 -- Standard x86_64
76+ # linux/arm64 -- Apple M1
77+ # linux/arm/v7 -- Raspberry pi
78+ platforms : linux/amd64,linux/arm64,linux/arm/v7
79+ # Push the created image
80+ push : true
81+ # tags to assign to the Docker image
82+ tags : ${{ steps.prep.outputs.tags }}
0 commit comments