Skip to content

Commit 09f3d02

Browse files
committed
Add image exist checks to tag builds.
Signed-off-by: Humair Khan <[email protected]>
1 parent 3fdfafe commit 09f3d02

File tree

2 files changed

+123
-157
lines changed

2 files changed

+123
-157
lines changed

.github/actions/build/action.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: "Set up KinD"
2+
description: "Step to start and configure KinD cluster"
3+
inputs:
4+
IMAGE_REPO:
5+
description: "Quay image repo name."
6+
required: true
7+
DOCKERFILE:
8+
description: "Path to Dockerfile."
9+
required: true
10+
GH_REPO:
11+
description: "GH org/repo that contains the dockerfile to source."
12+
required: true
13+
OVERWRITE:
14+
default: "false"
15+
description: "GH org/repo that contains the dockerfile to source."
16+
required: true
17+
runs:
18+
using: "composite"
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
repository: ${{ inputs.GH_REPO }}
23+
ref: ${{ env.SOURCE_BRANCH }}
24+
path: build
25+
- name: Login to Quay.io
26+
uses: redhat-actions/podman-login@v1
27+
with:
28+
username: ${{ env.QUAY_ID }}
29+
password: ${{ env.QUAY_TOKEN }}
30+
registry: quay.io
31+
# Tags in quay stick around as objects in api, when deleted quay adds "end_ts" time stamp on the tag.
32+
# To determine a tag is deleted, we need to check for the presence of this tag.
33+
# Also note there can be multiple tags created/deleted, thus we have 4 cases:
34+
# Case 1: Only 1 tag was ever created "tags: [{name:..},]" -- no end_ts field
35+
# Case 2: No tag was ever created "tags: []"
36+
# Case 3: >1 tags were created, but they were all deleted at some point [{name:..., end_ts,..},....] -- note they all have "end_ts" field.
37+
# Case 4: >1 tags were created, but the most recent one was never deleted (same as case 3, but the latest tag does not have "end_ts".
38+
- name: Check if Image already exists
39+
shell: bash
40+
if: ${{ inputs.OVERWRITE }} == "false"
41+
env:
42+
IMAGE: quay.io/${{ env.QUAY_ORG }}/${{ inputs.IMAGE_REPO }}:${{ env.TARGET_IMAGE_TAG }}
43+
run: |
44+
tags=$(curl --request GET 'https://quay.io/api/v1/repository/${{ env.QUAY_ORG }}/${{ inputs.IMAGE_REPO }}/tag/?specificTag=${{ env.TARGET_IMAGE_TAG }}')
45+
echo $tags | yq .tags - | yq 'sort_by(.start_ts) | reverse' - -P | yq .[0].end_ts -
46+
latest_tag_has_end_ts=$(echo $tags | yq .tags - | yq 'sort_by(.start_ts) | reverse' - -P | yq .[0].end_ts -)
47+
echo $latest_tag_has_end_ts
48+
notempty=$(echo ${tags} | yq .tags - | yq any)
49+
50+
# Image only exists if there is a tag that does not have "end_ts" (i.e. it is still present).
51+
if [[ "$notempty" == "true" && $latest_tag_has_end_ts == "null" ]]; then
52+
echo "::error::The image ${{ env.IMAGE }} already exists"
53+
exit 1
54+
else
55+
echo "Image does not exist...proceeding with build & push."
56+
fi
57+
- name: Build image
58+
shell: bash
59+
working-directory: build
60+
env:
61+
IMAGE: quay.io/${{ env.QUAY_ORG }}/${{ inputs.IMAGE_REPO }}:${{ env.TARGET_IMAGE_TAG }}
62+
run: |
63+
podman build . -f ${{ inputs.DOCKERFILE }} -t ${{ env.IMAGE }} && podman push ${{ env.IMAGE }}

.github/workflows/tag-and-build.yml

