-
Notifications
You must be signed in to change notification settings - Fork 8
157 lines (146 loc) · 5.61 KB
/
docker-build.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
name: Docker images - build
on:
workflow_dispatch:
release:
types: [published]
repository_dispatch:
types: [docker-build]
jobs:
build:
env:
LATEST_NODE: 14
DEFAULT_IMAGE: nrchkb/node-red-homekit
DEV_IMAGE: nrchkb/node-red-homekit-dev
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18]
suffix: ["", "-minimal", "-raspbian"]
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- 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 "date=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Get NRCHKB Version
id: nrchkbVersion
run: |
HOMEKIT_BRIDGED_VERSION=$(grep -oE "\"node-red-contrib-homekit-bridged\": \"(\w*.\w*.\w*.\w*.\w*.)" package.json | cut -d\" -f4)
echo "version=$HOMEKIT_BRIDGED_VERSION" >> $GITHUB_OUTPUT
- name: Set Node-RED Version
id: nodeRedVersion
run: |
NODE_RED_VERSION=""
if [[ "${{matrix.node}}" == "14" ]]; then
NODE_RED_VERSION="2.2.3"
sed -ie "s/\"node-red\":[^\"].*\"/\"node-red\": \"${NODE_RED_VERSION}\"/g" package.json
else
NODE_RED_VERSION=$(grep -oE "\"node-red\": \"(\w*.\w*.\w*.\w*.\w*.)" package.json | cut -d\" -f4)
fi
echo "version=$NODE_RED_VERSION" >> $GITHUB_OUTPUT
- name: Set Image Settings
id: imageSettings
run: |
TAGS=""
while IFS= read -r TAG;do
if [ -z "$TAGS" ]; then
TAGS=$TAG
else
TAGS="$TAGS,$TAG"
fi
done <<< "${{ steps.meta.outputs.tags }}"
CURRENT_TAG="$(echo "$GITHUB_REF" | awk -F '/' '{ print $3}')"
if [[ ! "$CURRENT_TAG" =~ ^v[0-9\.-]*$ ]]; then
CURRENT_TAG="$(git describe --tags --abbrev=0)"
fi
echo "current tag $CURRENT_TAG"
if [[ "$CURRENT_TAG" =~ ^v[0-9\.-]*$ ]]; then
IMAGE=${{ env.DEFAULT_IMAGE }}
PUSH="true"
VERSION=${CURRENT_TAG:1}
if [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "" ]; then
TAGS="$TAGS,$IMAGE:$VERSION,$IMAGE:latest"
elif [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "-minimal" ]; then
TAGS="$TAGS,$IMAGE:$VERSION,$IMAGE:latest-minimal"
elif [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "-raspbian" ]; then
TAGS="$TAGS,$IMAGE:$VERSION,$IMAGE:latest-raspbian"
fi
TAGS="$TAGS,$IMAGE:latest-${{ matrix.node }}"
if [ "${{ matrix.suffix}}" != "" ]; then
TAGS="$TAGS,$IMAGE:latest-${{ matrix.node }}${{ matrix.suffix }}"
fi
else
IMAGE=${{ env.DEV_IMAGE }}
if [[ "$CURRENT_TAG" == *"dev"* || "$CURRENT_TAG" == *"beta"* ]]; then
PUSH="true"
else
PUSH="false"
fi
VERSION=${CURRENT_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
PLATFORMS=""
SUFFIX=""
if [[ "${{matrix.suffix}}" == "-raspbian" ]]; then
PLATFORMS="linux/arm/v7, linux/arm/v6"
SUFFIX=""
FFMPEG_OS="raspbian"
else
PLATFORMS="linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6"
SUFFIX="${{ matrix.suffix }}"
FFMPEG_OS="alpine"
fi
echo $TAGS
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "push=$PUSH" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "platforms=$PLATFORMS" >> $GITHUB_OUTPUT
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
echo "ffmpegOS=$FFMPEG_OS" >> $GITHUB_OUTPUT
- name: Build and push
id: build-push
uses: docker/build-push-action@v5
continue-on-error: true
with:
context: .
platforms: ${{ steps.imageSettings.outputs.platforms }}
push: ${{ steps.imageSettings.outputs.push }}
file: .docker/Dockerfile.alpine
build-args: |
NODE_VERSION=${{ matrix.node }}
BUILD_DATE=${{ steps.date.outputs.date }}
BUILD_VERSION=${{ steps.imageSettings.outputs.version }}
BUILD_REF=${{ env.GITHUB_SHA }}
NODE_RED_VERSION=${{ steps.nodeRedVersion.outputs.version }}
HOMEKIT_BRIDGED_VERSION=${{ steps.nrchkbVersion.outputs.version }}
FFMPEG_OS=${{ steps.imageSettings.outputs.ffmpegOS }}
TAG_SUFFIX=${{ steps.imageSettings.outputs.suffix }}
tags: ${{ steps.imageSettings.outputs.tags }}