Build and push docker (tag) #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Builds & pushes a docker image when a tag is created. | |
# Tag pattern: '[tag]' & '[tag]-classic' | |
# 'latest' & 'classic' also, when master tagged. | |
# Only pushes the tag when it matches one of the following patterns: | |
# X, X.Y or X.Y.Z | |
name: Build and push docker (tag) | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- '[0-9]+' # X | |
- '[0-9]+\.[0-9]+' # X.Y | |
- '[0-9]+\.[0-9]+\.[0-9]+' # X.Y.Z | |
env: | |
DOCKER_PLATFORMS: linux/386,linux/amd64,linux/arm/v6,linux/arm64,linux/arm/v7 | |
NQPTP_BRANCH: main | |
jobs: | |
main: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3.5.2 | |
with: | |
fetch-depth: 0 | |
- name: Set SHAIRPORT_SYNC_BRANCH env. | |
run: | | |
raw=$(git branch -r --contains ${{ github.ref }}) | |
branch=${raw##*/} | |
echo "SHAIRPORT_SYNC_BRANCH=${branch}" >> $GITHUB_ENV | |
- name: Set tag env | |
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | |
- name: Is branch "master"? | |
if: ${{ env.SHAIRPORT_SYNC_BRANCH == 'master' }} | |
run: echo "LATEST_TAG=true" >> $GITHUB_ENV | |
- name: Is branch "development"? | |
if: ${{ env.SHAIRPORT_SYNC_BRANCH == 'development' }} | |
run: | | |
echo "NQPTP_BRANCH=development" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2.1.0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2.5.0 | |
- name: Login to Docker Registry | |
uses: docker/login-action@v2.1.0 | |
with: | |
registry: ${{ secrets.DOCKER_REGISTRY }} | |
username: ${{ secrets.DOCKER_REGISTRY_USER }} | |
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} | |
- name: Build and push (classic) | |
uses: docker/build-push-action@v4.0.0 | |
with: | |
context: ./ | |
file: ./docker/classic/Dockerfile | |
platforms: ${{ env.DOCKER_PLATFORMS }} | |
push: true | |
tags: | | |
${{ secrets.DOCKER_IMAGE_NAME }}:${{ env.GIT_TAG }}-classic | |
${{ env.LATEST_TAG == 'true' && format('{0}:classic', secrets.DOCKER_IMAGE_NAME) || '' }} | |
build-args: | | |
SHAIRPORT_SYNC_BRANCH=${{ env.SHAIRPORT_SYNC_BRANCH }} | |
- name: Build and push | |
uses: docker/build-push-action@v4.0.0 | |
with: | |
context: ./ | |
file: ./docker/Dockerfile | |
platforms: ${{ env.DOCKER_PLATFORMS }} | |
push: true | |
tags: | | |
${{ secrets.DOCKER_IMAGE_NAME }}:${{ env.GIT_TAG }} | |
${{ env.LATEST_TAG == 'true' && format('{0}:latest', secrets.DOCKER_IMAGE_NAME) || '' }} | |
build-args: | | |
SHAIRPORT_SYNC_BRANCH=${{ env.SHAIRPORT_SYNC_BRANCH }} | |
NQPTP_BRANCH=${{ env.NQPTP_BRANCH }} |