Lines changed: 60 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -20,248 +20,151 @@ on:
2020
description: 'DSP org/repo'
2121
required: true
2222
env:
23-
IMAGE_DSPO: data-science-pipelines-operator
24-
IMAGE_SERVER: ds-pipelines-api-server
25-
IMAGE_UI: ds-pipelines-frontend
26-
IMAGE_CACHE: ds-pipelines-cacheserver
27-
IMAGE_PA: ds-pipelines-persistenceagent
28-
IMAGE_SWF: ds-pipelines-scheduledworkflow
29-
IMAGE_VC: ds-pipelines-viewercontroller
30-
IMAGE_ARTIFACT: ds-pipelines-artifact-manager
31-
IMAGE_MLMD_WRITER: ds-pipelines-metadata-writer
32-
IMAGE_MLMD_ENVOY: ds-pipelines-metadata-envoy
33-
IMAGE_MLMD_GRPC: ds-pipelines-metadata-grpc
23+
IMAGE_REPO_DSPO: data-science-pipelines-operator
24+
IMAGE_REPO_SERVER: ds-pipelines-api-server
25+
IMAGE_REPO_UI: ds-pipelines-frontend
26+
IMAGE_REPO_CACHE: ds-pipelines-cacheserver
27+
IMAGE_REPO_PA: ds-pipelines-persistenceagent
28+
IMAGE_REPO_SWF: ds-pipelines-scheduledworkflow
29+
IMAGE_REPO_VC: ds-pipelines-viewercontroller
30+
IMAGE_REPO_ARTIFACT: ds-pipelines-artifact-manager
31+
IMAGE_REPO_MLMD_WRITER: ds-pipelines-metadata-writer
32+
IMAGE_REPO_MLMD_ENVOY: ds-pipelines-metadata-envoy
33+
IMAGE_REPO_MLMD_GRPC: ds-pipelines-metadata-grpc
34+
SOURCE_BRANCH: ${{ inputs.src_branch }}
35+
QUAY_ORG: ${{ inputs.quay_org }}
36+
QUAY_ID: ${{ secrets.QUAY_ID }}
37+
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
38+
TARGET_IMAGE_TAG: ${{ inputs.target_tag }}
3439
jobs:
3540
dspo-build:
3641
runs-on: ubuntu-latest
3742
permissions:
3843
contents: read
3944
steps:
40-
- uses: actions/checkout@v3
41-
with:
42-
ref: ${{ inputs.src_branch }}
43-
44-
- name: Login to Quay.io
45-
uses: redhat-actions/podman-login@v1
46-
with:
47-
username: ${{ secrets.QUAY_ID }}
48-
password: ${{ secrets.QUAY_TOKEN }}
49-
registry: quay.io
50-
51-
- name: Image Build and Push
52-
run: |
53-
make podman-build podman-push -e IMG=quay.io/${{ inputs.quay_org }}/${IMAGE_DSPO}:${{ inputs.target_tag }}
45+
- uses: actions/checkout@v3
46+
- uses: ./.github/actions/build
47+
with:
48+
IMAGE_REPO: ${{ env.IMAGE_REPO_DSPO }}
49+
DOCKERFILE: Dockerfile
50+
GH_REPO: ${{ github.repository }}
5451

5552
server-build:
5653
runs-on: ubuntu-latest
5754
permissions:
5855
contents: read
5956
steps:
6057
- uses: actions/checkout@v3
58+
- uses: ./.github/actions/build
6159
with:
62-
repository: ${{ inputs.dsp_org_repo }}
63-
ref: ${{ inputs.src_branch }}
64-
- name: Login to Quay.io
65-
uses: redhat-actions/podman-login@v1
66-
with:
67-
username: ${{ secrets.QUAY_ID }}
68-
password: ${{ secrets.QUAY_TOKEN }}
69-
registry: quay.io
70-
- name: Buid image
71-
env:
72-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_SERVER}:${{ inputs.target_tag }}
60+
IMAGE_REPO: ${{ env.IMAGE_REPO_SERVER }}
7361
DOCKERFILE: backend/Dockerfile
74-
run: |
75-
RESULT=$(podman image exists ${{ env.IMAGE }})
76-
if [ $RESULT -eq 1 ]; then echo "Image already exists" && exit 1; fi
77-
podman build . -f ${{ env.DOCKERFILE }} -t ${{ env.IMAGE }} && podman push ${{ env.IMAGE }}
62+
GH_REPO: ${{ inputs.dsp_org_repo }}
7863

7964
ui-build:
8065
runs-on: ubuntu-latest
8166
permissions:
8267
contents: read
8368
steps:
8469
- uses: actions/checkout@v3
70+
- uses: ./.github/actions/build
8571
with:
86-
repository: ${{ inputs.dsp_org_repo }}
87-
ref: ${{ inputs.src_branch }}
88-
- name: Login to Quay.io
89-
uses: redhat-actions/podman-login@v1
90-
with:
91-
username: ${{ secrets.QUAY_ID }}
92-
password: ${{ secrets.QUAY_TOKEN }}
93-
registry: quay.io
94-
- name: Build image
95-
env:
96-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_UI}:${{ inputs.target_tag }}
72+
IMAGE_REPO: ${{ env.IMAGE_REPO_UI }}
9773
DOCKERFILE: frontend/Dockerfile
98-
run: |
99-
podman build . -f frontend/Dockerfile -t ${{ env.UI }} && podman push ${{ env.UI }}
74+
GH_REPO: ${{ inputs.dsp_org_repo }}
10075

