forked from dashpay/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (133 loc) · 4.86 KB
/
Copy pathrelease-docker-image.yml
File metadata and controls
146 lines (133 loc) · 4.86 KB
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
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
env:
DIGEST_NAME: digests-${{ inputs.image_org }}-${{ inputs.image_name }}-${{ github.sha }}
DIGEST_DIR_PATH: /tmp/digests
jobs:
build-image:
name: Build ${{ matrix.platform }} image
runs-on: ${{ matrix.runner }}
timeout-minutes: 20
strategy:
matrix:
include:
- runner: [ "self-hosted", "linux", "x64", "ubuntu-platform" ]
platform: linux/amd64
- runner: [ "self-hosted", "linux", "arm64", "ubuntu-platform" ]
platform: linux/arm64
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure AWS credentials and bucket region
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
- 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: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.event.release.tag_name }}
target: ${{ inputs.target }}
platform: ${{ matrix.platform }}
cargo_profile: release
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
region: ${{ vars.AWS_REGION }}
- name: Export digest
run: |
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@v3
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-22.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: Get image version
uses: actions/github-script@v6
id: version
with:
result-encoding: string
script: |
return (
context.eventName === 'workflow_dispatch'
? '${{ github.event.inputs.tag }}'
: context.payload.release.tag_name
);
- name: Set suffix
uses: actions/github-script@v6
id: suffix
with:
result-encoding: string
script: |
const fullTag = '${{ steps.version.outputs.result }}';
if (fullTag.includes('-')) {
const [, fullSuffix] = fullTag.split('-');
const [suffix] = fullSuffix.split('.');
return `-${suffix}`;
} 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(\d+),group=1,value=${{ steps.version.outputs.result }}
type=match,pattern=v(\d+.\d+),group=1,value=${{ steps.version.outputs.result }}
type=match,pattern=v(\d+.\d+.\d+),group=1,value=${{ steps.version.outputs.result }}
type=match,pattern=v(.*),group=1,value=${{ steps.version.outputs.result }},suffix=
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 }}