diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml index 45c5e34c..f30bdbe8 100644 --- a/.github/workflows/build-and-push-image.yml +++ b/.github/workflows/build-and-push-image.yml @@ -18,7 +18,6 @@ env: IMG_REPO: model-registry DOCKER_USER: ${{ secrets.DOCKERHUB_USERNAME }} DOCKER_PWD: ${{ secrets.DOCKERHUB_TOKEN }} - PUSH_IMAGE: true jobs: build-image: runs-on: ubuntu-latest @@ -33,36 +32,36 @@ jobs: # 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: Set tag environment if: env.BUILD_CONTEXT == 'tag' run: | echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV - - name: Build and Push Image - shell: bash - run: ./scripts/build_deploy.sh - - name: Tag Latest - if: env.BUILD_CONTEXT == 'main' - shell: bash - env: - IMG: ${{ env.IMG_ORG }}/${{ env.IMG_REPO }} - BUILD_IMAGE: false # image is already built in "Build and Push Image" step + echo "IMAGE_NAME=${{env.IMG_ORG}}/${{env.IMG_REPO}}" >> $GITHUB_ENV + - name: Set main-branch environment + if: env.BUILD_CONTEXT == 'main' 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 Main + echo "TAG=latest" >> $GITHUB_ENV + echo "IMAGE_NAME=${{env.IMG_ORG}}/${{env.IMG_REPO}}" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and Push Image + if: env.BUILD_CONTEXT == 'tag' + uses: docker/build-push-action@v3 + with: + tags: ${{ env.IMAGE_NAME }}:${{ env.VERSION }} + platforms: linux/amd64,linux/s390x,linux/ppc64le + push: true + - name: Build and Push Latest tag if: env.BUILD_CONTEXT == 'main' - shell: bash - env: - IMG: ${{ env.IMG_ORG }}/${{ env.IMG_REPO }} - BUILD_IMAGE: false # image is already built in "Build and Push Image" step - run: | - docker tag ${{ env.IMG }}:$VERSION ${{ env.IMG }}:main - # BUILD_IMAGE=false skip the build, just push the tag made above - VERSION=main ./scripts/build_deploy.sh + uses: docker/build-push-action@v3 + with: + tags: ${{ env.IMAGE_NAME }}:${{ env.TAG }} + platforms: linux/amd64,linux/s390x,linux/ppc64le + push: true diff --git a/Dockerfile b/Dockerfile index 8f94195a..d7777094 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,7 +34,7 @@ RUN make deps # Build USER root -RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 make clean model-registry +RUN CGO_ENABLED=1 GOOS=linux make clean model-registry # Use distroless as minimal base image to package the model-registry binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index c0b6e681..f555b5d6 100644 --- a/Makefile +++ b/Makefile @@ -96,9 +96,10 @@ pkg/openapi/client.go: bin/openapi-generator-cli api/openapi/model-registry.yaml --ignore-file-override ./.openapi-generator-ignore --additional-properties=isGoSubmodule=true,enumClassPrefix=true,useOneOfDiscriminatorLookup=true gofmt -w pkg/openapi +# Export cc = gcc to resolve error ( cgo: C compiler "s390x-linux-gnu-gcc" not found: exec: "s390x-linux-gnu-gcc": executable file not found in $PATH ) .PHONY: vet vet: - ${GO} vet ./... + CC=gcc ${GO} vet ./... .PHONY: clean clean: @@ -173,10 +174,11 @@ build/odh: vet gen: deps gen/grpc gen/openapi gen/openapi-server gen/converter ${GO} generate ./... +# golanci lint takes more time while running under qemu and facing timeout issue "level=error msg="Timeout exceeded: try increasing it by passing --timeout option" .PHONY: lint lint: - ${GOLANGCI_LINT} run main.go - ${GOLANGCI_LINT} run cmd/... internal/... ./pkg/... + ${GOLANGCI_LINT} run main.go --timeout 2m + ${GOLANGCI_LINT} run cmd/... internal/... ./pkg/... --timeout 2m .PHONY: test test: gen @@ -218,5 +220,15 @@ image/build: .PHONY: image/push image/push: ${DOCKER} push ${IMG}:$(IMG_VERSION) +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le +.PHONY: image/buildx +image/buildx: ## Build and push docker image for the manager for cross-platform support + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross + - $(DOCKER) buildx create --name project-v3-builder + $(DOCKER) buildx use project-v3-builder + - $(DOCKER) buildx build --push --platform=$(PLATFORMS) --tag ${IMG}:$(IMG_VERSION) -f Dockerfile.cross . + - $(DOCKER) buildx rm project-v3-builder + rm Dockerfile.cross all: model-registry diff --git a/scripts/install_protoc.sh b/scripts/install_protoc.sh index b7b165e5..cacc5a9f 100755 --- a/scripts/install_protoc.sh +++ b/scripts/install_protoc.sh @@ -9,9 +9,13 @@ if [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX OS="osx" fi -ARCH="x86_64" -if [[ "$(uname -m)" == "arm"* ]]; then +ARCH=$(uname -m) +if [[ "$ARCH" == "arm"* ]]; then ARCH="aarch_64" +elif [[ "$ARCH" == "s390x" ]]; then + ARCH="s390_64" +elif [[ "$ARCH" == "ppc64le" ]] ; then + ARCH="ppcle_64" fi mkdir -p ${SCRIPT_DIR}/../bin