Build & Publish Docker image #14
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
name: Build & Publish Docker image | |
on: | |
release: | |
types: [ created ] | |
secrets: | |
DOCKER_USERNAME: | |
required: true | |
DOCKER_TOKEN: | |
required: true | |
workflow_dispatch: | |
inputs: | |
version: | |
type: string | |
description: Version number | |
required: true | |
jobs: | |
publish: | |
name: Build & Publish to DockerHub and GitHub Packages | |
runs-on: ubuntu-latest | |
if: contains(github.event.head_commit.message, '[no build]') == false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Establish variables | |
id: vars | |
run: | | |
echo "app_name=plex_prerolls" >> "$GITHUB_OUTPUT" | |
echo "version=${{ github.event.inputs.version || github.event.release.tag_name }}" >> "$GITHUB_OUTPUT" | |
echo "major_version=$(echo ${{ github.event.inputs.version || github.event.release.tag_name }} | cut -d '.' -f 1)" >> "$GITHUB_OUTPUT" | |
echo "today=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT" | |
echo "year=$(date +'%Y')" >> "$GITHUB_OUTPUT" | |
- name: Update version number | |
uses: jacobtomlinson/gha-find-replace@2.0.0 | |
with: | |
find: "VERSIONADDEDBYGITHUB" | |
replace: "${{ steps.vars.outputs.version }}" | |
regex: false | |
- name: Update copyright year | |
uses: jacobtomlinson/gha-find-replace@2.0.0 | |
with: | |
find: "YEARADDEDBYGITHUB" | |
replace: "${{ steps.vars.outputs.year }}" | |
regex: false | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
id: docker-buildx | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Gitea Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ secrets.GITEA_REGISTRY }} | |
username: ${{ secrets.GITEA_USERNAME }} | |
password: ${{ secrets.GITEA_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
builder: ${{ steps.docker-buildx.outputs.name }} | |
context: . | |
file: ./Dockerfile | |
push: true | |
platforms: linux/amd64,linux/armhf,linux/arm64 | |
tags: | | |
nwithan8/${{ steps.vars.outputs.app_name }}:latest | |
nwithan8/${{ steps.vars.outputs.app_name }}:${{ steps.vars.outputs.version }} | |
nwithan8/${{ steps.vars.outputs.app_name }}:${{ steps.vars.outputs.major_version }} | |
ghcr.io/nwithan8/${{ steps.vars.outputs.app_name }}:latest | |
ghcr.io/nwithan8/${{ steps.vars.outputs.app_name }}:${{ steps.vars.outputs.version }} | |
ghcr.io/nwithan8/${{ steps.vars.outputs.app_name }}:${{ steps.vars.outputs.major_version }} | |
${{ secrets.GITEA_REGISTRY }}/nwithan8/${{ steps.vars.outputs.app_name }}:latest | |
${{ secrets.GITEA_REGISTRY }}/nwithan8/${{ steps.vars.outputs.app_name }}:${{ steps.vars.outputs.version }} | |
${{ secrets.GITEA_REGISTRY }}/nwithan8/${{ steps.vars.outputs.app_name }}:${{ steps.vars.outputs.major_version }} | |
labels: | | |
org.opencontainers.image.title=${{ steps.vars.outputs.app_name }} | |
org.opencontainers.image.version=${{ steps.vars.outputs.version }} | |
org.opencontainers.image.created=${{ steps.vars.outputs.today }} |