Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multi-arch i.e. s390x & pp64cle #62

Closed
wants to merge 12 commits into from
55 changes: 27 additions & 28 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 6 additions & 2 deletions scripts/install_protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down