Skip to content

Commit

Permalink
Support arm
Browse files Browse the repository at this point in the history
Signed-off-by: shaoyue.chen <[email protected]>
  • Loading branch information
haorenfsa committed Jan 19, 2024
1 parent 6695ebc commit 7af6715
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 61 deletions.
128 changes: 73 additions & 55 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,97 @@
name: Build and Push on Tag

# This workflow is triggered on new tag pushed to the repository.
# ref doc: https://docs.docker.com/build/ci/github-actions/multi-platform/
on:
push:
tags:
- "*"
env:
REGISTRY_IMAGE: milvusdb/milvus-operator

jobs:
publish-builder:
name: Publish Builder
build:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: [ubuntu18.04]
env:
OS_NAME: ${{ matrix.os }}
REGISTRY_NAME: milvusdb/milvus-operator
platform:
- linux/amd64
- linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Get version from system time after release step
id: extracter
run: |
echo "::set-output name=git_tag::$(echo "${{ github.ref }}" | awk -F '/' '{print $3}')"
# TODO: add go mod cache
# - name: Cache Go Mod Volumes
# uses: actions/cache@v1
# with:
# path: .docker/go-mod
# key: go-mod-${{ hashFiles('**/go.sum') }}
# restore-keys: go-mod-
- name: Build Docker Image
shell: bash
run: |
IMAGE_TAG=${{ steps.extracter.outputs.git_tag }}
echo "Start Building ${REGISTRY_NAME}:${IMAGE_TAG}"
docker build -t ${REGISTRY_NAME}:${IMAGE_TAG} .
docker tag ${REGISTRY_NAME}:${IMAGE_TAG} ${REGISTRY_NAME}:latest
- name: Push Docker Image
shell: bash
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- 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.MILVUSDB_DOCKER_USER }}
password: ${{ secrets.MILVUSDB_DOCKER_PWD }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
IMAGE_TAG=${{ steps.extracter.outputs.git_tag }}
docker login -u ${{ secrets.MILVUSDB_DOCKER_USER }} \
-p ${{ secrets.MILVUSDB_DOCKER_PWD }}
docker push ${REGISTRY_NAME}:${IMAGE_TAG}
docker push ${REGISTRY_NAME}:latest
tool-publish:
name: Tool Publish Builder
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: [ubuntu18.04]
env:
OS_NAME: ${{ matrix.os }}
REGISTRY_NAME: milvusdb/milvus-config-tool
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get version from system time after release step
id: extracter
run: |
echo "::set-output name=git_tag::$(echo "${{ github.ref }}" | awk -F '/' '{print $3}')"
- name: Build Docker Image
shell: bash
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.MILVUSDB_DOCKER_USER }}
password: ${{ secrets.MILVUSDB_DOCKER_PWD }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
make docker-tool-build
- name: Push Docker Image
shell: bash
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
IMAGE_TAG=${{ steps.extracter.outputs.git_tag }}
docker login -u ${{ secrets.MILVUSDB_DOCKER_USER }} \
-p ${{ secrets.MILVUSDB_DOCKER_PWD }}
make docker-tool-push
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
101 changes: 101 additions & 0 deletions .github/workflows/tool-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Release Config Tool

# This workflow is triggered on new tag pushed to the repository.
# ref doc: https://docs.docker.com/build/ci/github-actions/multi-platform/
on:
push:
branches:
- "release_tool"
env:
REGISTRY_IMAGE: milvusdb/milvus-config-tool
TAG: v0.2.0
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Get version from system time after release step
id: extracter
run: |
echo "::set-output name=git_tag::$(echo "${{ github.ref }}" | awk -F '/' '{print $3}')"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- 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.MILVUSDB_DOCKER_USER }}
password: ${{ secrets.MILVUSDB_DOCKER_PWD }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./tool.Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
${{ env.TAG }}
latest
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.MILVUSDB_DOCKER_USER }}
password: ${{ secrets.MILVUSDB_DOCKER_PWD }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ build-only:

build-config-tool:
mkdir -p out
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o out/merge ./tool/merge
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o out/cp ./tool/cp
CGO_ENABLED=0 go build -ldflags="-s -w" -o out/merge ./tool/merge
CGO_ENABLED=0 go build -ldflags="-s -w" -o out/cp ./tool/cp

build-release: build-config-tool
mkdir -p out
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(BUILD_LDFLAGS)" -o out/manager main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o out/checker ./tool/checker
CGO_ENABLED=0 go build -ldflags="$(BUILD_LDFLAGS)" -o out/manager main.go
CGO_ENABLED=0 go build -ldflags="-s -w" -o out/checker ./tool/checker

run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
Expand Down Expand Up @@ -135,10 +135,12 @@ docker-tool-prepare: build-config-tool
cp ./out/cp ./out/tool/cp

docker-tool-build:
docker build -t ${TOOL_RELEASE_IMG} -f tool.Dockerfile .
docker build --platform=linux/amd64 -t ${TOOL_RELEASE_IMG}-amd64 -f tool.Dockerfile .
docker build --platform=linux/arm64 -t ${TOOL_RELEASE_IMG}-arm64 -f tool.Dockerfile .

docker-tool-push:
docker push ${TOOL_RELEASE_IMG}
docker manifest create ${TOOL_RELEASE_IMG} ${TOOL_RELEASE_IMG}-amd64 ${TOOL_RELEASE_IMG}-arm64
docker manifest push ${TOOL_RELEASE_IMG}

docker-local-build:
docker build -t ${IMG} -f local.Dockerfile .
Expand Down

0 comments on commit 7af6715

Please sign in to comment.