-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (74 loc) · 2.64 KB
/
build-image.yml
File metadata and controls
86 lines (74 loc) · 2.64 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
name: Build the target Docker image
on:
workflow_call:
inputs:
image_name:
required: true
type: string
description: Image name without tag, e.g. 'repo/app'
image_tag_suffix:
required: true
type: string
default: ''
target_env:
required: true
type: string
default: 'production'
# options:
# - production
# - dev
settings_module:
required: true
type: string
default: 'docker'
# options:
# - docker
# - dev
outputs:
image_name:
description: Image name + tag of the built image
value: ${{ jobs.image_build.outputs.image_name }}
artifact_name:
description: Artifact name for the built image
value: ${{ jobs.image_build.outputs.artifact_name }}
jobs:
image_build:
name: Build image
runs-on: ubuntu-latest
env:
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_BUILDKIT: 1
outputs:
image_name: ${{ steps.build-args.outputs.image_name }}
artifact_name: ${{ steps.build-args.outputs.artifact_name }}
steps:
- uses: actions/checkout@v4
- name: Extract build args
id: build-args
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
# PRs result in version 'merge' -> transform that into 'latest'
[ "$VERSION" == "merge" ] && VERSION=latest
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "image_name=${{ inputs.image_name }}:${VERSION}${{ inputs.image_tag_suffix }}" >> $GITHUB_OUTPUT
echo "artifact_name=docker-image-${VERSION}${{ inputs.image_tag_suffix }}" >> $GITHUB_OUTPUT
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
- name: Build the Docker image
run: |
docker build . \
--tag ${{ steps.build-args.outputs.image_name }} \
--build-arg COMMIT_HASH=${{ steps.build-args.outputs.git_hash }} \
--build-arg RELEASE=${{ steps.build-args.outputs.version }} \
--build-arg TARGET_ENVIRONMENT=${{ inputs.target_env }} \
--build-arg SETTINGS_MODULE=${{ inputs.settings_module }}
- name: Dump image to file
run: docker image save -o image.tar ${{ steps.build-args.outputs.image_name }}
- name: Store image artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build-args.outputs.artifact_name }}
path: image.tar
retention-days: 1