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

Build multi platform image & Reorganize Makefiles #4943

Merged
merged 40 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
34c3004
Remove push-image and tag-image script
tung2744 Dec 12, 2024
bf8041a
Remove push-image and tag-image script in custom build
tung2744 Dec 12, 2024
aac6c18
Build multi platform images
tung2744 Dec 12, 2024
65eeb92
Setup docker container builder
tung2744 Dec 13, 2024
62e19c4
Always use build platform to build js assets
tung2744 Dec 13, 2024
1d38d58
Only build amd64 image in prs to reduce build time
tung2744 Dec 13, 2024
16c776d
Fix ssh key is cleaned up too early
tung2744 Dec 13, 2024
cbe4c96
Support BUILD_PLATFORMS in build-image of custombuild
tung2744 Dec 13, 2024
16181dd
Extract common scripts to common.mk
tung2744 Dec 13, 2024
a3a365e
Extract go-mod-outdated to another file
tung2744 Dec 13, 2024
7fa2269
Extract govulncheck to another file
tung2744 Dec 13, 2024
67e74ea
Build different arch image parallelly
tung2744 Dec 13, 2024
7fa51ed
Build different arch portal image parallelly
tung2744 Dec 13, 2024
5bf0931
Update custom build workflows
tung2744 Dec 13, 2024
00fab94
Do not build arm64 image in pr and do not tag image
tung2744 Dec 16, 2024
177d6f1
Use composite action to build image
tung2744 Dec 16, 2024
a45af4e
Fix custom build missing ssh forwarding
tung2744 Dec 16, 2024
0b63af2
Fix custom build scripts
tung2744 Dec 16, 2024
78a96c9
Reduce code duplication in custom build by composite action
tung2744 Dec 16, 2024
a8399c6
Fix EXTRA_BUILD_OPTS is not added to build options
tung2744 Dec 16, 2024
27e2952
Remove duplicated govulncheck
tung2744 Dec 16, 2024
24297f2
Remove extra quote in script
tung2744 Dec 16, 2024
dc7cb1a
Reorganize workflows
tung2744 Dec 16, 2024
af42e74
Build amd64 image in prs
tung2744 Dec 16, 2024
3331fed
Fix workflow names
tung2744 Dec 16, 2024
d390f69
Fix a typo in filename
tung2744 Dec 16, 2024
35f62cb
Write Makefile in idiomatic way
tung2744 Dec 17, 2024
f500227
Push arm64 and amd64 image layer by digest, and create manifest by th…
tung2744 Dec 17, 2024
dcd9abf
Use custom builder
tung2744 Dec 17, 2024
d8c5b17
Do not always push image
tung2744 Dec 17, 2024
b6804fd
Fix portal build step missing id
tung2744 Dec 18, 2024
ce2625a
Use digest in custom build scripts
tung2744 Dec 18, 2024
21b2bb3
Print metadata json for debug
tung2744 Dec 18, 2024
0dd8d21
Use a unique manifest name
tung2744 Dec 18, 2024
9a6a37f
Fix manifest path in custombuild
tung2744 Dec 18, 2024
8fbad47
Turn off provenance in image build
tung2744 Dec 18, 2024
f3f07aa
Use BUILDX_BUILDER instead of --builder
louischan-oursky Dec 19, 2024
6487fda
Remove unused input `builder` from action `build-custom-image`
louischan-oursky Dec 19, 2024
58e96ba
Write METADATA_FILE to temp dir
louischan-oursky Dec 19, 2024
0e94420
Document --provenance=false
louischan-oursky Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/actions/build-custom-image/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build custom image
inputs:
target:
required: true
image_name:
required: true
gcp_project_id:
required: true
gcp_workload_identity_provider:
required: true
docker_repo:
required: false
builder:
required: true
runs:
using: "composite"
steps:
- uses: oursky/google-github-actions-auth@v2
with:
project_id: ${{ inputs.gcp_project_id }}
workload_identity_provider: ${{ inputs.gcp_workload_identity_provider }}
- uses: oursky/google-github-actions-setup-gcloud@v2
- name: Configure docker
env:
REPO: ${{ inputs.docker_repo }}
shell: bash
run: |
gcloud auth configure-docker "$REPO"
- name: Build and Push
env:
TARGET: ${{ inputs.target }}
IMAGE_NAME: ${{ inputs.image_name }}
REPO: ${{ inputs.docker_repo }}
BUILDER: ${{ inputs.builder }}
louischan-oursky marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
run: |
MANIFEST_NAME="./$(uuidgen).json"
make -C custombuild build-image \
TARGET=$TARGET \
BUILD_ARCH=amd64 \
OUTPUT="type=image,name=$IMAGE_NAME,push-by-digest=true,name-canonical=true,push=true" \
IMAGE_NAME=$IMAGE_NAME \
METADATA_FILE=$MANIFEST_NAME \
EXTRA_BUILD_OPTS="--ssh=default --builder=container-builder"
cat custombuild/$MANIFEST_NAME
DIGEST="$(cat custombuild/$MANIFEST_NAME | jq '.["containerimage.digest"]' -r)"
make -C custombuild tag-image SOURCE_DIGESTS="$DIGEST" IMAGE_NAME=$IMAGE_NAME
- name: docker logout
if: ${{ always() }}
env:
REPO: ${{ inputs.docker_repo }}
shell: bash
run: |
docker logout "$REPO"
65 changes: 65 additions & 0 deletions .github/actions/build-image/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build image
inputs:
target:
required: true
image_name:
required: true
push_image:
required: true
build_arch:
required: true
docker_registry:
required: false
docker_username:
required: false
docker_password:
required: false
outputs:
image_digest:
value: ${{ steps.build_image.outputs.image_digest }}
runs:
using: "composite"
steps:
- name: Install qemu for multi arch build
shell: bash
run: docker run --privileged --rm tonistiigi/binfmt --install all
- name: Setup container builder
shell: bash
run: |
docker buildx create \
--name container-builder \
--driver docker-container \
--bootstrap --use
- name: docker login
if: ${{ inputs.push_image == 'true' }}
env:
DOCKER_USERNAME: ${{ inputs.docker_username }}
DOCKER_PASSWORD: ${{ inputs.docker_password }}
DOCKER_REGISTRY: ${{ inputs.docker_registry }}
shell: bash
run: |
printf "$DOCKER_PASSWORD" | docker login --password-stdin --username "$DOCKER_USERNAME" $DOCKER_REGISTRY
- id: build_image
run: |
make build-image \
BUILD_ARCH=$BUILD_ARCH \
OUTPUT=$OUTPUT \
TARGET=$TARGET \
IMAGE_NAME=$IMAGE_NAME \
METADATA_FILE=metadata.json \
EXTRA_BUILD_OPTS="--builder=container-builder"
DIGEST="$(cat metadata.json | jq '.["containerimage.digest"]' -r)"
echo "image_digest=$DIGEST" >> "$GITHUB_OUTPUT"
shell: bash
env:
TARGET: ${{ inputs.target }}
IMAGE_NAME: ${{ inputs.image_name }}
OUTPUT: ${{ (inputs.push_image == 'true') && 'type=image,name=$$IMAGE_NAME,push-by-digest=true,name-canonical=true,push=true' || ''}}
BUILD_ARCH: ${{ inputs.build_arch }}
- name: docker logout
if: ${{ always() }}
env:
DOCKER_REGISTRY: ${{ inputs.docker_registry }}
shell: bash
run: |
docker logout $DOCKER_REGISTRY
21 changes: 21 additions & 0 deletions .github/workflows/ci-branches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI - Branches

