Skip to content

Commit 0a379a6

Browse files
authored
Merge pull request opendatahub-io#238 from HumairAK/tag_build_image_exists
Tag build image exists
2 parents bb3d3f3 + 09f3d02 commit 0a379a6

File tree

2 files changed

+125
-175
lines changed

2 files changed

+125
-175
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: 62 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -20,264 +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
59-
env:
60-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
6156
steps:
6257
- uses: actions/checkout@v3
58+
- uses: ./.github/actions/build
6359
with:
64-
repository: ${{ inputs.dsp_org_repo }}
65-
ref: ${{ inputs.src_branch }}
66-
- name: Login to Quay.io
67-
uses: redhat-actions/podman-login@v1
68-
with:
69-
username: ${{ secrets.QUAY_ID }}
70-
password: ${{ secrets.QUAY_TOKEN }}
71-
registry: quay.io
72-
- name: Buid APIServer
73-
env:
74-
API_SERVER: quay.io/${{ inputs.quay_org }}/${IMAGE_SERVER}:${{ inputs.target_tag }}
75-
run: |
76-
podman build . -f backend/Dockerfile -t ${{ env.API_SERVER }} && podman push ${{ env.API_SERVER }}
60+
IMAGE_REPO: ${{ env.IMAGE_REPO_SERVER }}
61+
DOCKERFILE: backend/Dockerfile
62+
GH_REPO: ${{ inputs.dsp_org_repo }}
7763

7864
ui-build:
7965
runs-on: ubuntu-latest
8066
permissions:
8167
contents: read
82-
env:
83-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
8468
steps:
8569
- uses: actions/checkout@v3
70+
- uses: ./.github/actions/build
8671
with:
87-
repository: ${{ inputs.dsp_org_repo }}
88-
ref: ${{ inputs.src_branch }}
89-
- name: Login to Quay.io
90-
uses: redhat-actions/podman-login@v1
91-
with:
92-
username: ${{ secrets.QUAY_ID }}
93-
password: ${{ secrets.QUAY_TOKEN }}
94-
registry: quay.io
95-
- name: Build image
96-
env:
97-
UI: quay.io/${{ inputs.quay_org }}/${IMAGE_UI}:${{ inputs.target_tag }}
98-
run: |
99-
podman build . -f frontend/Dockerfile -t ${{ env.UI }} && podman push ${{ env.UI }}
72+
IMAGE_REPO: ${{ env.IMAGE_REPO_UI }}
73+
DOCKERFILE: frontend/Dockerfile
74+
GH_REPO: ${{ inputs.dsp_org_repo }}
10075

10176
cache-build:
10277
runs-on: ubuntu-latest
10378
permissions:
10479
contents: read
105-
env:
106-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
10780
steps:
10881
- uses: actions/checkout@v3
82+
- uses: ./.github/actions/build
10983
with:
110-
repository: ${{ inputs.dsp_org_repo }}
111-
ref: ${{ inputs.src_branch }}
112-
- name: Login to Quay.io
113-
uses: redhat-actions/podman-login@v1
114-
with:
115-
username: ${{ secrets.QUAY_ID }}
116-
password: ${{ secrets.QUAY_TOKEN }}
117-
registry: quay.io
118-
- name: Build image
119-
env:
120-
CACHE: quay.io/${{ inputs.quay_org }}/${IMAGE_CACHE}:${{ inputs.target_tag }}
121-
run: |
122-
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 }}
12387

12488
PA-build:
12589
runs-on: ubuntu-latest
12690
permissions:
12791
contents: read
128-
env:
129-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
13092
steps:
13193
- uses: actions/checkout@v3
94+
- uses: ./.github/actions/build
13295
with:
133-
repository: ${{ inputs.dsp_org_repo }}
134-
ref: ${{ inputs.src_branch }}
135-
- name: Login to Quay.io
136-
uses: redhat-actions/podman-login@v1
137-
with:
138-
username: ${{ secrets.QUAY_ID }}
139-
password: ${{ secrets.QUAY_TOKEN }}
140-
registry: quay.io
141-
- name: Build image
142-
env:
143-
PA: quay.io/${{ inputs.quay_org }}/${IMAGE_PA}:${{ inputs.target_tag }}
144-
run: |
145-
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 }}
14699

147100
SWF-build:
148101
runs-on: ubuntu-latest
149102
permissions:
150103
contents: read
151-
env:
152-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
153104
steps:
154105
- uses: actions/checkout@v3
106+
- uses: ./.github/actions/build
155107
with:
156-
repository: ${{ inputs.dsp_org_repo }}
157-
ref: ${{ inputs.src_branch }}
158-
- name: Login to Quay.io
159-
uses: redhat-actions/podman-login@v1
160-
with:
161-
username: ${{ secrets.QUAY_ID }}
162-
password: ${{ secrets.QUAY_TOKEN }}
163-
registry: quay.io
164-
- name: Build image
165-
env:
166-
SWF: quay.io/${{ inputs.quay_org }}/${IMAGE_SWF}:${{ inputs.target_tag }}
167-
run: |
168-
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 }}
169111

