-
Notifications
You must be signed in to change notification settings - Fork 155
119 lines (106 loc) · 4.58 KB
/
Copy pathpublish-and-deploy-images.yaml
File metadata and controls
119 lines (106 loc) · 4.58 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: "Build and publish mythical images"
on:
push:
branches:
- 'main'
paths:
- source/**
pull_request:
types: [opened, synchronize]
paths:
- source/**
jobs:
build_and_push_images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY_LOCATION: ghcr.io/grafana/intro-to-mltp
strategy:
fail-fast: false
matrix:
file_tag:
- file: source/docker/Dockerfile
tag_suffix: mythical-beasts-requester
context: source
service: mythical-beasts-requester
setup-qemu: true
- file: source/docker/Dockerfile
tag_suffix: mythical-beasts-server
context: source
service: mythical-beasts-server
setup-qemu: true
- file: source/docker/Dockerfile
tag_suffix: mythical-beasts-recorder
context: source
service: mythical-beasts-recorder
setup-qemu: true
- file: source/mythical-beasts-frontend/Dockerfile
tag_suffix: mythical-beasts-frontend
context: source/mythical-beasts-frontend
service: mythical-beasts-frontend
setup-qemu: true
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
persist-credentials: false
- name: DetermineReference
id: get_reference
run: |
if [ -z "$GITHUB_HEAD_REF" ]; then
echo "ref=$GITHUB_REF" >> "$GITHUB_OUTPUT"
else
echo "ref=$GITHUB_HEAD_REF" >> "$GITHUB_OUTPUT"
fi
- name: Determine image_tag to use
id: image_tag
run: |
SHA=$(git rev-parse --short HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD | tr '/' '__')
REF_TAG=${{ steps.get_reference.outputs.ref }}
echo "SHA: $SHA"
echo "Branch: $BRANCH"
echo "Ref tag: $REF_TAG"
if [[ $REF_TAG =~ refs\/(heads|tags)\/ ]]; then
REF_TAG=$(echo $REF_TAG | cut -d "/" -f 3)
echo "Shortened ref tag is $REF_TAG"
fi
REF_TAG=$(echo -n "$REF_TAG" | tr -c '[:alnum:]._' '-')
echo "version=$REF_TAG" >> "$GITHUB_OUTPUT"
echo "Using version tag $REF_TAG"
# Finally check to see if we're building on main; if we are, add a tag for latest.
if [ "$BRANCH" == "main" ]; then
echo "latest_tag=${{env.REGISTRY_LOCATION}}:${{matrix.file_tag.tag_suffix}}-latest" >> "$GITHUB_OUTPUT"
fi
- name: Set up QEMU
if: ${{ matrix.file_tag.setup-qemu }}
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392
with:
image: tonistiigi/binfmt:master
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
with:
config-inline: |
[worker.oci]
max-parallelism = 2
- name: Login to GitHub Container Registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Matrix Build and push Mythical images
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1
with:
context: ${{ matrix.file_tag.context }}
file: ${{ matrix.file_tag.file }}
build-args: |
SERVICE=${{ matrix.file_tag.service }}
platforms: linux/amd64,linux/arm64
# Only push to the registry on pushes to main; pull request runs build only to validate.
push: ${{ github.event_name == 'push' }}
tags: |
${{ env.REGISTRY_LOCATION }}:${{ matrix.file_tag.tag_suffix }}-${{ steps.image_tag.outputs.version }}
${{ steps.image_tag.outputs.latest_tag }}