on:
push:
branches:
- '*'
- '!gh-pages'
tags:
- '*'

jobs:
checks:
uses: ./.github/workflows/run-checks.yaml
builds:
needs: checks
uses: ./.github/workflows/run-builds.yaml
secrets: inherit
release:
needs: builds
uses: ./.github/workflows/run-release.yaml
secrets: inherit
20 changes: 20 additions & 0 deletions .github/workflows/ci-prs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI - Pull Requests

on:
pull_request:
branches:
- '*'
- '!gh-pages'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
checks:
uses: ./.github/workflows/run-checks.yaml
builds:
needs: checks
uses: ./.github/workflows/run-builds.yaml
with:
amd64-build-only: true
126 changes: 56 additions & 70 deletions .github/workflows/custom-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ jobs:
if: ${{ github.repository == 'authgear/authgear-server' }}
steps:
- uses: actions/checkout@v4
- name: Install qemu for multi arch build
run: docker run --privileged --rm tonistiigi/binfmt --install all
- name: Setup container builder
run: |
docker buildx create \
--name container-builder \
--driver docker-container \
--bootstrap --use

# https://aran.dev/posts/github-actions-go-private-modules/
- name: Set up SSH key
env:
Expand All @@ -53,7 +62,25 @@ jobs:
printf "$AUTHGEAR_PRIVATE_DEPLOY_KEY" | base64 --decode | ssh-add -
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> "$GITHUB_ENV"
echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> "$GITHUB_ENV"
- run: make -C custombuild build-image TARGET=authgearx IMAGE_NAME=authgear-server-custom

