ci: update build for multi-machine architecture support
Testing / SonarQube Trigger (push) Successful in 2m16s
Testing / SonarQube Trigger (push) Successful in 2m16s
This commit is contained in:
+138
-90
@@ -1,25 +1,14 @@
|
|||||||
name: Docker Build and Push
|
name: Docker Build and Push
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_run:
|
||||||
branches:
|
workflows: ["Testing"]
|
||||||
- main
|
types:
|
||||||
- staging
|
- completed
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
paths:
|
|
||||||
- '**.go'
|
|
||||||
- 'go.mod'
|
|
||||||
- 'go.sum'
|
|
||||||
- 'Dockerfile'
|
|
||||||
- 'Dockerfile.*'
|
|
||||||
- '.dockerignore'
|
|
||||||
- '.gitea/workflows/build.yml'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push-branches:
|
build-amd64:
|
||||||
runs-on: ubuntu-latest
|
runs-on: [ubuntu-latest, amd64]
|
||||||
if: github.ref_type == 'branch'
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -28,7 +17,7 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: git.fossy.my.id
|
registry: git.fossy.my.id
|
||||||
@@ -38,45 +27,46 @@ jobs:
|
|||||||
- name: Set version variables
|
- name: Set version variables
|
||||||
id: vars
|
id: vars
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
if [ "${{ github.ref_type }}" == "tag" ]; then
|
||||||
echo "VERSION=dev-main" >> $GITHUB_OUTPUT
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
|
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||||
|
VERSION=dev-main
|
||||||
else
|
else
|
||||||
echo "VERSION=dev-staging" >> $GITHUB_OUTPUT
|
VERSION=dev-staging
|
||||||
fi
|
fi
|
||||||
|
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
||||||
echo "COMMIT=${{ github.sha }}" >> $GITHUB_OUTPUT
|
echo "COMMIT=${{ github.sha }}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build and push Docker image for main
|
- name: Build and push AMD64 image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${{ steps.vars.outputs.VERSION }}-amd64
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:latest
|
platforms: linux/amd64
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=${{ steps.vars.outputs.VERSION }}
|
VERSION=${{ steps.vars.outputs.VERSION }}
|
||||||
BUILD_DATE=${{ steps.vars.outputs.BUILD_DATE }}
|
BUILD_DATE=${{ steps.vars.outputs.BUILD_DATE }}
|
||||||
COMMIT=${{ steps.vars.outputs.COMMIT }}
|
COMMIT=${{ steps.vars.outputs.COMMIT }}
|
||||||
if: github.ref == 'refs/heads/main'
|
outputs: type=image,name=git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please,push-by-digest=true,name-canonical=true,push=true
|
||||||
|
|
||||||
- name: Build and push Docker image for staging
|
- name: Export digest
|
||||||
uses: docker/build-push-action@v6
|
run: |
|
||||||
|
mkdir -p /tmp/digests
|
||||||
|
digest="${{ steps.build.outputs.digest }}"
|
||||||
|
touch "/tmp/digests/${digest#sha256:}"
|
||||||
|
|
||||||
|
- name: Upload digest
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
name: digests-amd64
|
||||||
push: true
|
path: /tmp/digests/*
|
||||||
tags: |
|
if-no-files-found: error
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:staging
|
retention-days: 1
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
build-args: |
|
|
||||||
VERSION=${{ steps.vars.outputs.VERSION }}
|
|
||||||
BUILD_DATE=${{ steps.vars.outputs.BUILD_DATE }}
|
|
||||||
COMMIT=${{ steps.vars.outputs.COMMIT }}
|
|
||||||
if: github.ref == 'refs/heads/staging'
|
|
||||||
|
|
||||||
build-and-push-tags:
|
build-arm64:
|
||||||
runs-on: ubuntu-latest
|
runs-on: [ubuntu-latest, arm64]
|
||||||
if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -85,68 +75,126 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: git.fossy.my.id
|
registry: git.fossy.my.id
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- name: Extract version and determine release type
|
- name: Set version variables
|
||||||
id: version
|
id: vars
|
||||||
run: |
|
run: |
|
||||||
VERSION=${GITHUB_REF#refs/tags/v}
|
if [ "${{ github.ref_type }}" == "tag" ]; then
|
||||||
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
|
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||||
|
VERSION=dev-main
|
||||||
|
else
|
||||||
|
VERSION=dev-staging
|
||||||
|
fi
|
||||||
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
||||||
echo "COMMIT=${{ github.sha }}" >> $GITHUB_OUTPUT
|
echo "COMMIT=${{ github.sha }}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and push ARM64 image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${{ steps.vars.outputs.VERSION }}-arm64
|
||||||
|
platforms: linux/arm64
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ steps.vars.outputs.VERSION }}
|
||||||
|
BUILD_DATE=${{ steps.vars.outputs.BUILD_DATE }}
|
||||||
|
COMMIT=${{ steps.vars.outputs.COMMIT }}
|
||||||
|
outputs: type=image,name=git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please,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-arm64
|
||||||
|
path: /tmp/digests/*
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
merge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- build-amd64
|
||||||
|
- build-arm64
|
||||||
|
|
||||||
|
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: Log in to Docker Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.fossy.my.id
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Determine tags
|
||||||
|
id: tags
|
||||||
|
run: |
|
||||||
|
TAGS=""
|
||||||
|
|
||||||
if echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
|
if [ "${{ github.ref_type }}" == "tag" ]; then
|
||||||
MAJOR=$(echo "$VERSION" | cut -d. -f1)
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
MINOR=$(echo "$VERSION" | cut -d. -f2)
|
|
||||||
|
if echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
|
||||||
echo "MAJOR=$MAJOR" >> $GITHUB_OUTPUT
|
MAJOR=$(echo "$VERSION" | cut -d. -f1)
|
||||||
echo "MINOR=$MINOR" >> $GITHUB_OUTPUT
|
MINOR=$(echo "$VERSION" | cut -d. -f2)
|
||||||
|
|
||||||
if echo "$VERSION" | grep -q '-'; then
|
TAGS="v${VERSION}"
|
||||||
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
|
|
||||||
echo "ADDITIONAL_TAG=staging" >> $GITHUB_OUTPUT
|
if echo "$VERSION" | grep -q '-'; then
|
||||||
|
TAGS="${TAGS},staging"
|
||||||
|
else
|
||||||
|
TAGS="${TAGS},v${MAJOR}.${MINOR},v${MAJOR},latest"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
|
echo "Invalid version format: $VERSION"
|
||||||
echo "ADDITIONAL_TAG=latest" >> $GITHUB_OUTPUT
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||||
echo "Invalid version format: $VERSION"
|
TAGS="latest"
|
||||||
exit 1
|
elif [ "${{ github.ref }}" == "refs/heads/staging" ]; then
|
||||||
|
TAGS="staging"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "TAGS=$TAGS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build and push Docker image for release
|
- name: Create manifest list and push
|
||||||
uses: docker/build-push-action@v6
|
working-directory: /tmp/digests
|
||||||
with:
|
run: |
|
||||||
context: .
|
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.TAGS }}"
|
||||||
push: true
|
|
||||||
tags: |
|
CMD="docker buildx imagetools create"
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:v${{ steps.version.outputs.VERSION }}
|
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:v${{ steps.version.outputs.MAJOR }}.${{ steps.version.outputs.MINOR }}
|
for tag in "${TAG_ARRAY[@]}"; do
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:v${{ steps.version.outputs.MAJOR }}
|
CMD="$CMD -t git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${tag}"
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${{ steps.version.outputs.ADDITIONAL_TAG }}
|
done
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
build-args: |
|
CMD="$CMD $(printf 'git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please@sha256:%s ' *)"
|
||||||
VERSION=${{ steps.version.outputs.VERSION }}
|
|
||||||
BUILD_DATE=${{ steps.version.outputs.BUILD_DATE }}
|
eval $CMD
|
||||||
COMMIT=${{ steps.version.outputs.COMMIT }}
|
|
||||||
if: steps.version.outputs.IS_PRERELEASE == 'false'
|
|
||||||
|
|
||||||
- name: Build and push Docker image for pre-release
|
- name: Inspect image
|
||||||
uses: docker/build-push-action@v6
|
run: |
|
||||||
with:
|
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.TAGS }}"
|
||||||
context: .
|
FIRST_TAG="${TAG_ARRAY[0]}"
|
||||||
push: true
|
docker buildx imagetools inspect git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${FIRST_TAG}
|
||||||
tags: |
|
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:v${{ steps.version.outputs.VERSION }}
|
|
||||||
git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${{ steps.version.outputs.ADDITIONAL_TAG }}
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
build-args: |
|
|
||||||
VERSION=${{ steps.version.outputs.VERSION }}
|
|
||||||
BUILD_DATE=${{ steps.version.outputs.BUILD_DATE }}
|
|
||||||
COMMIT=${{ steps.version.outputs.COMMIT }}
|
|
||||||
if: steps.version.outputs.IS_PRERELEASE == 'true'
|
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, synchronize, reopened]
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
name: SonarQube Scan
|
name: Testing
|
||||||
jobs:
|
jobs:
|
||||||
sonarqube:
|
sonarqube:
|
||||||
name: SonarQube Trigger
|
name: SonarQube Trigger
|
||||||
@@ -42,14 +43,22 @@ jobs:
|
|||||||
|
|
||||||
- name: Set SonarQube project key
|
- name: Set SonarQube project key
|
||||||
run: |
|
run: |
|
||||||
BRANCH_NAME=${GITHUB_REF#refs/heads/}
|
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
||||||
if [ "$BRANCH_NAME" = "main" ]; then
|
TAG_NAME=${GITHUB_REF#refs/tags/}
|
||||||
SONAR_PROJECT_KEY="tunnel-please"
|
BRANCH_KEY=${TAG_NAME//\//-}
|
||||||
else
|
|
||||||
BRANCH_KEY=${BRANCH_NAME//\//-}
|
|
||||||
SONAR_PROJECT_KEY="tunnel-please-$BRANCH_KEY"
|
SONAR_PROJECT_KEY="tunnel-please-$BRANCH_KEY"
|
||||||
|
elif [[ "$GITHUB_REF" == refs/heads/* ]]; then
|
||||||
|
BRANCH_NAME=${GITHUB_REF#refs/heads/}
|
||||||
|
if [ "$BRANCH_NAME" = "main" ]; then
|
||||||
|
SONAR_PROJECT_KEY="tunnel-please"
|
||||||
|
else
|
||||||
|
BRANCH_KEY=${BRANCH_NAME//\//-}
|
||||||
|
SONAR_PROJECT_KEY="tunnel-please-$BRANCH_KEY"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
SONAR_PROJECT_KEY="tunnel-please"
|
||||||
fi
|
fi
|
||||||
echo "SONAR_PROJECT_KEY=tunnel-please-$BRANCH_KEY" >> $GITHUB_ENV
|
echo "SONAR_PROJECT_KEY=$SONAR_PROJECT_KEY" >> $GITHUB_ENV
|
||||||
echo "Using SonarQube Project Key: $SONAR_PROJECT_KEY"
|
echo "Using SonarQube Project Key: $SONAR_PROJECT_KEY"
|
||||||
|
|
||||||
- name: SonarQube Scan
|
- name: SonarQube Scan
|
||||||
|
|||||||
Reference in New Issue
Block a user