Skip to content

Create build workflow #1

Create build workflow

Create build workflow #1

Workflow file for this run

name: "Docker Build and Push"
on:
release:
types: ["published"]
push:
branches: ["master"]
pull_request:
branches: ["master"]
workflow_dispatch:
inputs:
push:
type: boolean
description: "Push image after build"
default: false
tags:
type: string
description: "Tags to apply to built image in addition to commit ID (separated by spaces)"
default: ""
jobs:
build:
name: Build and push docker images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Prepare tag list (manual trigger)
if: github.event_name == 'workflow_dispatch'
run: |
declare -a tags
for tag in ${{ github.inputs.tags }}
do
tags+=("$tag")
done
tags+=("$(git rev-parse --short HEAD)")
echo "tags=\"${tags[@]}\"" >> $GITHUB_ENV
- name: Prepare tag list (push trigger)
if: github.event_name != 'workflow_dispatch'
run: |
release=$(git tag --points-at HEAD)
echo "tags=\"latest $(git rev-parse --short HEAD)\" $release" >> $GITHUB_ENV
- name: Check push configuration
run: |
auto=1
manual=1
release=1
if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]
then
auto=0
fi
if [ "${{ github.inputs.push }}" = "true" ]
then
manual=0
fi
if [ "${{ github.event_name }}" = "release" ]
then
release=0
fi
push=`[[ $auto -eq 0 || $manual -eq 0 || $release -eq 0 ]] && echo 'true' || echo 'false'`
echo "do_push=$push" >> $GITHUB_ENV
- name: Build Cadence server image
run: |
IMAGE=kenellorando/cadence
declare -a flags
for tag in "${{ env.tags }}"
do
flags+=("-t $IMAGE:$tag")
done
docker build ${flags[@]} -f src/cadence.Dockerfile src
- name: Build icecast2 image
run: |
IMAGE=kenellorando/cadence_icecast2
declare -a flags
for tag in "${{ env.tags }}"
do
flags+=("-t $IMAGE:$tag")
done
docker build ${flags[@]} -f src/icecast2.Dockerfile src
- name: Build liquidsoap image
run: |
IMAGE=kenellorando/cadence_liquidsoap
declare -a flags
for tag in "${{ env.tags }}"
do
flags+=("-t $IMAGE:$tag")
done
docker build ${flags[@]} -f src/liquidsoap.Dockerfile src
- name: Login to Docker Hub
if: env.push == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Push Cadence images
if: env.push == 'true'
run: |
sha=$(git rev-parse --short HEAD)
docker push --all-tags kenellorando/cadence:$sha
docker push --all-tags kenellorando/cadence_icecast2:$sha
docker push --all-tags kenellorando/cadence_liquidsoap:$sha