200 lines
6.3 KiB
YAML
200 lines
6.3 KiB
YAML
name: Docker Build and Push
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["sonarqube"]
|
|
types:
|
|
- completed
|
|
|
|
jobs:
|
|
build-amd64:
|
|
runs-on: [ubuntu-latest, amd64]
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v6
|
|
|
|
- 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: Set version variables
|
|
id: vars
|
|
run: |
|
|
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 "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
|
echo "COMMIT=${{ github.sha }}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push AMD64 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 }}-amd64
|
|
platforms: linux/amd64
|
|
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-amd64
|
|
path: /tmp/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
build-arm64:
|
|
runs-on: [ubuntu-latest, arm64]
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v6
|
|
|
|
- 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: Set version variables
|
|
id: vars
|
|
run: |
|
|
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 "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $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 [ "${{ github.ref_type }}" == "tag" ]; then
|
|
VERSION=${GITHUB_REF#refs/tags/v}
|
|
|
|
if echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
|
|
MAJOR=$(echo "$VERSION" | cut -d. -f1)
|
|
MINOR=$(echo "$VERSION" | cut -d. -f2)
|
|
|
|
TAGS="v${VERSION}"
|
|
|
|
if echo "$VERSION" | grep -q '-'; then
|
|
TAGS="${TAGS},staging"
|
|
else
|
|
TAGS="${TAGS},v${MAJOR}.${MINOR},v${MAJOR},latest"
|
|
fi
|
|
else
|
|
echo "Invalid version format: $VERSION"
|
|
exit 1
|
|
fi
|
|
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
|
TAGS="latest"
|
|
elif [ "${{ github.ref }}" == "refs/heads/staging" ]; then
|
|
TAGS="staging"
|
|
fi
|
|
|
|
echo "TAGS=$TAGS" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create manifest list and push
|
|
working-directory: /tmp/digests
|
|
run: |
|
|
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.TAGS }}"
|
|
|
|
CMD="docker buildx imagetools create"
|
|
|
|
for tag in "${TAG_ARRAY[@]}"; do
|
|
CMD="$CMD -t git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${tag}"
|
|
done
|
|
|
|
CMD="$CMD $(printf 'git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please@sha256:%s ' *)"
|
|
|
|
eval $CMD
|
|
|
|
- name: Inspect image
|
|
run: |
|
|
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.TAGS }}"
|
|
FIRST_TAG="${TAG_ARRAY[0]}"
|
|
docker buildx imagetools inspect git.fossy.my.id/${{ secrets.DOCKER_USERNAME }}/tunnel-please:${FIRST_TAG} |