Skip to content

Docker

Docker #49

Workflow file for this run

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:
include:
- dockerfile: multiarch
- dockerfile: hwaccel
qsv: 0
- dockerfile: hwaccel
qsv: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Show matrix image type
id: image_type
run: |
echo "suffix=${{ matrix.dockerfile == 'hwaccel' && ((matrix.qsv == 0 && '-hw') || (matrix.qsv == 1 && '-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,aarch64,armhf' || 'amd64' }}" >> $GITHUB_OUTPUT
- 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: 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@v3
with:
platforms: ${{ steps.image_type.outputs.platforms }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/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=semver,pattern={{major}}.{{minor}},suffix=${{ steps.image_type.outputs.suffix }}
type=semver,pattern={{major}},suffix=${{ steps.image_type.outputs.suffix }}
type=edge,branch=$repo.default_branch,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 }}
type=ref,event=pr,suffix=${{ steps.image_type.outputs.suffix }}
type=sha,format=long,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=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
GITHUB_SHA=${{ github.sha }}
QSV=${{ matrix.qsv }}
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'