From 89865733f621e8d1b4b63a567c296f5f6889d245 Mon Sep 17 00:00:00 2001 From: Kent Dong Date: Wed, 21 Jun 2023 10:18:23 +0800 Subject: [PATCH] feat: Support building and pushing Higress docker images via GitHub actions (#388) --- .github/workflows/build-image-and-push.yaml | 142 +++++++++++++++++++ .github/workflows/deploy-to-oss.yaml | 3 + istio/1.12/patches/istio/20221027-init.patch | 5 +- 3 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build-image-and-push.yaml diff --git a/.github/workflows/build-image-and-push.yaml b/.github/workflows/build-image-and-push.yaml new file mode 100644 index 000000000..d3b2f9396 --- /dev/null +++ b/.github/workflows/build-image-and-push.yaml @@ -0,0 +1,142 @@ +name: Build Docker Images and Push to Image Registry + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: ~ + +jobs: + build-controller-image: + runs-on: ubuntu-latest + environment: + name: image-registry-controller + env: + CONTROLLER_IMAGE_REGISTRY: ${{ vars.IMAGE_REGISTRY || 'higress-registry.cn-hangzhou.cr.aliyuncs.com' }} + CONTROLLER_IMAGE_NAME: ${{ vars.CONTROLLER_IMAGE_NAME || 'higress/higress' }} + steps: + - name: "Checkout ${{ github.ref }}" + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: "Setup Go" + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Setup Golang Caches + uses: actions/cache@v3 + with: + path: |- + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ github.run_id }} + restore-keys: ${{ runner.os }}-go + + - name: Setup Submodule Caches + uses: actions/cache@v3 + with: + path: |- + envoy + istio + external + .git/modules + key: ${{ runner.os }}-submodules-${{ github.run_id }} + restore-keys: ${{ runner.os }}-submodules + + - name: Calculate Docker metadata + id: docker-meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.CONTROLLER_IMAGE_REGISTRY }}/${{ env.CONTROLLER_IMAGE_NAME }} + tags: | + type=sha + type=ref,event=tag + type=semver,pattern={{version}} + 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.CONTROLLER_IMAGE_REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build Docker Image and Push + run: | + GOPROXY="https://proxy.golang.org,direct" make docker-build + BUILT_IMAGE="higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/higress" + readarray -t IMAGES <<< "${{ steps.docker-meta.outputs.tags }}" + for image in ${IMAGES[@]}; do + docker tag $BUILT_IMAGE:$GITHUB_SHA $image + docker push $image + done + + build-pilot-image: + runs-on: ubuntu-latest + environment: + name: image-registry-pilot + env: + PILOT_IMAGE_REGISTRY: ${{ vars.IMAGE_REGISTRY || 'higress-registry.cn-hangzhou.cr.aliyuncs.com' }} + PILOT_IMAGE_NAME: ${{ vars.PILOT_IMAGE_NAME || 'higress/pilot' }} + steps: + - name: "Checkout ${{ github.ref }}" + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: "Setup Go" + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Setup Golang Caches + uses: actions/cache@v3 + with: + path: |- + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ github.run_id }} + restore-keys: ${{ runner.os }}-go + + - name: Setup Submodule Caches + uses: actions/cache@v3 + with: + path: |- + envoy + istio + external + .git/modules + key: ${{ runner.os }}-submodules-${{ github.run_id }} + restore-keys: ${{ runner.os }}-submodules + + - name: Calculate Docker metadata + id: docker-meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.PILOT_IMAGE_REGISTRY }}/${{ env.PILOT_IMAGE_NAME }} + tags: | + type=sha + type=ref,event=tag + type=semver,pattern={{version}} + 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.PILOT_IMAGE_REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build Docker Image and Push + run: | + sudo GOPROXY="https://proxy.golang.org,direct" make build-istio + BUILT_IMAGE="higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/pilot" + readarray -t IMAGES <<< "${{ steps.docker-meta.outputs.tags }}" + for image in ${IMAGES[@]}; do + docker tag $BUILT_IMAGE:$GITHUB_SHA $image + docker push $image + done diff --git a/.github/workflows/deploy-to-oss.yaml b/.github/workflows/deploy-to-oss.yaml index f9af0ae5d..f470919ad 100644 --- a/.github/workflows/deploy-to-oss.yaml +++ b/.github/workflows/deploy-to-oss.yaml @@ -4,10 +4,13 @@ on: push: tags: - "v*.*.*" + workflow_dispatch: ~ jobs: deploy-to-oss: runs-on: ubuntu-latest + environment: + name: oss steps: # Step 1 - name: Checkout diff --git a/istio/1.12/patches/istio/20221027-init.patch b/istio/1.12/patches/istio/20221027-init.patch index 7dd55b2ce..f867e4ad8 100644 --- a/istio/1.12/patches/istio/20221027-init.patch +++ b/istio/1.12/patches/istio/20221027-init.patch @@ -140,7 +140,7 @@ index 25479439b7..bd34442260 100755 # This script builds and version stamps the output -+export GOPROXY="https://proxy.golang.com.cn,direct" ++export GOPROXY=${GOPROXY:-"https://proxy.golang.com.cn,direct"} + VERBOSE=${VERBOSE:-"0"} V="" @@ -215,10 +215,11 @@ index 271fe77a2d..c9e625efdc 100755 --init \ --sig-proxy=true \ ${DOCKER_SOCKET_MOUNT:--v /var/run/docker.sock:/var/run/docker.sock} \ -@@ -55,7 +59,15 @@ read -ra DOCKER_RUN_OPTIONS <<< "${DOCKER_RUN_OPTIONS:-}" +@@ -55,7 +59,16 @@ read -ra DOCKER_RUN_OPTIONS <<< "${DOCKER_RUN_OPTIONS:-}" --env-file <(env | grep -v ${ENV_BLOCKLIST}) \ -e IN_BUILD_CONTAINER=1 \ -e TZ="${TIMEZONE:-$TZ}" \ ++ -e GOPROXY="${GOPROXY}" \ + -e HUB="${HUB}" \ + -e ENVOY_TAR_PATH="${ENVOY_TAR_PATH}" \ + --mount "type=bind,source=${MOUNT_PACKAGE_SOURCE},destination=/home/package" \