170112
VC-build:
171113
runs-on: ubuntu-latest
172114
permissions:
173115
contents: read
174-
env:
175-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
176116
steps:
177117
- uses: actions/checkout@v3
118+
- uses: ./.github/actions/build
178119
with:
179-
repository: ${{ inputs.dsp_org_repo }}
180-
ref: ${{ inputs.src_branch }}
181-
- name: Login to Quay.io
182-
uses: redhat-actions/podman-login@v1
183-
with:
184-
username: ${{ secrets.QUAY_ID }}
185-
password: ${{ secrets.QUAY_TOKEN }}
186-
registry: quay.io
187-
- name: Build image
188-
env:
189-
VC: quay.io/${{ inputs.quay_org }}/${IMAGE_VC}:${{ inputs.target_tag }}
190-
run: |
191-
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 }}
192123

193124
ARTIFACT-build:
194125
runs-on: ubuntu-latest
195126
permissions:
196127
contents: read
197-
env:
198-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
199128
steps:
200129
- uses: actions/checkout@v3
130+
- uses: ./.github/actions/build
201131
with:
202-
repository: ${{ inputs.dsp_org_repo }}
203-
ref: ${{ inputs.src_branch }}
204-
- name: Login to Quay.io
205-
uses: redhat-actions/podman-login@v1
206-
with:
207-
username: ${{ secrets.QUAY_ID }}
208-
password: ${{ secrets.QUAY_TOKEN }}
209-
registry: quay.io
210-
- name: Build image
211-
env:
212-
ARTIFACT: quay.io/${{ inputs.quay_org }}/${IMAGE_ARTIFACT}:${{ inputs.target_tag }}
213-
run: |
214-
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 }}
215135

216136
MLMD_WRITER-build:
217137
runs-on: ubuntu-latest
218138
permissions:
219139
contents: read
220-
env:
221-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
222140
steps:
223141
- uses: actions/checkout@v3
142+
- uses: ./.github/actions/build
224143
with:
225-
repository: ${{ inputs.dsp_org_repo }}
226-
ref: ${{ inputs.src_branch }}
227-
- name: Login to Quay.io
228-
uses: redhat-actions/podman-login@v1
229-
with:
230-
username: ${{ secrets.QUAY_ID }}
231-
password: ${{ secrets.QUAY_TOKEN }}
232-
registry: quay.io
233-
- name: Build image
234-
env:
235-
MLMD_WRITER: quay.io/${{ inputs.quay_org }}/${IMAGE_MLMD_WRITER}:${{ inputs.target_tag }}
236-
run: |
237-
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 }}
238147

239148
MLMD_ENVOY-build:
240149
runs-on: ubuntu-latest
241150
permissions:
242151
contents: read
243-
env:
244-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
245152
steps:
246153
- uses: actions/checkout@v3
154+
- uses: ./.github/actions/build
247155
with:
248-
repository: ${{ inputs.dsp_org_repo }}
249-
ref: ${{ inputs.src_branch }}
250-
- name: Login to Quay.io
251-
uses: redhat-actions/podman-login@v1
252-
with:
253-
username: ${{ secrets.QUAY_ID }}
254-
password: ${{ secrets.QUAY_TOKEN }}
255-
registry: quay.io
256-
- name: Build image
257-
env:
258-
MLMD_ENVOY: quay.io/${{ inputs.quay_org }}/${IMAGE_MLMD_ENVOY}:${{ inputs.target_tag }}
259-
run: |
260-
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 }}
261159

262160
MLMD_GRPC-build:
263161
runs-on: ubuntu-latest
264162
permissions:
265163
contents: read
266-
env:
267-
IMAGE_ORG_BASE: quay.io/${{ inputs.quay_org }}
268164
steps:
269165
- uses: actions/checkout@v3
166+
- uses: ./.github/actions/build
270167
with:
271-
repository: ${{ inputs.dsp_org_repo }}
272-
ref: ${{ inputs.src_branch }}
273-
- name: Login to Quay.io
274-
uses: redhat-actions/podman-login@v1
275-
with:
276-
username: ${{ secrets.QUAY_ID }}
277-
password: ${{ secrets.QUAY_TOKEN }}
278-
registry: quay.io
279-
- name: Build image
280-
env:
281-
MLMD_GRPC: quay.io/${{ inputs.quay_org }}/${IMAGE_MLMD_GRPC}:${{ inputs.target_tag }}
282-
run: |
283-
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)