Skip to content

Build and Push Docker Images #281

Build and Push Docker Images

Build and Push Docker Images #281

Workflow file for this run

name: Build and Push Docker Images
on:
release:
types: [published]
jobs:
# build all the image variants
build:
runs-on: ubuntu-latest
steps:
# checkout repo
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get branch/tag name
id: get_branch
run: |
export BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e "s/refs\/heads\///g" -e "s/refs\/tags\///g")
echo $BRANCH_NAME
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
- name: Set image tag
id: image_tag
run: |
export IMAGE_TAG=$(if [[ "${{ steps.get_branch.outputs.BRANCH_NAME }}" =~ (latest|master|main) ]]; then echo "latest"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}"; fi)
echo $IMAGE_TAG
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set alternate image tag
id: alt_image_tag
run: |
export ALT_IMAGE_TAG=$(if [[ "${{ steps.get_branch.outputs.BRANCH_NAME }}" =~ (latest|master|main) ]]; then echo "ubuntu"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}-ubuntu"; fi)
echo $ALT_IMAGE_TAG
echo "ALT_IMAGE_TAG=${ALT_IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set versioned image tag
id: versioned_image_tag
run: |
export FORMATED_DATE=`date +%Y-%m-%d`
export VERSION_IMAGE_TAG=$(if [[ "${{ steps.get_branch.outputs.BRANCH_NAME }}" =~ (latest|master|main) ]]; then echo ${FORMATED_DATE}; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}-${FORMATED_DATE}"; fi)
echo $VERSION_IMAGE_TAG
echo "VERSION_IMAGE_TAG=${VERSION_IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set Package Versions
id: pkg_version
run: |
get_latest_release() {
curl --silent "https://github.com/gitapi/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
export HOMEBRIDGE_APT_PKG_VERSION=`get_latest_release "homebridge/homebridge-apt-pkg"`
export FFMPEG_VERSION=`get_latest_release "homebridge/ffmpeg-for-homebridge"`
echo "HOMEBRIDGE_APT_PKG_VERSION=${HOMEBRIDGE_APT_PKG_VERSION}" >> $GITHUB_OUTPUT
echo "FFMPEG_VERSION=${FFMPEG_VERSION}" >> $GITHUB_OUTPUT
- name: Log into GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Image to GitHub Container Registry
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
build-args: |
HOMEBRIDGE_APT_PKG_VERSION=${{ steps.pkg_version.outputs.HOMEBRIDGE_APT_PKG_VERSION }}
FFMPEG_VERSION=${{ steps.pkg_version.outputs.FFMPEG_VERSION }}
tags: |
ghcr.io/homebridge/homebridge:latest
ghcr.io/homebridge/homebridge:ubuntu
ghcr.io/homebridge/homebridge:${{ steps.image_tag.outputs.IMAGE_TAG }}
- name: Log into Docker Hub
uses: docker/login-action@v3
if: github.repository == 'homebridge/docker-homebridge'
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Image to Docker Hub
uses: docker/build-push-action@v5
if: github.repository == 'homebridge/docker-homebridge'
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
build-args: |
HOMEBRIDGE_APT_PKG_VERSION=${{ steps.pkg_version.outputs.HOMEBRIDGE_APT_PKG_VERSION }}
FFMPEG_VERSION=${{ steps.pkg_version.outputs.FFMPEG_VERSION }}
tags: |
homebridge/homebridge:latest
homebridge/homebridge:ubuntu
homebridge/homebridge:${{ steps.image_tag.outputs.IMAGE_TAG }}
tag:
name: Verify Release Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Get Release Tag
id: get_version
uses: jannemattila/get-version-from-tag@v3
- name: Tag Info
run: |
echo "Release Tag: ${{github.ref}}"
echo "Latest Tag: ${{ steps.get_version.outputs.version }}"
- name: Tag Info Matches
if: endsWith(github.ref, steps.get_version.outputs.version )
run: |
echo Latest Tag matches Release tag
- name: Tag Info Doesn't Match
if: ${{ !endsWith(github.ref, steps.get_version.outputs.version ) }}
run: |
echo Latest Tag does not matches Release tag
exit 1
github-releases-to-discord:
name: Discord Webhooks
needs: build
uses: homebridge/.github/.github/workflows/discord-webhooks.yml@latest
with:
title: "Homebridge Docker Release"
description: |
Version `${{ github.event.release.tag_name }}`
url: "https://github.com/homebridge/homebridge-docker/releases/tag/${{ github.event.release.tag_name }}"
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_LATEST }}