-
Notifications
You must be signed in to change notification settings - Fork 8
66 lines (59 loc) · 2.97 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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 }}