-
Notifications
You must be signed in to change notification settings - Fork 25
74 lines (67 loc) · 2.08 KB
/
build-and-push-image.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
name: Build and push image
on:
workflow_call:
inputs:
imageName:
required: false
type: string
default: ${{ github.event.repository.name }}
dockerfilePath:
required: false
type: string
default: Dockerfile
buildArgs:
required: false
type: string
gitRef:
required: false
type: string
default: ${{ github.sha }}
outputs:
imageTag:
description: "The image tag for the built image"
value: ${{ jobs.build-and-push-image.outputs.imageTag }}
jobs:
build-and-push-image:
name: Build and push image
runs-on: ubuntu-latest
outputs:
imageTag: ${{ steps.meta.outputs.version }}
permissions:
id-token: write
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.gitRef }}
show-progress: false
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
id: local-head
- name: Determine image tags
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/govuk/${{ inputs.imageName }}
tags: |
type=raw,priority=500,value=${{ inputs.gitRef }},enable=${{ startsWith(inputs.gitRef, 'v') }}
type=raw,priority=400,value=${{ steps.local-head.outputs.sha }},enable=${{ !startsWith(inputs.gitRef, 'v') }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: ${{ inputs.dockerfilepath }}
build-args: ${{ inputs.buildArgs }}
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max