From 053d7e259a1a06845b97717aa0f4a12611cc7c5b Mon Sep 17 00:00:00 2001 From: CH3CHO Date: Mon, 3 Jun 2024 18:06:11 +0800 Subject: [PATCH] feat: Support building all-in-one images in GitHub action --- .../build-aio-image-and-push copy.yaml | 58 +++++++++++++++++++ all-in-one/Makefile | 24 ++++++++ 2 files changed, 82 insertions(+) create mode 100644 .github/workflows/build-aio-image-and-push copy.yaml create mode 100644 all-in-one/Makefile diff --git a/.github/workflows/build-aio-image-and-push copy.yaml b/.github/workflows/build-aio-image-and-push copy.yaml new file mode 100644 index 0000000..319645d --- /dev/null +++ b/.github/workflows/build-aio-image-and-push copy.yaml @@ -0,0 +1,58 @@ +name: Build All-in-One Image and Push to Image Registry + +on: + push: + tags: + - "aio-v*.*.*" + workflow_dispatch: ~ + +jobs: + build-aio-image: + runs-on: ubuntu-latest + env: + IMAGE_REGISTRY: ${{ vars.IMAGE_REGISTRY || 'higress-registry.cn-hangzhou.cr.aliyuncs.com' }} + IMAGE_NAME: ${{ vars.ALL_IN_ONE_IMAGE_NAME || 'higress/all-in-one' }} + steps: + - name: "Checkout ${{ github.ref }}" + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Calculate Docker metadata + id: docker-meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha + type=match,pattern=aio-v(.*),group=1 + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + + - name: Login to Docker Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build Docker Image and Push + run: | + cd all-in-one/ + readarray -t IMAGES <<< "${{ steps.docker-meta.outputs.tags }}" + baseImage="" + for image in ${IMAGES[@]}; do + echo "Image: $image" + if [ -z "$baseImage" ]; then + IMG="${image}" make docker-buildx-push + baseImage="$image" + else + docker buildx imagetools create "$baseImage" --tag "$image" + fi + done diff --git a/all-in-one/Makefile b/all-in-one/Makefile new file mode 100644 index 0000000..665a672 --- /dev/null +++ b/all-in-one/Makefile @@ -0,0 +1,24 @@ +REGISTRY ?= higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/ +IMAGE_NAME ?= all-in-one +IMAGE_VERSION ?= 1.4.0 +BUILD_TIME := $(shell date "+%Y%m%d-%H%M%S") +COMMIT_ID := $(shell git rev-parse --short HEAD 2>/dev/null) +IMAGE_TAG = $(if $(strip $(IMAGE_VERSION)),${IMAGE_VERSION},${BUILD_TIME}-${COMMIT_ID}) +IMG ?= ${REGISTRY}${IMAGE_NAME}:${IMAGE_TAG} + +.DEFAULT: +docker-build: + docker build \ + -t ${IMG} \ + . + @echo "" + @echo "Image: ${IMG}" + +docker-buildx-push: + docker buildx build --no-cache \ + --platform linux/amd64,linux/arm64 \ + -t ${IMG} \ + --push \ + . + @echo "" + @echo "Image: ${IMG}"