forked from cloud-barista/cb-webtool
-
Notifications
You must be signed in to change notification settings - Fork 7
114 lines (102 loc) · 3.73 KB
/
publish-multi-arch-container-images.yaml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# This workflow will build the container image and publish it to container registries.
name: Publish multi-arch container images
# When its time to do a release do a full cross platform build for all supported
# architectures and push all of them to Docker Hub and GitHub Container Registry (GHCR).
# Only trigger on semver shaped tags.
on:
# "Build and publish" on merged
# Actually, there's no "merged" event.
# A "push" event is occurred after the pull request "close" event with "merged" true condition.
# The "push" event could replace "merged" event.
push:
branches:
- master
tags:
- "v*.*.*"
paths-ignore:
- '**.md'
- '.all-contributorsrc'
- '.gitignore'
- 'LICENSE'
- 'CODEOWNERS'
jobs:
# The job key is "publishing"
publishing:
# Job name is "Publishing"
name: Publishing
# This job runs on Ubuntu-latest
runs-on: ubuntu-18.04
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Prepare tags
id: prep
env:
# TODO: Change variable to your repository name and image name.
DOCKER_REPO: cloudbaristaorg
IMAGE_NAME: cb-webtool
run: |
VERSION=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
DOCKER_IMAGE=$DOCKER_REPO/$IMAGE_NAME
DOCKER_TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}.*$ ]]; then
DOCKER_TAGS="$DOCKER_TAGS,${DOCKER_IMAGE}:latest"
fi
echo "docker-tags=${DOCKER_TAGS}" >> $GITHUB_OUTPUT
echo ${DOCKER_TAGS}
GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
GHCR_TAGS="${GHCR_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}.*$ ]]; then
GHCR_TAGS="$GHCR_TAGS,${GHCR_IMAGE}:latest"
fi
echo "ghcr-tags=${GHCR_TAGS}" >> $GITHUB_OUTPUT
echo ${GHCR_TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and publish
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
file: ./Dockerfile
target: prod
platforms: linux/amd64 # linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x,linux/arm/v6
push: true
tags: |
${{ steps.prep.outputs.docker-tags }}
${{ steps.prep.outputs.ghcr-tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}