-
Notifications
You must be signed in to change notification settings - Fork 139
91 lines (84 loc) · 3.13 KB
/
_docker-build-push.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
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
name: Docker build and docker push (reusable)
on:
workflow_call:
inputs:
registry:
description: 'A container registry where the image is stored'
default: 'ghcr.io'
required: false
type: string
organization:
description: 'An organization the image is associated with'
default: 'blockscout'
required: false
type: string
service-name:
required: true
type: string
docker-context-path:
required: false
type: string
dockerfile-path:
required: false
type: string
secrets:
ARM_RUNNER_HOSTNAME:
required: true
ARM_RUNNER_KEY:
required: true
outputs:
tag-value:
description: 'A semver compatible version retrieved from the tag'
value: ${{ jobs.build-and-push.outputs.tag-value }}
jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 300
env:
IMAGE_NAME: '${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.service-name }}'
outputs:
tag-value: ${{ steps.regex.outputs.group2 }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions-ecosystem/action-regex-match@v2
id: regex
with:
text: ${{ github.ref }}
regex: '^(refs\/tags\/${{ inputs.service-name }}\/(v\d+\.\d+\.\d+))|(refs\/heads\/(main))$'
- name: Extract tag name
id: tags_extractor
run: |
t=${{ steps.regex.outputs.group2 }}
m=${{ steps.regex.outputs.group4 }}
(if ! [[ "$t" == "" ]]; then echo tags=${{ env.IMAGE_NAME }}:$t, ${{ env.IMAGE_NAME }}:latest; elif ! [[ "$m" == "" ]]; then echo tags=${{ env.IMAGE_NAME }}:$m; else echo tags=; fi) >> $GITHUB_OUTPUT
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
- name: Setup repo
uses: blockscout/blockscout-ci-cd/.github/actions/setup-multiarch-buildx@master
id: setup
with:
docker-image: ${{ env.IMAGE_NAME }}
docker-username: ${{ github.actor }}
docker-password: ${{ secrets.GITHUB_TOKEN }}
docker-remote-multi-platform: true
docker-arm-host: ${{ secrets.ARM_RUNNER_HOSTNAME }}
docker-arm-host-key: ${{ secrets.ARM_RUNNER_KEY }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context-path || format('{0}/', inputs.service-name) }}
file: ${{ inputs.dockerfile-path || format('{0}/Dockerfile', inputs.service-name) }}
build-contexts: |
proto=proto
push: ${{ steps.tags_extractor.outputs.tags != '' }}
tags: ${{ steps.tags_extractor.outputs.tags }}
platforms: |
linux/amd64
linux/arm64/v8
labels: ${{ steps.setup.outputs.docker-labels }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:build-cache
cache-to: ${{ github.ref == 'refs/heads/main' && format('type=registry,ref={0}:build-cache,mode=max', env.IMAGE_NAME) || '' }}