-
Notifications
You must be signed in to change notification settings - Fork 2
134 lines (130 loc) · 4.85 KB
/
package.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Publish to ghcr.io
on:
push:
tags:
- '*'
env:
REGISTRY: ghcr.io # default is docker.io
IMAGE_NAME: ${{ github.repository }}
jobs:
ghcr-releaser:
name: Release container images
runs-on: ubuntu-latest
permissions:
packages: write # required to write to container registry
strategy:
fail-fast: true
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Set Variables used in build-args for docker build
run: |
echo "VAULTPAL_COMMIT=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV
echo "VAULTPAL_VERSION=${GITHUB_REF#refs/*/}" >> "$GITHUB_ENV"
echo "VAULTPAL_BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%S')" >> "$GITHUB_ENV"
-
name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
# since we run platform specific builds in parallel, we only need the current platform
platforms: ${{ matrix.platform }}
-
name: Set up Docker Buildx for Multiple platform builds
uses: docker/setup-buildx-action@v2
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
# You can use the ${{ github.actor }} context to automatically use the username of the user that triggered the workflow run.
username: ${{ github.actor }}
# You can use the automatically-generated GITHUB_TOKEN secret for the password
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build docker image
id: build # so we can reference this step as ${{ steps.build.outputs.digest }} in export step
uses: docker/build-push-action@v4
with:
platforms: ${{ matrix.platform }}
context: .
push: false # push later
# don't specify 'tags' here (error "get can't push tagged ref by digest")
# tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# provenance? See GitHub Action produces unknown architecture and OS: https://github.com/docker/build-push-action/issues/820
provenance: false
build-args: |
VAULTPAL_COMMIT=${{ env.VAULTPAL_COMMIT }}
VAULTPAL_VERSION=${{ env.VAULTPAL_VERSION }}
VAULTPAL_BUILD_DATE=${{ env.VAULTPAL_BUILD_DATE }}
# capture output for export and upload image digests
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
-
name: Export image digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
-
name: Upload image digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# dedicated manifest merge job which runs after all platform specific build jobs are finished
# see https://docs.docker.com/build/ci/github-actions/multi-platform/
# see https://github.com/docker/build-push-action/issues/846
merge-manifests:
runs-on: ubuntu-latest
needs:
- ghcr-releaser
steps:
-
name: Download image digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
-
name: Set up Docker Buildx # but no need for QEMU in this job
uses: docker/setup-buildx-action@v2
-
name: Extract docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
-
name: Inspect and test new multi-platform image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} version