Skip to content

Build and Push voltaserve/console #3

Build and Push voltaserve/console

Build and Push voltaserve/console #3

Workflow file for this run

# Copyright 2023 Anass Bouassaba, Piotr Łoboda.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the GNU Affero General Public License v3.0 only, included in the file
# licenses/AGPL.txt.
name: Build and Push voltaserve/console
on:
workflow_dispatch:
inputs:
branch:
required: false
default: ""
type: string
description: Override code checkout branch (e.g. "feature/branch")
push:
branches:
- main
paths:
- "console/**"
tags:
- 'v*'
jobs:
prepare_env:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.input_branch.outputs.branch }}
tags: ${{ steps.tag.outputs.tags || steps.tags.outputs.tags }}
steps:
- name: Prepare input branch
id: input_branch
if: ${{ github.event.inputs.branch != '' }}
run: echo "branch=refs/heads/${{ github.event.inputs.branch }}" >> $GITHUB_OUTPUT
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ steps.input_branch.outputs.branch || github.ref }}
- name: Create tag list matching semver from executing tag
id: tag
if: ${{ github.ref_type == 'tag' }}
run: |
name="voltaserve/console"
version="${{ github.ref_name }}"
version="${version#v}"
IFS='.' read -r -a parts <<< "$version"
TAGS="$name:$version"
for ((i=${#parts[@]}-1; i>0; i--)); do
tag=$(IFS='.'; echo "${parts[*]:0:$i}")
TAGS+=",$name:$tag"
done
TAGS+=",$name:latest"
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Set the tag on workflow dispatch
id: tags
if: ${{ github.ref_type != 'tag' }}
run: echo "tags=voltaserve/console:$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
build_and_push:
runs-on: ubuntu-latest
needs: prepare_env
strategy:
matrix:
platform: [ "arm64", "amd64" ]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare_env.outputs.branch || github.ref }}
- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./console
push: true
tags: ${{ needs.prepare_env.outputs.tags }}
platforms: ${{ matrix.platform }}