-
Notifications
You must be signed in to change notification settings - Fork 385
275 lines (241 loc) · 8.91 KB
/
main.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# This is a basic workflow to help you get started with Actions
name: Docker Build
# Controls when the action will run.
on:
workflow_dispatch:
inputs:
version:
required: true
type: string
description: "Version"
release:
types: [published]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a 2 jobs called "alpine" and "debian"
alpine:
env:
# Setting the defaults up front
LATEST_NODE: 16
DEFAULT_IMAGE: nodered/node-red
DEV_IMAGE: nodered/node-red-dev
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18]
suffix: ["", "-minimal"]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
-
name: Checkout
uses: actions/checkout@v3
- name: Show Env
run: env
-
name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
flavor: |
latest=false
suffix=-${{matrix.node}}${{matrix.suffix}}
images: |
${{ env.DEFAULT_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
-
name: Setup QEMU
uses: docker/setup-qemu-action@v3
-
name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Get Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H:%M:%SZ')"
- name: Get Node-RED Version
id: nrVersion
run: |
TAGS=""
while IFS= read -r TAG;do
if [ -z "$TAGS" ]; then
TAGS=$TAG
else
TAGS="$TAGS,$TAG"
fi
done <<< "${{ steps.meta.outputs.tags }}"
echo "Start Tags = $TAGS"
echo "GITHUB_REF = $GITHUB_REF"
echo "version = ${{ github.event.inputs.version }}"
if [[ ! -z "${{ github.event.inputs.version }}" ]]; then
TEMP=${{ github.event.inputs.version }}
TEMP=${TEMP:1}
TEMP2=$(echo $GITHUB_REF | awk -F '/' '{ print $3}')
echo "$GITHUB_REF - $TEMP"
TAGS=$(echo $TAGS | sed "s/$TEMP2/$TEMP/")
TRAVIS_TAG=${{ github.event.inputs.version }}
else
TRAVIS_TAG=$(echo $GITHUB_REF | awk -F '/' '{ print $3}')
fi
echo "TRAVIS_TAG = $TRAVIS_TAG"
if [[ "$TRAVIS_TAG" =~ ^v[0-9\.-]*$ ]]; then
IMAGE=${{ env.DEFAULT_IMAGE }}
PUSH=true
VERSION=${TRAVIS_TAG:1}
STABLE_VERSION=`echo ${VERSION} | sed -r 's/^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)$/\1.\2/'`
if [[ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" && "${{ matrix.suffix }}" == "" ]]; then
TAGS="$TAGS,$IMAGE:$VERSION,$IMAGE:$STABLE_VERSION"
elif [[ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" && "${{ matrix.suffix }}" == "-minimal" ]]; then
TAGS="$TAGS,$IMAGE:$VERSION-minimal"
fi
else
IMAGE=${{ env.DEV_IMAGE }}
if [[ "$TRAVIS_TAG" == *"dev"* || "$TRAVIS_TAG" == *"beta"* ]]; then
PUSH=true
else
PUSH=false
fi
VERSION=${TRAVIS_TAG}
TAGS=$(echo $TAGS | sed 's!${{ env.DEFAULT_IMAGE}}!${{ env.DEV_IMAGE }}!')
if [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "" ]; then
TAGS="$TAGS,$IMAGE:$VERSION"
fi
fi
echo $TAGS
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "push=$PUSH" >> $GITHUB_OUTPUT
echo "version=$TRAVIS_TAG" >> $GITHUB_OUTPUT
echo "buildVersion=$VERSION" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
# echo "::set-output name=tags::$TAGS"
# echo "::set-output name=push::$PUSH"
# echo "::set-output name=version::$TRAVIS_TAG"
# echo "::set-output name=buildVersion::$VERSION"
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: build-push
uses: docker/build-push-action@v5
continue-on-error: true
with:
context: .
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
push: ${{ steps.nrVersion.outputs.push }}
file: .docker/Dockerfile.alpine
build-args: |
NODE_VERSION=${{ matrix.node }}
BUILD_DATE=${{ steps.date.outputs.date }}
BUILD_VERSION=${{ steps.nrVersion.outputs.buildVersion }}
BUILD_REF=${{ env.GITHUB_SHA }}
NODE_RED_VERSION=${{ steps.nrVersion.outputs.version }}
TAG_SUFFIX=${{ matrix.suffix }}
tags: ${{ steps.nrVersion.outputs.tags }}
debian:
env:
# Setting the defaults up front
LATEST_NODE: 16
DEFAULT_IMAGE: nodered/node-red
DEV_IMAGE: nodered/node-red-dev
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H:%M:%SZ')"
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
flavor: |
latest=false
images: |
${{ env.DEFAULT_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
- name: Get Node-RED Version
id: nrVersion
run: |
TAGS=""
echo Original tags ${{ steps.meta.outputs.tags }}
if [[ ! -z "${{ github.event.inputs.version }}" ]]; then
TRAVIS_TAG=${{ github.event.inputs.version }}
else
TRAVIS_TAG=$(echo $GITHUB_REF | awk -F '/' '{ print $3}')
fi
if [[ "$TRAVIS_TAG" =~ ^v[0-9\.-]*$ ]]; then
# release build
IMAGE=${{ env.DEFAULT_IMAGE }}
PUSH=true
VERSION=${TRAVIS_TAG:1}
STABLE_VERSION=`echo ${VERSION} | sed -r 's/^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)$/\1.\2/'`
TAGS="$IMAGE:$VERSION-debian,$IMAGE:$STABLE_VERSION-debian"
else
IMAGE=${{ env.DEV_IMAGE }}
if [[ "$TRAVIS_TAG" == *"dev"* || "$TRAVIS_TAG" == *"beta"* ]]; then
# beta build
PUSH=true
else
PUSH=false
fi
VERSION=${TRAVIS_TAG}
TAGS="$IMAGE:$VERSION-debian"
fi
echo $TAGS
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "push=$PUSH" >> $GITHUB_OUTPUT
echo "version=$TRAVIS_TAG" >> $GITHUB_OUTPUT
echo "buildVersion=$VERSION" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Build and push
id: build-push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64, linux/arm64, linux/arm/v7
file: .docker/Dockerfile.debian
push: ${{ steps.nrVersion.outputs.push }}
build-args: |
NODE_VERSION=${{ env.LATEST_NODE }}
BUILD_DATE=${{ steps.date.outputs.date }}
BUILD_REF=${{ env.GITHUB.SHA }}
TAG_SUFFIX=-debian
NODE_RED_VERSION=${{ steps.nrVersion.outputs.version }}
BUILD_VERSION=${{ steps.nrVersion.outputs.buildVersion }}
tags: ${{ steps.nrVersion.outputs.tags }}
# -
# name: Sign Image
# run: |
# echo "Digest ${{ steps.build-push.outputs.digest }}"
# for TAG in $(echo "${{ steps.nrVersion.outputs.tags }}" | sed "s/,/ /g"); do
# if [[ "$TAG" == "${{ env.DEFAULT_IMAGE }}:latest" ]]; then
# export DOCKER_CONTENT_TRUST=1
# SIGNER_KEY_NAME="8b08f4d8315a5d6443a4f59eaab60a49dacbc105c13d25f167cdb5cc9fa8f9ed.key"
# PATH_KEYS=$HOME/.docker/trust/private
# mkdir -p $PATH_KEYS
# cp .docker/$SIGNER_KEY_NAME $PATH_KEYS
# chmod 600 $PATH_KEYS/$SIGNER_KEY_NAME
# export DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=${{ secrets.DOCKER_SIGNING_PASSWORD }}
# docker trust key load $PATH_KEYS/$SIGNER_KEY_NAME
# # docker trust sign $TAG
# # docker trust inspect --pretty $TAG
# echo "Siging tag $TAG"
# else
# echo "Not signing $TAG"
# fi
# done