Skip to content

Housekeeping-2023

Housekeeping-2023 #140

Workflow file for this run

name: Docker Build
on: [push]
env:
DOCKER_REGISTRY_IMAGE: ghcr.io/fortrabbit/craft-copy
DOCKER_REGISTRY_IMAGE_DEV: ghcr.io/fortrabbit/craft-copy-dev
jobs:
build:
name: Build
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ./docker
strategy:
fail-fast: false
matrix:
craft_image_tag: ['7.4', '8.0', '8.1']
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Slugify branch name
shell: bash
run: echo "branch_slug=$(echo $GITHUB_REF | sed -E 's/refs\/(heads|tags)\///g' | iconv -t ascii//TRANSLIT | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z)" >> $GITHUB_ENV
# Usage: ${{ env.branch_slug }}
- name: Build docker image
working-directory: ./docker
run: |
docker build \
--build-arg CRAFT_IMAGE_TAG="${{ matrix.craft_image_tag }}" \
--tag $DOCKER_REGISTRY_IMAGE:${{ matrix.craft_image_tag }} \
--tag $DOCKER_REGISTRY_IMAGE:${{ matrix.craft_image_tag }}_${{ env.branch_slug }} \
--tag $DOCKER_REGISTRY_IMAGE_DEV:${{ matrix.craft_image_tag }}_${{ env.branch_slug }} \
.
# Only publish main image (:8.0) on tag push matching "1.0.5" format
# https://stackoverflow.com/questions/58862864/github-actions-ci-conditional-regex
- name: Check if we are on a semantic git tag
id: check-tag
run: |
if [[ ${{ github.event.ref }} =~ ^refs/tags/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo ::set-output name=match::true
fi
# Dev image will contain all builds from all branches
# ghcr.io/fortrabbit/craft-copy-dev:8.0_main
# ghcr.io/fortrabbit/craft-copy-dev:8.0_feature-branch
- name: Publish dev image
if: steps.check-tag.outputs.match != 'true'
run: |
docker push $DOCKER_REGISTRY_IMAGE_DEV:${{ matrix.craft_image_tag }}_${{ env.branch_slug }}
# Main image will contain only builds from semantic tags
# ghcr.io/fortrabbit/craft-copy:8.0 - removed push to not break old installs of craft-copy that depend on old version of the image
# ghcr.io/fortrabbit/craft-copy:8.0_1.2.3
- name: Publish main image
if: steps.check-tag.outputs.match == 'true'
run: |
docker push $DOCKER_REGISTRY_IMAGE:${{ matrix.craft_image_tag }}_${{ env.branch_slug }}