- name: Build and push to HK
uses: ./.github/actions/build-custom-image
with:
target: authgearx
image_name: "${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_HK }}/authgear-server"
gcp_project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_HK }}
gcp_workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_HK }}
docker_repo: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_HK }}

- name: Build and push to US
uses: ./.github/actions/build-custom-image
with:
target: authgearx
image_name: "${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_US }}/authgear-server"
gcp_project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_US }}
gcp_workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_US }}
docker_repo: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_US }}

- name: Clean up SSH key
if: ${{ always() }}
run: |
Expand All @@ -62,45 +89,20 @@ jobs:
echo "SSH_AUTH_SOCK=" >> "$GITHUB_ENV"
echo "SSH_AGENT_PID=" >> "$GITHUB_ENV"

- uses: oursky/google-github-actions-auth@v2
with:
project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_HK }}
workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_HK }}
- uses: oursky/google-github-actions-setup-gcloud@v2
- name: Configure docker
env:
REPO: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_HK }}
run: |
gcloud auth configure-docker "$REPO"
- name: Push to HK
env:
REPO_PREFIX: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_HK }}
run: |
make -C custombuild tag-image IMAGE_NAME=authgear-server-custom REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-server"
make -C custombuild push-image REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-server" || docker logout "$REPO"

- uses: oursky/google-github-actions-auth@v2
with:
project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_US }}
workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_US }}
- uses: oursky/google-github-actions-setup-gcloud@v2
- name: Configure docker
env:
REPO: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_US }}
run: |
gcloud auth configure-docker "$REPO"
- name: Push to US
env:
REPO_PREFIX: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_US }}
run: |
make -C custombuild tag-image IMAGE_NAME=authgear-server-custom REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-server"
make -C custombuild push-image REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-server" || docker logout "$REPO"

portal-image-custom:
runs-on: ubuntu-24.04
if: ${{ github.repository == 'authgear/authgear-server' }}
steps:
- uses: actions/checkout@v4
- name: Install qemu for multi arch build
run: docker run --privileged --rm tonistiigi/binfmt --install all
- name: Setup container builder
run: |
docker buildx create \
--name container-builder \
--driver docker-container \
--bootstrap --use

# https://aran.dev/posts/github-actions-go-private-modules/
- name: Set up SSH key
env:
Expand All @@ -112,45 +114,29 @@ jobs:
printf "$AUTHGEAR_PRIVATE_DEPLOY_KEY" | base64 --decode | ssh-add -
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> "$GITHUB_ENV"
echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> "$GITHUB_ENV"
- run: make -C custombuild build-image TARGET=portalx IMAGE_NAME=authgear-portal-custom

- name: Build and push to HK
uses: ./.github/actions/build-custom-image
with:
target: portalx
image_name: "${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_HK }}/authgear-portal"
gcp_project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_HK }}
gcp_workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_HK }}
docker_repo: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_HK }}

- name: Build and push to US
uses: ./.github/actions/build-custom-image
with:
target: portalx
image_name: "${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_US }}/authgear-portal"
gcp_project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_US }}
gcp_workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_US }}
docker_repo: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_US }}

- name: Clean up SSH key
if: ${{ always() }}
run: |
ssh-add -D
ssh-agent -k
echo "SSH_AUTH_SOCK=" >> "$GITHUB_ENV"
echo "SSH_AGENT_PID=" >> "$GITHUB_ENV"

- uses: oursky/google-github-actions-auth@v2
with:
project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_HK }}
workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_HK }}
- uses: oursky/google-github-actions-setup-gcloud@v2
- name: Configure docker
env:
REPO: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_HK }}
run: |
gcloud auth configure-docker "$REPO"
- name: Push to HK
env:
REPO_PREFIX: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_HK }}
run: |
make -C custombuild tag-image IMAGE_NAME=authgear-portal-custom REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-portal"
make -C custombuild push-image REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-portal" || docker logout "$REPO"

- uses: oursky/google-github-actions-auth@v2
with:
project_id: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_PROJECT_ID_US }}
workload_identity_provider: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_GOOGLE_WORKLOAD_IDENTITY_PROVIDER_US }}
- uses: oursky/google-github-actions-setup-gcloud@v2
- name: Configure docker
env:
REPO: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_US }}
run: |
gcloud auth configure-docker "$REPO"
- name: Push to US
env:
REPO_PREFIX: ${{ secrets.AUTHGEAR_CUSTOM_BUILD_REPO_PREFIX_US }}
run: |
make -C custombuild tag-image IMAGE_NAME=authgear-portal-custom REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-portal"
make -C custombuild push-image REMOTE_IMAGE_NAME="$REPO_PREFIX/authgear-portal" || docker logout "$REPO"
Loading