-
Notifications
You must be signed in to change notification settings - Fork 39
148 lines (136 loc) · 5.14 KB
/
release-docker-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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
on:
workflow_call:
inputs:
name:
type: string
description: Name
required: true
image_name:
type: string
description: Image name. i.e. drive, dapi
required: true
image_org:
type: string
description: Image org. i.e. dashpay
required: true
target:
type: string
description: Image target. i.e. drive-abci, dapi
required: true
tag:
type: string
description: Image tag, i.e. v0.1.0; note it can be inherited from 'workflow_dispatch' event
default: ${{ github.event.inputs.tag || github.event.release.tag_name }}
cargo_profile:
type: string
description: Cargo profile. i.e. release, dev
default: release
env:
DIGEST_NAME: digests-${{ inputs.image_org }}-${{ inputs.image_name }}-${{ inputs.tag }}-${{ inputs.cargo_profile }}-${{ github.sha }}
DIGEST_DIR_PATH: /tmp/digests
jobs:
build-image:
name: Build ${{ matrix.platform }} image
runs-on: ${{ matrix.runner }}
timeout-minutes: 180
strategy:
matrix:
include:
- runner: ubuntu-24.04
platform: linux/amd64
- runner: ubuntu-24.04
platform: linux/arm64
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: ${{ matrix.platform == 'linux/arm64' }}
- name: Build and push by digest
uses: ./.github/actions/docker
id: docker_build
with:
image_name: ${{ inputs.image_name }}
image_org: ${{ inputs.image_org }}
image_version: ${{ inputs.tag }}
target: ${{ inputs.target }}
platform: ${{ matrix.platform }}
cargo_profile: ${{ inputs.cargo_profile }}
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
cache_region: ${{ vars.CACHE_REGION }}
cache_bucket: ${{ vars.CACHE_S3_BUCKET }}
cache_endpoint: ${{ vars.CACHE_S3_ENDPOINT }}
cache_access_key_id: ${{ secrets.CACHE_KEY_ID }}
cache_secret_access_key: ${{ secrets.CACHE_SECRET_KEY }}
# On release, we generate a new "base" image, so we need to save cache to name manifest, like '.../drive'
cache_to_name: ${{ github.event_name == 'release' && 'true' || 'false' }}
- name: Export digest
run: |
rm -rf ${{ env.DIGEST_DIR_PATH }}
mkdir -p ${{ env.DIGEST_DIR_PATH }}
digest="${{ steps.docker_build.outputs.digest }}"
touch "${{ env.DIGEST_DIR_PATH }}/${digest#sha256:}"
ls -lah ${{ env.DIGEST_DIR_PATH }}
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: ${{ env.DIGEST_NAME }}
path: ${{ env.DIGEST_DIR_PATH }}/*
if-no-files-found: error
retention-days: 1
publish-manifest:
name: Publish image tags
needs: build-image
runs-on: ubuntu-24.04
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: ${{ env.DIGEST_NAME }}
path: ${{ env.DIGEST_DIR_PATH }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set suffix
uses: actions/github-script@v6
id: suffix
with:
result-encoding: string
script: |
const fullTag = '${{ inputs.tag }}';
if (fullTag.includes('-')) {
const suffixes = fullTag.split('-').slice(1);
const firstElements = suffixes.map(suffix => suffix.split('.')[0]);
return `-${firstElements.join('-')}`;
} else {
return '';
}
- name: Set Docker tags and labels from image
id: docker_meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.image_org }}/${{ inputs.image_name }}
tags: |
type=match,pattern=v(.*),group=1,value=${{ inputs.tag }},priority=910,suffix=
type=match,pattern=v(\d+),group=1,value=${{ inputs.tag }}
type=match,pattern=v(\d+.\d+),group=1,value=${{ inputs.tag }}
type=match,pattern=v(\d+.\d+.\d+),group=1,value=${{ inputs.tag }}
flavor: |
suffix=${{ steps.suffix.outputs.result }},onlatest=true
latest=${{ github.event_name == 'release' }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create manifest list and push
working-directory: ${{ env.DIGEST_DIR_PATH }}
run: |
ls -lah
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ inputs.image_org }}/${{ inputs.image_name }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ inputs.image_org }}/${{ inputs.image_name }}:${{ steps.docker_meta.outputs.version }}