10176
cache-build:
10277
runs-on: ubuntu-latest
10378
permissions:
10479
contents: read
10580
steps:
10681
- uses: actions/checkout@v3
82+
- uses: ./.github/actions/build
10783
with:
108-
repository: ${{ inputs.dsp_org_repo }}
109-
ref: ${{ inputs.src_branch }}
110-
- name: Login to Quay.io
111-
uses: redhat-actions/podman-login@v1
112-
with:
113-
username: ${{ secrets.QUAY_ID }}
114-
password: ${{ secrets.QUAY_TOKEN }}
115-
registry: quay.io
116-
- name: Build image
117-
env:
118-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_CACHE}:${{ inputs.target_tag }}
119-
run: |
120-
podman build . -f backend/Dockerfile.cacheserver -t ${{ env.CACHE }} && podman push ${{ env.CACHE }}
84+
IMAGE_REPO: ${{ env.IMAGE_REPO_CACHE }}
85+
DOCKERFILE: backend/Dockerfile.cacheserver
86+
GH_REPO: ${{ inputs.dsp_org_repo }}
12187

12288
PA-build:
12389
runs-on: ubuntu-latest
12490
permissions:
12591
contents: read
12692
steps:
12793
- uses: actions/checkout@v3
94+
- uses: ./.github/actions/build
12895
with:
129-
repository: ${{ inputs.dsp_org_repo }}
130-
ref: ${{ inputs.src_branch }}
131-
- name: Login to Quay.io
132-
uses: redhat-actions/podman-login@v1
133-
with:
134-
username: ${{ secrets.QUAY_ID }}
135-
password: ${{ secrets.QUAY_TOKEN }}
136-
registry: quay.io
137-
- name: Build image
138-
env:
139-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_PA}:${{ inputs.target_tag }}
140-
run: |
141-
podman build . -f backend/Dockerfile.persistenceagent -t ${{ env.PA }} && podman push ${{ env.PA }}
96+
IMAGE_REPO: ${{ env.IMAGE_REPO_PA }}
97+
DOCKERFILE: backend/Dockerfile.persistenceagent
98+
GH_REPO: ${{ inputs.dsp_org_repo }}
14299

143100
SWF-build:
144101
runs-on: ubuntu-latest
145102
permissions:
146103
contents: read
147104
steps:
148105
- uses: actions/checkout@v3
106+
- uses: ./.github/actions/build
149107
with:
150-
repository: ${{ inputs.dsp_org_repo }}
151-
ref: ${{ inputs.src_branch }}
152-
- name: Login to Quay.io
153-
uses: redhat-actions/podman-login@v1
154-
with:
155-
username: ${{ secrets.QUAY_ID }}
156-
password: ${{ secrets.QUAY_TOKEN }}
157-
registry: quay.io
158-
- name: Build image
159-
env:
160-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_SWF}:${{ inputs.target_tag }}
161-
run: |
162-
podman build . -f backend/Dockerfile.scheduledworkflow -t ${{ env.SWF }} && podman push ${{ env.SWF }}
108+
IMAGE_REPO: ${{ env.IMAGE_REPO_SWF }}
109+
DOCKERFILE: backend/Dockerfile.scheduledworkflow
110+
GH_REPO: ${{ inputs.dsp_org_repo }}
163111

164112
VC-build:
165113
runs-on: ubuntu-latest
166114
permissions:
167115
contents: read
168116
steps:
169117
- uses: actions/checkout@v3
118+
- uses: ./.github/actions/build
170119
with:
171-
repository: ${{ inputs.dsp_org_repo }}
172-
ref: ${{ inputs.src_branch }}
173-
- name: Login to Quay.io
174-
uses: redhat-actions/podman-login@v1
175-
with:
176-
username: ${{ secrets.QUAY_ID }}
177-
password: ${{ secrets.QUAY_TOKEN }}
178-
registry: quay.io
179-
- name: Build image
180-
env:
181-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_VC}:${{ inputs.target_tag }}
182-
run: |
183-
podman build . -f backend/Dockerfile.viewercontroller -t ${{ env.VC }} && podman push ${{ env.VC }}
120+
IMAGE_REPO: ${{ env.IMAGE_REPO_VC }}
121+
DOCKERFILE: backend/Dockerfile.viewercontroller
122+
GH_REPO: ${{ inputs.dsp_org_repo }}
184123

