From bcfe41b9ff5634c582f52659d2bced34dcfb5ea4 Mon Sep 17 00:00:00 2001 From: Griffin-Sullivan Date: Tue, 1 Oct 2024 14:05:19 -0400 Subject: [PATCH] Add GitHub Action for building and pushing UI and BFF images Signed-off-by: Griffin-Sullivan --- .../workflows/build-and-push-ui-images.yml | 67 +++++++++++++++++++ Makefile | 17 ++++- clients/ui/bff/README.md | 2 +- clients/ui/manifests/base/kustomization.yaml | 4 +- scripts/build_deploy.sh | 2 +- 5 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/build-and-push-ui-images.yml diff --git a/.github/workflows/build-and-push-ui-images.yml b/.github/workflows/build-and-push-ui-images.yml new file mode 100644 index 00000000..7954f1f5 --- /dev/null +++ b/.github/workflows/build-and-push-ui-images.yml @@ -0,0 +1,67 @@ +name: Build and Push UI and BFF Images +on: + # TODO: Replace pull_request with push before merging!!! + pull_request: + branches: + - 'main' + tags: + - 'v*' + paths: + - 'clients/ui/**' +env: + IMG_ORG: gsulliva + IMG_UI_REPO: model-registry-ui + IMG_BFF_REPO: model-registry-bff + DOCKER_USER: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKER_PWD: ${{ secrets.DOCKERHUB_TOKEN }} + PUSH_IMAGE: true +jobs: + build-image: + runs-on: ubuntu-latest + environment: griffin-testing # TODO: REMOVE LINE BEFORE MERGING + steps: + # Assign context variable for various action contexts (main, CI) + - name: Assigning main context + if: github.head_ref == '' && github.ref == 'refs/heads/main' + run: echo "BUILD_CONTEXT=main" >> $GITHUB_ENV + # checkout branch + - uses: actions/checkout@v4 + # set image version + - name: Set main-branch environment + if: env.BUILD_CONTEXT == 'main' + run: | + commit_sha=${{ github.event.after }} + tag=main-${commit_sha:0:7} + echo "VERSION=${tag}" >> $GITHUB_ENV + - name: Build and Push UI Image + shell: bash + env: + IMG_REPO: ${{ env.IMG_UI_REPO }} + run: ./scripts/build_deploy.sh + - name: Build and Push BFF Image + shell: bash + env: + IMG_REPO: ${{ env.IMG_BFF_REPO }} + run: ./scripts/build_deploy.sh + - name: Tag Latest UI Image + if: env.BUILD_CONTEXT == 'main' + shell: bash + env: + IMG_REPO: ${{ env.IMG_UI_REPO }} + IMG: ${{ env.IMG_ORG }}/${{ env.IMG_UI_REPO }} + BUILD_IMAGE: false # image is already built in "Build and Push UI Image" step + run: | + docker tag ${{ env.IMG }}:$VERSION ${{ env.IMG }}:latest + # BUILD_IMAGE=false skip the build, just push the tag made above + VERSION=latest ./scripts/build_deploy.sh + - name: Tag Latest BFF Image + if: env.BUILD_CONTEXT == 'main' + shell: bash + env: + IMG_REPO: ${{ env.IMG_BFF_REPO }} + IMG: ${{ env.IMG_ORG }}/${{ env.IMG_BFF_REPO }} + BUILD_IMAGE: false # image is already built in "Build and Push BFF Image" step + run: | + docker tag ${{ env.IMG }}:$VERSION ${{ env.IMG }}:latest + # BUILD_IMAGE=false skip the build, just push the tag made above + VERSION=latest ./scripts/build_deploy.sh \ No newline at end of file diff --git a/Makefile b/Makefile index 3081c1d0..72204844 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH))) PROJECT_BIN := $(PROJECT_PATH)/bin GO ?= "$(shell which go)" +BFF_PATH := $(PROJECT_PATH)/clients/ui/bff +UI_PATH := $(PROJECT_PATH)/clients/ui/frontend # add tools bin directory PATH := $(PROJECT_BIN):$(PATH) @@ -21,6 +23,8 @@ IMG_ORG ?= kubeflow IMG_VERSION ?= main # container image repository IMG_REPO ?= model-registry +# container image build path +BUILD_PATH ?= . # container image ifdef IMG_REGISTRY IMG := ${IMG_REGISTRY}/${IMG_ORG}/${IMG_REPO} @@ -28,6 +32,17 @@ else IMG := ${IMG_ORG}/${IMG_REPO} endif +# Change Dockerfile path depending on IMG_REPO +ifeq ($(IMG_REPO),model-registry-ui) + DOCKERFILE := $(UI_PATH)/Dockerfile + BUILD_PATH := $(UI_PATH) +endif + +ifeq ($(IMG_REPO),model-registry-bff) + DOCKERFILE := $(BFF_PATH)/Dockerfile + BUILD_PATH := $(BFF_PATH) +endif + model-registry: build # clean the ml-metadata protos and trigger a fresh new build which downloads @@ -216,7 +231,7 @@ endif # build docker image .PHONY: image/build image/build: - ${DOCKER} build . -f ${DOCKERFILE} -t ${IMG}:$(IMG_VERSION) + ${DOCKER} build ${BUILD_PATH} -f ${DOCKERFILE} -t ${IMG}:$(IMG_VERSION) # build docker image using buildx # PLATFORMS defines the target platforms for the model registry image be built to provide support to multiple diff --git a/clients/ui/bff/README.md b/clients/ui/bff/README.md index 37028090..62720503 100644 --- a/clients/ui/bff/README.md +++ b/clients/ui/bff/README.md @@ -19,7 +19,7 @@ docker compose -f docker-compose[-local].yaml up The main difference between the two docker compose files is that `-local` one builds the model registry from source, the other one, instead, download the `latest` pushed [quay.io](https://quay.io/repository/opendatahub/model-registry?tab=tags) image. -When shutting down the docker compose, you might want to clean-up the SQLite db file generated by ML Metadata, for example `./test/config/ml-metadata/metadata.sqlite.db` +When shutting down the docker compose, you might want to clean-up the SQLite db file generated by ML Metadata, for example `./test/config/ml-metadata/metadata.sqlite.db`. # Development diff --git a/clients/ui/manifests/base/kustomization.yaml b/clients/ui/manifests/base/kustomization.yaml index 7a3e3676..4c9472a1 100644 --- a/clients/ui/manifests/base/kustomization.yaml +++ b/clients/ui/manifests/base/kustomization.yaml @@ -10,6 +10,6 @@ resources: images: - name: model-registry-ui-image - newName: quay.io/gsulliva/mr-ui:latest + newName: kubeflow/model-registry-ui:latest - name: model-registry-bff-image - newName: quay.io/gsulliva/mr-bff:latest + newName: kubeflow/model-registry-bff:latest diff --git a/scripts/build_deploy.sh b/scripts/build_deploy.sh index 91fc4914..933c0005 100755 --- a/scripts/build_deploy.sh +++ b/scripts/build_deploy.sh @@ -3,7 +3,7 @@ set -e # see Makefile for the IMG_ variables semantic -IMG_REGISTRY="" +IMG_REGISTRY="quay.io" # TODO: CHANGE TO EMPTY STRING BEFORE MERGE!!! IMG_ORG="${IMG_ORG:-kubeflow}" IMG_REPO="${IMG_REPO:-model-registry}" DOCKER_USER="${DOCKER_USER}"