-
Notifications
You must be signed in to change notification settings - Fork 27
169 lines (149 loc) · 4.99 KB
/
build-prod-container.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Build and Push Prod Image
on:
pull_request:
push:
branches:
- main
repository_dispatch:
types:
- dispatch-build
workflow_dispatch:
workflow_call:
inputs:
from_workflow_call:
required: false
type: boolean
default: true
permissions:
contents: write
jobs:
build-base-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache base image
uses: actions/cache@v4
with:
path: /tmp/.base-buildx-cache
key: base-buildx-${{ github.sha }}-${{ github.run_id }}
# allow cache hits from previous runs of the current branch,
# parent branch, then upstream branches, in that order
restore-keys: |
base-buildx-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
file: ./images/Dockerfile
target: final-stage
build-args: |
IS_PR_BUILD=${{ github.event_name == 'pull_request' }}
cache-from: type=local,src=/tmp/.base-buildx-cache
cache-to: type=local,dest=/tmp/.base-buildx-cache,mode=max
make-date-tag:
runs-on: ubuntu-latest
outputs:
dtag: ${{ steps.mkdatetag.outputs.dtag }}
steps:
- name: make date tag
id: mkdatetag
run: echo "dtag=$(date +%Y%m%d-%H%M)" >> $GITHUB_OUTPUT
build-server-images:
needs: [build-base-image, make-date-tag]
strategy:
fail-fast: False
matrix:
image:
- cache
- origin
- director
- registry
- osdf-cache
- osdf-origin
- osdf-director
- osdf-registry
runs-on: ubuntu-latest
steps:
- name: Set Branch
id: set_branch
if: ${{ inputs.from_workflow_call }}
run: |
echo "branch=${GITHUB_REF_NAME%.*}.x" >> $GITHUB_OUTPUT
- name: Checkout for release
uses: actions/checkout@v4
if: ${{ inputs.from_workflow_call }}
with:
fetch-depth: 0
ref: ${{ steps.set_branch.outputs.branch }}
- name: Checkout for push to main
uses: actions/checkout@v4
if: ${{ !inputs.from_workflow_call }}
- name: Generate tag list
id: generate-tag-list
env:
TIMESTAMP: ${{ needs.make-date-tag.outputs.dtag }}
# Here, we either tag the container with the "latest" tag if
# the commit that triggered this action doesn't have a tag,
# or we tag it with the commit's tag if one exists
run: |
# Check if we're working with a tagged version
if [ -z "${{ inputs.tag }}" ]
then
# Use regex to check for a semver tag match
if [[ ${GITHUB_REF##*/} =~ v[0-9]+\.[0-9]+\.[0-9]+ ]]
then
GITHUB_TAG=${GITHUB_REF##*/}
else
GITHUB_TAG="latest"
fi
else
GITHUB_TAG=${{ inputs.tag }}
fi
echo "Master SHA:"
echo $(git rev-parse $GITHUB_REF_NAME)
echo "Current SHA:"
echo $(git rev-parse HEAD)
echo $GITHUB_TAG
docker_repo="pelican_platform/pelican"
tag_list=()
for registry in hub.opensciencegrid.org; do
for image_tag in "$GITHUB_TAG"; do
tag_list+=("$registry/$docker_repo":"$image_tag")
done
done
# This causes the tag_list array to be comma-separated below,
# which is required for build-push-action
IFS=,
echo "::set-output name=taglist::${tag_list[*]}"
- name: Load cached base image
uses: actions/cache@v4
with:
path: /tmp/.base-buildx-cache
key: base-buildx-${{ github.sha }}-${{ github.run_id }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Log in to OSG Harbor
uses: docker/login-action@v3
if: github.repository == 'PelicanPlatform/pelican' && github.event_name != 'pull_request'
with:
registry: hub.opensciencegrid.org
username: ${{ secrets.PELICAN_HARBOR_ROBOT_USER }}
password: ${{ secrets.PELICAN_HARBOR_ROBOT_PASSWORD }}
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
file: ./images/Dockerfile
push: ${{ github.repository == 'PelicanPlatform/pelican' && github.event_name != 'pull_request' }}
tags: "${{ steps.generate-tag-list.outputs.taglist }}"
target: ${{ matrix.image }}
build-args: |
IS_PR_BUILD=${{ github.event_name == 'pull_request' }}
cache-from: type=local,src=/tmp/.base-buildx-cache
cache-to: type=local,dest=/tmp/.${{ matrix.image }}-buildx-cache,mode=max