-
Notifications
You must be signed in to change notification settings - Fork 20
85 lines (81 loc) · 2.48 KB
/
build_production_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
75
76
77
78
79
80
81
82
83
84
name: Build Production Image
on:
workflow_dispatch:
inputs:
branch:
description: 'Git Reference to Build Into an Image'
required: true
default: trunk
repo:
description: 'Docker Repo to Push Image To'
required: true
tag:
description: 'Name for Image'
required: false
default: edge
push:
branches: 'trunk'
tags: 'v*.*.*' #all version tags
jobs:
generate-image:
runs-on: ubuntu-latest
steps:
-
name: Setup QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Git Build Context
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.event.inputs.branch }}
-
name: Determine Image Tags
id: generate_tag
run: |
source ${GITHUB_WORKSPACE}/.github/actions/common.sh
_tags=""
if [[ $GITHUB_EVENT_NAME == "workflow_dispatch" ]]; then
_repo=${{ github.event.inputs.repo }}
_input_tag=${{ github.event.inputs.tag }}
if [[ ${_repo} == "ldmx/pro" ]]; then
error "Provided 'ldmx/pro' repo on non-trunk branch."
exit 1
fi
_tags="${_repo}:${_input_tag},${_repo}:sha-${GITHUB_SHA::8}"
elif [[ $GITHUB_REF == refs/tags/* ]]; then
# if pushing a git tag ==> get the git tag for the docker tag
_git_tag=${GITHUB_REF#refs/tags/}
_tags="ldmx/pro:$_git_tag"
if [[ $_git_tag =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
# there was a version released on github
# v<1-3 digits>.<1-3 digits>.<1-3 digits>
_tags="$_tags,ldmx/pro:latest"
fi
elif [[ $GITHUB_REF == refs/heads/* ]]; then
#pushing to trunk
_tags="ldmx/pro:edge,ldmx/pro:sha-${GITHUB_SHA::8}"
else
error "Running Determine Image Tags on a commit that isn't a tag or a branch."
exit 1
fi
set_output tags ${_tags}
set_output should_push ${_should_push}
shell: bash
-
name: Build the Image
id: docker_build
uses: docker/build-push-action@v6
with:
tags: ${{ steps.generate_tag.outputs.tags }}
push: true
context: .