Skip to content

Merge branch 'master' into development #48

Merge branch 'master' into development

Merge branch 'master' into development #48

Workflow file for this run

name: Publish Docker image
on:
workflow_dispatch:
push:
branches:
- 'master'
- 'development'
- 'beta'
- 'hotfix/*'
tags:
- 'v*.*.*'
env:
TEST_TAG: unifi:test
PKGURL: https://dl.ui.com/unifi/6.5.55/unifi_sysvinit_all.deb
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Resgistry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Build and export to Docker
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: ${{ env.TEST_TAG }}
- name: Test image
run: |
export PKGURL=${{env.PKGURL}} &&
docker run -d --env PKGURL --rm --name unifitest ${{env.TEST_TAG}} &&
sleep 35 &&
for i in $(seq 1 10); do [ $(docker inspect --format='{{json .State.Health.Status}}' unifitest ) == \"healthy\" ] && break || sleep 35; done &&
[ $(docker inspect --format='{{json .State.Health.Status}}' unifitest ) == \"healthy\" ] &&
docker stop unifitest
- name: Prepare image names
id: prep
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
USER="${GITHUB_REPOSITORY_OWNER}"
IMAGE_NAME="$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | sed s/docker-//)"
DOCKER_IMAGE="${USER}/${IMAGE_NAME}"
IMAGES=""
if [ "$DOCKERHUB_USERNAME" != '' ] && [ "$DOCKERHUB_TOKEN" != '' ]; then
IMAGES="${DOCKER_IMAGE}"
fi
if [ "$IMAGES" != '' ]; then
IMAGES="${IMAGES},ghcr.io/${DOCKER_IMAGE}"
else
IMAGES="ghcr.io/${DOCKER_IMAGE}"
fi
echo "images=${IMAGES}" >> "$GITHUB_OUTPUT"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}
type=semver,pattern=v{{major}}.{{minor}}
type=ref,event=branch
images: |
${{ steps.prep.outputs.images }}
- name: Build container image
uses: docker/build-push-action@v4
with:
context: .
provenance: false
platforms: linux/arm64/v8,linux/amd64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.tags }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}