185124
ARTIFACT-build:
186125
runs-on: ubuntu-latest
187126
permissions:
188127
contents: read
189128
steps:
190129
- uses: actions/checkout@v3
130+
- uses: ./.github/actions/build
191131
with:
192-
repository: ${{ inputs.dsp_org_repo }}
193-
ref: ${{ inputs.src_branch }}
194-
- name: Login to Quay.io
195-
uses: redhat-actions/podman-login@v1
196-
with:
197-
username: ${{ secrets.QUAY_ID }}
198-
password: ${{ secrets.QUAY_TOKEN }}
199-
registry: quay.io
200-
- name: Build image
201-
env:
202-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_ARTIFACT}:${{ inputs.target_tag }}
203-
run: |
204-
podman build . -f backend/artifact_manager/Dockerfile -t ${{ env.ARTIFACT }} && podman push ${{ env.ARTIFACT }}
132+
IMAGE_REPO: ${{ env.IMAGE_REPO_ARTIFACT }}
133+
DOCKERFILE: backend/artifact_manager/Dockerfile
134+
GH_REPO: ${{ inputs.dsp_org_repo }}
205135

206136
MLMD_WRITER-build:
207137
runs-on: ubuntu-latest
208138
permissions:
209139
contents: read
210140
steps:
211141
- uses: actions/checkout@v3
142+
- uses: ./.github/actions/build
212143
with:
213-
repository: ${{ inputs.dsp_org_repo }}
214-
ref: ${{ inputs.src_branch }}
215-
- name: Login to Quay.io
216-
uses: redhat-actions/podman-login@v1
217-
with:
218-
username: ${{ secrets.QUAY_ID }}
219-
password: ${{ secrets.QUAY_TOKEN }}
220-
registry: quay.io
221-
- name: Build image
222-
env:
223-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_MLMD_WRITER}:${{ inputs.target_tag }}
224-
run: |
225-
podman build . -f backend/metadata_writer/Dockerfile -t ${{ env.MLMD_WRITER }} && podman push ${{ env.MLMD_WRITER }}
144+
IMAGE_REPO: ${{ env.IMAGE_REPO_MLMD_WRITER }}
145+
DOCKERFILE: backend/metadata_writer/Dockerfile
146+
GH_REPO: ${{ inputs.dsp_org_repo }}
226147

227148
MLMD_ENVOY-build:
228149
runs-on: ubuntu-latest
229150
permissions:
230151
contents: read
231152
steps:
232153
- uses: actions/checkout@v3
154+
- uses: ./.github/actions/build
233155
with:
234-
repository: ${{ inputs.dsp_org_repo }}
235-
ref: ${{ inputs.src_branch }}
236-
- name: Login to Quay.io
237-
uses: redhat-actions/podman-login@v1
238-
with:
239-
username: ${{ secrets.QUAY_ID }}
240-
password: ${{ secrets.QUAY_TOKEN }}
241-
registry: quay.io
242-
- name: Build image
243-
env:
244-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_MLMD_ENVOY}:${{ inputs.target_tag }}
245-
run: |
246-
podman build . -f third-party/metadata_envoy/Dockerfile -t ${{ env.MLMD_ENVOY }} && podman push ${{ env.MLMD_ENVOY }}
156+
IMAGE_REPO: ${{ env.IMAGE_REPO_MLMD_ENVOY }}
157+
DOCKERFILE: third-party/metadata_envoy/Dockerfile
158+
GH_REPO: ${{ inputs.dsp_org_repo }}
247159

248160
MLMD_GRPC-build:
249161
runs-on: ubuntu-latest
250162
permissions:
251163
contents: read
252164
steps:
253165
- uses: actions/checkout@v3
166+
- uses: ./.github/actions/build
254167
with:
255-
repository: ${{ inputs.dsp_org_repo }}
256-
ref: ${{ inputs.src_branch }}
257-
- name: Login to Quay.io
258-
uses: redhat-actions/podman-login@v1
259-
with:
260-
username: ${{ secrets.QUAY_ID }}
261-
password: ${{ secrets.QUAY_TOKEN }}
262-
registry: quay.io
263-
- name: Build image
264-
env:
265-
IMAGE: quay.io/${{ inputs.quay_org }}/${IMAGE_MLMD_GRPC}:${{ inputs.target_tag }}
266-
run: |
267-
podman build . -f third-party/ml-metadata/Dockerfile -t ${{ env.MLMD_GRPC }} && podman push ${{ env.MLMD_GRPC }}
168+
IMAGE_REPO: ${{ env.IMAGE_REPO_MLMD_GRPC }}
169+
DOCKERFILE: third-party/ml-metadata/Dockerfile
170+
GH_REPO: ${{ inputs.dsp_org_repo }}

0 commit comments

Comments
 (0)