-
-
Notifications
You must be signed in to change notification settings - Fork 169
144 lines (130 loc) · 5.22 KB
/
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
name: Docker
on:
schedule:
- cron: '31 22 * * 0'
push:
branches: [main, dev]
# Publish semver tags as releases.
tags: ['v*.*.*']
pull_request:
branches: [main]
workflow_dispatch:
jobs:
prebuild:
runs-on: ubuntu-latest
steps:
- name: Should build?
run: |
if [ -z "${{ secrets.DOCKERHUB_USERNAME }}" ]; then
echo "The DOCKERHUB_USERNAME secret is missing."
exit 1
fi
build:
needs: [prebuild]
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
strategy:
matrix:
dockerfile: ['multiarch', 'hwaccel', 'qsv']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: matrix image type
id: image_type
run: |
echo "suffix=${{ matrix.dockerfile == 'hwaccel' && '-hw' || matrix.dockerfile == 'qsv' && '-qsv' ||'' }}" >> $GITHUB_OUTPUT
echo "platforms=${{ matrix.dockerfile == 'multiarch' && 'linux/amd64,linux/arm64,linux/arm/v7' || 'linux/amd64' }}" >> $GITHUB_OUTPUT
echo "arch=${{ matrix.dockerfile == 'multiarch' && 'amd64,armhf,aarch64' || 'amd64' }}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ steps.image_type.outputs.platforms }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
with:
platforms: ${{ steps.image_type.outputs.platforms }}
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log into registry ghcr.io
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ github.repository_owner }}/wyze-bridge
ghcr.io/${{ github.repository }}
flavor: |
latest=auto
suffix=${{ steps.image_type.outputs.suffix }},onlatest=true
tags: |
type=schedule,suffix=${{ steps.image_type.outputs.suffix }}
type=semver,pattern={{ version }},suffix=${{ steps.image_type.outputs.suffix }}
type=edge,branch=main,enable=${{ github.event_name == 'push' }},suffix=${{ steps.image_type.outputs.suffix }}
type=ref,event=branch,enable=${{ contains(github.ref,'dev') }},suffix=${{ steps.image_type.outputs.suffix }}
- name: Update Release Version
id: version_bump
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG_NAME=${GITHUB_REF##*/v}
echo "TAG_NAME: $TAG_NAME"
if [[ $TAG_NAME =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
sed -i "s/^VERSION=.*/VERSION=${TAG_NAME}/" ./app/.env
echo "Updated VERSION in app/.env to $TAG_NAME"
fi
- name: Build and push a Docker image
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
push: ${{ github.event_name != 'pull_request' }}
context: .
file: ./docker/Dockerfile.${{ matrix.dockerfile }}
platforms: ${{ steps.image_type.outputs.platforms }}
build-args: |
BUILD=${{ steps.meta.outputs.VERSION }}
BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
GITHUB_SHA=${{ github.sha }}
labels: |
${{ steps.meta.outputs.labels }}
io.hass.name=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }}
io.hass.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
io.hass.version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
io.hass.type=addon
io.hass.arch=${{ steps.image_type.outputs.arch }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=${{ matrix.dockerfile }}
cache-to: type=gha,mode=max,scope=${{ matrix.dockerfile }}
provenance: false
version_bump:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update Release Version
id: version_bump
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG_NAME=${GITHUB_REF##*/v}
if [[ $TAG_NAME =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
sed -i "s/^VERSION=.*/VERSION=${TAG_NAME}/" ./app/.env
sed -i "s/^version: .*/version: ${TAG_NAME}/" ./home_assistant/config.yml
echo "tag=${TAG_NAME}" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: 'Bump Version to v${{ steps.version_bump.outputs.tag }}'
file_pattern: 'app/.env home_assistant/config.yml'