Skip to content

Commit

Permalink
Record and retrieve information about registry to which the image got…
Browse files Browse the repository at this point in the history
… pushed.
  • Loading branch information
adelton committed Oct 13, 2023
1 parent 805d169 commit de4ed5b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ spec:
PR_BRANCH=pipeline_$(context.pipelineRun.uid)
git checkout -b $PR_BRANCH
sed -i -e "s%newName: .*%newName: $(tasks.retrieve-image-info.results.target-registry-url)%" $(params.imageReferenceFilePath)
sed -i -e "s/digest: .*/digest: $(tasks.retrieve-image-info.results.image-sha)/" $(params.imageReferenceFilePath)
if [ -z "$(git status --porcelain)" ]; then
Expand Down Expand Up @@ -124,6 +125,7 @@ spec:
| PipelineRun Name | $(context.pipelineRun.name) |
| PipelinRun UID | `$(context.pipelineRun.uid)` |
| File Path | `$(params.imageReferenceFilePath)` |
| Image registry | `$(tasks.retrieve-image-info.results.target-registry-url)` |
| New Digest | `$(tasks.retrieve-image-info.results.image-sha)` |
- name: TITLE
value: "Auto: update image ref"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Task
metadata:
name: retrieve-image-info
spec:
description: Retrieve SHA of the built image from the previous PipelineRun
description: Retrieve location and SHA of the built image from the previous PipelineRun
params:
- name: namespace
type: string
Expand All @@ -13,8 +13,10 @@ spec:
- name: get-image-sha
image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
script: |
oc get -n $(params.namespace) pipelinerun --selector tekton.dev/pipeline=test-mlflow-image --sort-by=.status.completionTime -o jsonpath='{range .items[?(@.spec.params[0].name == "model-name")]}{.spec.params[?(@.name == "model-name")].value} {.status.results[?(@.name == "image-sha")].value}{"\n"}{end}' | awk -v model=$(params.model-name) '$1 == model && NF == 2 { print $2 }' | tail -1 | tee /dev/stderr | while read sha ; do echo -n "$sha" > $(results.image-sha.path) ; done ;
test -s $(results.image-sha.path)
oc get -n $(params.namespace) pipelinerun --selector tekton.dev/pipeline=test-mlflow-image --sort-by=.status.completionTime -o jsonpath='{range .items[?(@.spec.params[0].name == "model-name")]}{.spec.params[?(@.name == "model-name")].value} {.status.results[?(@.name == "image-sha")].value} {.status.results[?(@.name == "target-registry-url")].value}{"\n"}{end}' | awk -v model=$(params.model-name) '$1 == model && NF == 3 { print $2, $3 }' | tail -1 | tee /dev/stderr | while read sha registry ; do echo -n "$sha" > $(results.image-sha.path) ; echo -n "$registry" > $(results.target-registry-url.path) ; done ;
test -s $(results.image-sha.path) && test -s $(results.target-registry-url.path)
results:
- name: target-registry-url
description: The target-registry-url where the image will be stored
- name: image-sha
description: The image checksum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
type: string
default: delete
results:
- name: target-registry-url
value: $(tasks.record-image.results.target-registry-url)
- name: image-sha
value: $(tasks.record-image.results.image-sha)
tasks:
Expand Down Expand Up @@ -138,14 +140,16 @@ spec:
value: $(params.model-version)
- name: namespace
value: $(params.target-namespace)
- name: target-registry-url
value: quay.io/$(params.target-imagerepo)/$(params.model-name)
runAfter:
- test-mlflow-rest-svc
- name: skopeo-copy
params:
- name: srcImageURL
value: docker://image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/$(params.model-name)@$(tasks.record-image.results.image-sha)
- name: destImageURL
value: docker://quay.io/$(params.target-imagerepo)/$(params.model-name):$(params.model-version)-$(context.pipelineRun.uid)
value: docker://$(tasks.record-image.results.target-registry-url):$(params.model-version)-$(context.pipelineRun.uid)
- name: srcTLSverify
value: "true"
- name: destTLSverify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ kind: Task
metadata:
name: record-image
spec:
description: Record SHA of the built image
description: Record location and SHA of the built image
params:
- name: namespace
type: string
- name: model-name
type: string
- name: model-version
type: string
- name: target-registry-url
type: string
steps:
- name: get-image-sha
image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
script: |
echo -n "$(params.target-registry-url)" | tee $(results.target-registry-url.path) ;
echo ;
oc get -n $(params.namespace) -o jsonpath='{.status.tags[?(@.tag == "$(params.model-version)")].items[0].image}' imagestream/$(params.model-name) | tee $(results.image-sha.path)
results:
- name: target-registry-url
description: The target-registry-url where the image will be stored
- name: image-sha
description: The image checksum

0 comments on commit de4ed5b

Please sign in to comment.