-
Notifications
You must be signed in to change notification settings - Fork 57
63 lines (54 loc) · 1.96 KB
/
build-and-push-docker-multiarch-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Docker Image Build and Push - CI Workflow
on:
push:
branches:
- fedora
tags:
- fedora-minimal
jobs:
build-and-push-muti-arch-docker-image:
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: network-multitool
DOCKERHUB_ORGNAME: wbitt
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
#
# DOCKERHUB_USERNAME and DOCKERHUB_TOKEN are to be set in the GITHUB WEB UI,
# under RepoName -> Settings -> Secrets
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Prepare Docker Image Tags
id: prep
run: |
SHORT_REF=$(basename ${GITHUB_REF})
SHORT_HASH=${GITHUB_SHA::7}
TAGS=""
if [[ ! -z "${SHORT_REF}" && "${SHORT_REF}" == "master" ]]; then
echo "Found git commit on master branch. Setting docker image tag as: 'latest'"
TAG=${DOCKERHUB_ORGNAME}/${DOCKER_IMAGE}:latest
fi
if [[ ! -z "${SHORT_REF}" && "${SHORT_REF}" != "master" ]]; then
echo "Found git tag. Setting docker image tag as: '${SHORT_REF}'"
TAG=${DOCKERHUB_ORGNAME}/${DOCKER_IMAGE}:${SHORT_REF}
fi
TAGS="${TAG},${DOCKERHUB_ORGNAME}/${DOCKER_IMAGE}:${SHORT_HASH}"
echo "Complete Docker image-name and tags are setup as: ${TAGS}"
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: ${{ steps.prep.outputs.tags }}