-
Notifications
You must be signed in to change notification settings - Fork 8
195 lines (176 loc) · 6.83 KB
/
docker-image-build.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
# Inspiration
# https://github.com/actions/starter-workflows/blob/main/ci/docker-publish.yml
name: Docker image
on:
workflow_dispatch:
inputs:
tags:
description: 'Test scenario tags'
required: false
release:
types:
- published
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
steps:
# - name: Send job status to MQTT (starting job)
# uses: potaesm/[email protected]
# if: always()
# env:
# JOB_CONCLUSION: ${{ job.status }}
# NODE_VERSION: ${{ matrix.node }}
# with:
# url: ${{ secrets.PUBLIC_MQTT_BROKER_URL }}
# topic: control/github_actions_action_runner
# payload: '{ "type":"ci-test", "repo": "${{ github.repository }}", "job": "${{ github.job }}", "workflow": "${{ github.workflow }}", "nodeVersion": "${{ env.NODE_VERSION }}","status": "in_progress","conclusion":"${{ env.JOB_CONCLUSION }}" }'
# username: ${{ secrets.PUBLIC_MQTT_BROKER_USER }}
# connectTimeout: 30000
- name: Show input values
run: |
echo "Inputs: ${{ github.event.inputs }}"
- name: Checkout repository
uses: actions/checkout@v4
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
# Login against a Docker registry except on PR
# https://github.com/marketplace/actions/docker-login
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
- name: Login to Docker Hub
uses: docker/login-action@v3
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Docker tag has format: refs/tags/butler-v1.2.3
# We need to extract the tag semver from the full tag
# Store the tag in GITHUB_ENV environment variable
- name: Create clean tag for Docker
run: |
#export TAGTMP1=${{ github.ref }}
#export TAG=${TAGTMP1##*/}
export TAG=$(echo ${{ github.ref }} | grep -oP 'v\d+\.\d+\.\d+')
echo "TAG=$TAG" >> $GITHUB_ENV
#
# Debug
# echo "TAGTMP1=$TAGTMP1"
echo "TAG=$TAG"
echo "GITHUB_ENV=$GITHUB_ENV"
# export TAGTMP2=${TAGTMP1##*/}
# export TAG=${TAGTMP2##*-}
# echo "TAG=$TAG" >> $GITHUB_ENV
- name: Dump GitHub context
if: always()
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
if: always()
env:
JOB_CONTEXT: ${{ toJSON(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
if: always()
env:
STEPS_CONTEXT: ${{ toJSON(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
if: always()
env:
RUNNER_CONTEXT: ${{ toJSON(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
if: always()
env:
STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
run: echo "$STRATEGY_CONTEXT"
# Extract metadata (tags, labels) for Docker
# https://github.com/marketplace/actions/docker-metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
with:
# images: ${{ env.IMAGE_NAME }}
images: ${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}},value=${{ env.TAG }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.TAG }}
type=semver,pattern={{major}},value=${{ env.TAG }}
- name: Show Docker tags that will be used
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
run: echo '${{ steps.meta.outputs.tags }}'
- name: Show Docker labels that will be used
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
run: echo '${{ steps.meta.outputs.labels }}'
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
with:
context: .
platforms: |
linux/amd64
linux/arm64
linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
if: |
github.event_name != 'pull_request' &&
github.repository_owner == 'ptarmiganlabs'
run: echo ${{ steps.docker_build.outputs.digest }}
# Send MQTT message similar to this:
# { "topic":"control/github_actions_action_runner",
# "payload":"{
# \"type\":\"docker-build\",
# \"repo\": \"ptarmiganlabs/butler\",
# \"job\": \"build\", \
# "workflow\": \"Build Docker image CI\",
# \"status\": \"completed\",
# \"conclusion\":\"success\"
# }"
# }
# - name: Send job status to MQTT when done
# uses: potaesm/[email protected]
# if: always()
# env:
# JOB_STATUS: ${{ job.status }}
# with:
# url: ${{ secrets.PUBLIC_MQTT_BROKER_URL }}
# topic: control/github_actions_action_runner
# payload: '{ "type":"docker-build", "repo": "${{ github.repository }}", "job": "${{ github.job }}", "workflow": "${{ github.workflow }}","status": "completed","conclusion":"${{ env.JOB_STATUS }}" }'
# username: ${{ secrets.PUBLIC_MQTT_BROKER_USER }}
# connectTimeout: 30000