forked from kubeflow/model-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup image build and push to quay (kubeflow#72)
* Setup image build and push to quay * Skip docke login if we skip the push * Extract build and deploy steps in a dedicated script
- Loading branch information
Showing
5 changed files
with
181 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Main container image build and tag | ||
|
||
on: | ||
push: | ||
branches: [ 'main' ] | ||
|
||
env: | ||
QUAY_IMG_REPO: model-registry | ||
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} | ||
QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} | ||
PUSH_IMAGE: true | ||
|
||
jobs: | ||
build-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Generate Tag | ||
shell: bash | ||
id: tags | ||
run: | | ||
commit_sha=${{ github.event.after }} | ||
tag=main-${commit_sha:0:7} | ||
echo "tag=${tag}" >> $GITHUB_OUTPUT | ||
- name: Build and Push Image | ||
shell: bash | ||
env: | ||
VERSION: ${{ steps.tags.outputs.tag }} | ||
run: ./scripts/build_deploy.sh | ||
- name: Tag Latest | ||
shell: bash | ||
env: | ||
IMG: quay.io/${{ env.QUAY_ORG }}/${{ env.QUAY_IMG_REPO }} | ||
BUILD_IMAGE: false | ||
NEWEST_TAG: ${{ steps.tags.outputs.tag }} | ||
VERSION: latest | ||
run: | | ||
docker tag ${{ env.IMG }}:${{ env.NEWEST_TAG }} ${{ env.IMG }}:${{ env.VERSION }} | ||
# BUILD_IMAGE=false skip the build | ||
./scripts/build_deploy.sh | ||
- name: Tag Main | ||
shell: bash | ||
env: | ||
IMG: quay.io/${{ env.QUAY_ORG }}/${{ env.QUAY_IMG_REPO }} | ||
BUILD_IMAGE: false | ||
NEWEST_TAG: ${{ steps.tags.outputs.tag }} | ||
VERSION: main | ||
run: | | ||
docker tag ${{ env.IMG }}:${{ env.NEWEST_TAG }} ${{ env.IMG }}:${{ env.VERSION }} | ||
# BUILD_IMAGE=false skip the build | ||
./scripts/build_deploy.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Test container image build | ||
|
||
on: | ||
pull_request_target: | ||
branches: [ '*' ] | ||
|
||
env: | ||
QUAY_IMG_REPO: model-registry | ||
PUSH_IMAGE: false | ||
|
||
jobs: | ||
build-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Generate Tag | ||
shell: bash | ||
id: tags | ||
run: | | ||
commit_sha=${{ github.event.after }} | ||
tag=main-${commit_sha:0:7} | ||
echo "tag=${tag}" >> $GITHUB_OUTPUT | ||
- name: Build Image | ||
shell: bash | ||
env: | ||
VERSION: ${{ steps.tags.outputs.tag }} | ||
run: ./scripts/build_deploy.sh |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# quay.io credentials | ||
QUAY_REGISTRY=quay.io | ||
QUAY_ORG="${QUAY_ORG:-opendatahub}" | ||
QUAY_IMG_REPO="${QUAY_IMG_REPO:-model-registry}" | ||
QUAY_USERNAME="${QUAY_USERNAME}" | ||
QUAY_PASSWORD="${QUAY_PASSWORD}" | ||
|
||
# image version | ||
HASH="$(git rev-parse --short=7 HEAD)" | ||
VERSION="${VERSION:-$HASH}" | ||
|
||
# if set to 0 skip image build | ||
# otherwise build it | ||
BUILD_IMAGE="${BUILD_IMAGE:-true}" | ||
|
||
# if set to 0 skip push to registry | ||
# otherwise push it | ||
PUSH_IMAGE="${PUSH_IMAGE:-false}" | ||
|
||
# skip if image already existing on registry | ||
SKIP_IF_EXISTING="${SKIP_IF_EXISTING:-false}" | ||
|
||
# assure docker exists | ||
docker -v foo >/dev/null 2>&1 || { echo >&2 "::error:: Docker is required. Aborting."; exit 1; } | ||
|
||
# skip if image already existing | ||
if [[ "${SKIP_IF_EXISTING,,}" == "true" ]]; then | ||
TAGS=$(curl --request GET "https://$QUAY_REGISTRY/api/v1/repository/${QUAY_ORG}/${QUAY_IMG_REPO}/tag/?specificTag=${VERSION}") | ||
LATEST_TAG_HAS_END_TS=$(echo $TAGS | jq .tags - | jq 'sort_by(.start_ts) | reverse' | jq '.[0].end_ts') | ||
NOT_EMPTY=$(echo ${TAGS} | jq .tags - | jq any) | ||
|
||
# Image only exists if there is a tag that does not have "end_ts" (i.e. it is still present). | ||
if [[ "$NOT_EMPTY" == "true" && $LATEST_TAG_HAS_END_TS == "null" ]]; then | ||
echo "::error:: The image ${QUAY_ORG}/${QUAY_IMG_REPO}:${VERSION} already exists" | ||
exit 1 | ||
else | ||
echo "Image does not exist...proceeding with build & push." | ||
fi | ||
fi | ||
|
||
# build docker image, login is not required at this step | ||
if [[ "${BUILD_IMAGE,,}" == "true" ]]; then | ||
echo "Building container image.." | ||
make \ | ||
IMG_REGISTRY="${QUAY_REGISTRY}" \ | ||
IMG_ORG="${QUAY_ORG}" \ | ||
IMG_REPO="${QUAY_IMG_REPO}" \ | ||
IMG_VERSION="${VERSION}" \ | ||
image/build | ||
else | ||
echo "Skip container image build." | ||
fi | ||
|
||
# push container image to registry, requires login | ||
if [[ "${PUSH_IMAGE,,}" == "true" ]]; then | ||
echo "Pushing container image.." | ||
make \ | ||
IMG_REGISTRY="${QUAY_REGISTRY}" \ | ||
IMG_ORG="${QUAY_ORG}" \ | ||
IMG_REPO="${QUAY_IMG_REPO}" \ | ||
IMG_VERSION="${VERSION}" \ | ||
DOCKER_USER="${QUAY_USERNAME} "\ | ||
DOCKER_PWD="${QUAY_PASSWORD}" \ | ||
docker/login \ | ||
image/push | ||
else | ||
echo "Skip container image push." | ||
fi |