[Backport] #245 to rel/2.2.x (#246) #1539
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
name: Build Docker Image | |
on: | |
push: | |
branches: | |
- "dependabot/**" | |
- "dev/**" | |
- "main" | |
- "rel/**" | |
paths: | |
- "**.cs" | |
- "**.csproj" | |
- "**.json" | |
- "**.props" | |
- "**.sln" | |
- "CHANGELOG.md" | |
- "**.Dockerfile" | |
- "**/docker.yml" | |
workflow_dispatch: | |
jobs: | |
extract_meta: | |
name: Extract metadata for use | |
if: ${{ github.actor != 'dependabot[bot]' }} | |
runs-on: ubuntu-latest | |
outputs: | |
clean_version: ${{ steps.get-version.outputs.clean_version }} | |
version: ${{ steps.get-version.outputs.version }} | |
environment: ${{ steps.get-environment.outputs.environment }} | |
environment_alpine: ${{ steps.get-environment.outputs.environment_alpine }} | |
config: ${{ steps.get-config.outputs.config }} | |
dockerfile: ${{ steps.get-dockerfile.outputs.dockerfile }} | |
dockerfile_alpine: ${{ steps.get-dockerfile.outputs.dockerfile_alpine }} | |
datetime: ${{ steps.get-datetime.outputs.time }} | |
loc_cs: ${{ steps.get-loc_cs.outputs.total_lines }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get version from Directory.Build.props | |
id: get-version | |
run: | | |
VERSION=$(grep -oP '(?<=<Version>).*?(?=</Version>)' Directory.Build.props) | |
echo "version=v$VERSION" >> "$GITHUB_OUTPUT" | |
echo "clean_version=$VERSION" >> "$GITHUB_OUTPUT" | |
- name: Get build environment | |
id: get-environment | |
run: | | |
if ${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.head_commit.message, '[pre-release]') || contains(github.event.ref, 'rel/') || contains(github.event.ref, 'dev/') || contains(github.event.ref, 'dependabot/') }}; then | |
echo "environment=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" | |
echo "environment_alpine=${{ github.ref_name }}-alpine" >> "$GITHUB_OUTPUT" | |
elif ${{ contains(github.ref_name, 'main') && (!contains(github.event.head_commit.message, '[pre-release]') || !contains(github.event.head_commit.message, '[release]')) }}; then | |
echo "environment=dev" >> "$GITHUB_OUTPUT" | |
echo "environment_alpine=dev-alpine" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Get build config | |
id: get-config | |
run: | | |
if ${{ (contains(github.event.head_commit.message, '[release]') || contains(github.event.head_commit.message, '[pre-release]') || contains(github.event.ref, 'rel/')) }}; then | |
echo "config=Docker" >> "$GITHUB_OUTPUT" | |
else | |
echo "config=Docker-debug" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Get correct Dockerfile | |
id: get-dockerfile | |
run: | | |
if [[ "${{ steps.get-config.outputs.config }}" == "Docker" ]]; then | |
echo "dockerfile=release.Dockerfile" >> "$GITHUB_OUTPUT" | |
echo "dockerfile_alpine=release.alpine.Dockerfile" >> "$GITHUB_OUTPUT" | |
else | |
echo "dockerfile=dev.Dockerfile" >> "$GITHUB_OUTPUT" | |
echo "dockerfile_alpine=dev.alpine.Dockerfile" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Get Date and Time | |
id: get-datetime | |
uses: Kaven-Universe/github-action-current-date-time@v1 | |
with: | |
format: "YYYY-MM-DDTHH:mm:ss" | |
- name: Calculate Lines of Source Code | |
if: ${{ github.actor != 'dependabot[bot]' }} | |
id: get-loc_cs | |
uses: PavanMudigonda/lines-of-code-reporter@v1.6 | |
with: | |
include_lang: "C#,MSBuild script" | |
docker-build-amd: | |
name: Build Docker Image For ${{ matrix.os }} - ${{ matrix.arch }} | |
needs: [extract_meta] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- os: linux | |
arch: amd64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.ref, 'rel/') }} | |
images: sellagh/azzybot | |
tags: type=raw,value=${{ needs.extract_meta.outputs.environment }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
build-args: | | |
CONFIG=${{ needs.extract_meta.outputs.config }} | |
COMMIT=${{ github.sha }} | |
TIMESTAMP=${{ needs.extract_meta.outputs.datetime }} | |
LOC_CS=${{ needs.extract_meta.outputs.loc_cs }} | |
context: . | |
file: ${{ needs.extract_meta.outputs.dockerfile }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: ${{ matrix.os }}/${{ matrix.arch }} | |
outputs: type=image,name=sellagh/azzybot,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: debian-${{ matrix.os }}-${{ matrix.arch }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
docker-build-alpine-amd: | |
name: Build Docker Alpine Image For ${{ matrix.os }} - ${{ matrix.arch }} | |
needs: [extract_meta] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- os: linux | |
arch: amd64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker meta | |
if: ${{ !contains(github.event.head_commit.message, '[release]') && !contains(github.event.head_commit.message, '[pre-release]') && !contains(github.event.ref, 'rel/') }} | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=false | |
images: sellagh/azzybot | |
tags: type=raw,value=${{ needs.extract_meta.outputs.environment_alpine }} | |
- name: Docker meta | |
if: ${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.head_commit.message, '[pre-release]') || contains(github.event.ref, 'rel/') }} | |
id: meta-latest | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=false | |
images: sellagh/azzybot | |
tags: | | |
type=raw,value=${{ needs.extract_meta.outputs.environment_alpine }} | |
type=raw,value=latest-alpine | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
build-args: | | |
CONFIG=${{ needs.extract_meta.outputs.config }} | |
COMMIT=${{ github.sha }} | |
TIMESTAMP=${{ needs.extract_meta.outputs.datetime }} | |
LOC_CS=${{ needs.extract_meta.outputs.loc_cs }} | |
context: . | |
file: ${{ needs.extract_meta.outputs.dockerfile_alpine }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: ${{ matrix.os }}/${{ matrix.arch }} | |
outputs: type=image,name=sellagh/azzybot,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: alpine-${{ matrix.os }}-${{ matrix.arch }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
docker-build-arm: | |
name: Build Docker Image For ${{ matrix.os }} - ${{ matrix.arch }} | |
needs: [extract_meta] | |
runs-on: self-hosted | |
strategy: | |
matrix: | |
include: | |
- os: linux | |
arch: arm64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.ref, 'rel/') }} | |
images: sellagh/azzybot | |
tags: type=raw,value=${{ needs.extract_meta.outputs.environment }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
build-args: | | |
CONFIG=${{ needs.extract_meta.outputs.config }} | |
COMMIT=${{ github.sha }} | |
TIMESTAMP=${{ needs.extract_meta.outputs.datetime }} | |
LOC_CS=${{ needs.extract_meta.outputs.loc_cs }} | |
context: . | |
file: ${{ needs.extract_meta.outputs.dockerfile }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: ${{ matrix.os }}/${{ matrix.arch }} | |
outputs: type=image,name=sellagh/azzybot,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: debian-${{ matrix.os }}-${{ matrix.arch }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
- name: Cleanup Runner | |
if: always() | |
run: | | |
cd /home/runner/actions-runner/_work | |
rm -rf /tmp/digests | |
# docker stop $(docker ps -a -q) | |
# docker system prune -a -f --volumes | |
# docker volume prune -a -f | |
docker-build-alpine-arm: | |
name: Build Docker Alpine Image For ${{ matrix.os }} - ${{ matrix.arch }} | |
needs: [extract_meta] | |
runs-on: self-hosted | |
strategy: | |
matrix: | |
include: | |
- os: linux | |
arch: arm64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker meta | |
if: ${{ !contains(github.event.head_commit.message, '[release]') && !contains(github.event.head_commit.message, '[pre-release]') && !contains(github.event.ref, 'rel/') }} | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=false | |
images: sellagh/azzybot | |
tags: type=raw,value=${{ needs.extract_meta.outputs.environment_alpine }} | |
- name: Docker meta | |
if: ${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.head_commit.message, '[pre-release]') || contains(github.event.ref, 'rel/') }} | |
id: meta-latest | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=false | |
images: sellagh/azzybot | |
tags: | | |
type=raw,value=${{ needs.extract_meta.outputs.environment_alpine }} | |
type=raw,value=latest-alpine | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
build-args: | | |
CONFIG=${{ needs.extract_meta.outputs.config }} | |
COMMIT=${{ github.sha }} | |
TIMESTAMP=${{ needs.extract_meta.outputs.datetime }} | |
LOC_CS=${{ needs.extract_meta.outputs.loc_cs }} | |
context: . | |
file: ${{ needs.extract_meta.outputs.dockerfile_alpine }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: ${{ matrix.os }}/${{ matrix.arch }} | |
outputs: type=image,name=sellagh/azzybot,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: alpine-${{ matrix.os }}-${{ matrix.arch }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
- name: Cleanup Runner | |
if: always() | |
run: | | |
cd /home/runner/actions-runner/_work | |
rm -rf /tmp/digests | |
# docker stop $(docker ps -a -q) | |
# docker system prune -a -f --volumes | |
# docker volume prune -a -f | |
merge: | |
name: Creating Docker Release | |
runs-on: ubuntu-latest | |
needs: [extract_meta, docker-build-amd, docker-build-alpine-amd, docker-build-arm, docker-build-alpine-arm] | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: debian-* | |
merge-multiple: true | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.ref, 'rel/') }} | |
images: sellagh/azzybot | |
tags: type=raw,value=${{ needs.extract_meta.outputs.environment }} | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf 'sellagh/azzybot@sha256:%s ' *) | |
merge-alpine: | |
name: Creating Docker Alpine Release | |
runs-on: ubuntu-latest | |
needs: [extract_meta, docker-build-amd, docker-build-alpine-amd, docker-build-arm, docker-build-alpine-arm] | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: alpine-* | |
merge-multiple: true | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
if: ${{ !contains(github.event.head_commit.message, '[release]') && !contains(github.event.head_commit.message, '[pre-release]') && !contains(github.event.ref, 'rel/') }} | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=false | |
images: sellagh/azzybot | |
tags: type=raw,value=${{ needs.extract_meta.outputs.environment_alpine }} | |
- name: Docker meta | |
if: ${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.head_commit.message, '[pre-release]') || contains(github.event.ref, 'rel/') }} | |
id: meta-latest | |
uses: docker/metadata-action@v5 | |
with: | |
flavor: latest=false | |
images: sellagh/azzybot | |
tags: | | |
type=raw,value=${{ needs.extract_meta.outputs.environment_alpine }} | |
type=raw,value=latest-alpine | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf 'sellagh/azzybot@sha256:%s ' *) |