forked from alibaba/higress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support building and pushing Higress docker images via GitHub a…
…ctions (alibaba#388)
- Loading branch information
Showing
3 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters