Release (build & push) #71
This file contains hidden or 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: Release (build & push) | |
| 'on': | |
| push: | |
| tags: | |
| - 'v*.*.*' # SemVer-Tags | |
| workflow_dispatch: | |
| inputs: | |
| rebuild_tags: | |
| description: 'Rebuild last N tags' | |
| required: false | |
| default: false | |
| type: boolean | |
| num_tags: | |
| description: 'How many recent tags to rebuild' | |
| required: false | |
| default: 1 | |
| type: number | |
| schedule: | |
| - cron: '0 1 * * 2' # Dienstag 01:00 UTC | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| security-events: write | |
| concurrency: | |
| group: release-${{ github.event_name == 'schedule' && 'schedule' || github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| # (A) TAG-REBUILD: nur bei Cron oder manuell (rebuild_tags=true) | |
| select-tags: | |
| if: ${{ github.event_name == 'schedule' || inputs.rebuild_tags }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tags_json: ${{ steps.out.outputs.tags_json }} | |
| latest_tag: ${{ steps.out.outputs.latest_tag }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - id: out | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| num="${{ inputs.num_tags }}" | |
| [ -z "${num}" ] && num=1 | |
| TAGS="$(git tag --list 'v*.*.*' --sort=-v:refname | head -n "${num}")" | |
| printf 'Selected tags:\n%s\n' "${TAGS}" | |
| # Tags als JSON | |
| JSON_TAGS="$(printf '%s\n' "${TAGS}" | jq -R . | jq -s -c .)" | |
| echo "tags_json=${JSON_TAGS}" >> "$GITHUB_OUTPUT" | |
| # NEUSTER Tag (erste Zeile der sortierten Liste) | |
| LATEST_TAG="$(printf '%s\n' "${TAGS}" | head -n 1)" | |
| echo "latest_tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT" | |
| rebuild: | |
| needs: select-tags | |
| if: ${{ needs.select-tags.outputs.tags_json != '' }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| tag: ${{ fromJSON(needs.select-tags.outputs.tags_json) }} | |
| image: | |
| - name: "dbcleanup" | |
| dockerfile: "Dockerfile-dbcleanup" | |
| context: "." | |
| - name: "loganalyzer" | |
| dockerfile: "Dockerfile-loganalyzer" | |
| context: "." | |
| - name: "syslogng" | |
| dockerfile: "Dockerfile-syslogng" | |
| context: "." | |
| steps: | |
| - name: Checkout at tag | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ matrix.tag }} | |
| fetch-depth: 0 | |
| - name: Compute semver tags (strip v + major/minor) | |
| id: semver | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| v="${{ matrix.tag }}" | |
| v="${v#v}" # v1.45.1 -> 1.45.1 | |
| IFS='.' read -r major minor patch extra <<< "$v" | |
| if [[ -z "${major:-}" || -z "${minor:-}" || -z "${patch:-}" ]]; then | |
| echo "Tag is not x.y.z: '$v'" >&2 | |
| exit 1 | |
| fi | |
| echo "full=$v" >> "$GITHUB_OUTPUT" # 1.45.1 | |
| echo "minor=$major.$minor" >> "$GITHUB_OUTPUT" # 1.45 | |
| echo "major=$major" >> "$GITHUB_OUTPUT" # 1 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Docker meta (rebuild tag + aliases) | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ghcr.io/${{ github.repository_owner }}/${{ matrix.image.name }} | |
| tags: | | |
| type=raw,value=${{ steps.semver.outputs.full }} | |
| type=raw,value=${{ steps.semver.outputs.minor }} | |
| type=raw,value=${{ steps.semver.outputs.major }} | |
| type=raw,value=latest,enable=${{ matrix.tag == needs.select-tags.outputs.latest_tag }} | |
| labels: | | |
| org.opencontainers.image.source=${{ github.repository }} | |
| # Pre-build (amd64) zum Scannen, nicht pushen | |
| - name: Build (scan image) | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ${{ matrix.image.context }} | |
| file: ${{ matrix.image.dockerfile }} | |
| pull: true # aktualisiert Base-Image | |
| push: false | |
| load: true | |
| platforms: linux/amd64 | |
| tags: scan:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Trivy FS (SARIF) | |
| uses: aquasecurity/trivy-action@0.35.0 | |
| continue-on-error: true | |
| with: | |
| scan-type: fs | |
| format: sarif | |
| output: trivy-fs.sarif | |
| ignore-unfixed: true | |
| # severity: HIGH,CRITICAL | |
| severity: CRITICAL | |
| - name: Upload FS SARIF | |
| if: always() | |
| uses: github/codeql-action/upload-sarif@v4 | |
| with: | |
| sarif_file: trivy-fs.sarif | |
| category: trivy-fs-rebuild | |
| - name: Trivy Image (gate) | |
| uses: aquasecurity/trivy-action@0.35.0 | |
| with: | |
| image-ref: scan:${{ github.sha }} | |
| format: table | |
| exit-code: '1' | |
| ignore-unfixed: true | |
| # severity: HIGH,CRITICAL | |
| severity: CRITICAL | |
| - name: Build & Push (multi-arch, overwrite tag) | |
| if: ${{ success() }} | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ${{ matrix.image.context }} | |
| file: ${{ matrix.image.dockerfile }} | |
| platforms: linux/amd64,linux/arm64 | |
| pull: true | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # (B) KLASSISCHER RELEASE: nur bei Tag-Push | |
| release: | |
| if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: | |
| - name: "dbcleanup" | |
| dockerfile: "Dockerfile-dbcleanup" | |
| context: "." | |
| - name: "loganalyzer" | |
| dockerfile: "Dockerfile-loganalyzer" | |
| context: "." | |
| - name: "syslogng" | |
| dockerfile: "Dockerfile-syslogng" | |
| context: "." | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Docker meta (semver without v + latest) | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ghcr.io/${{ github.repository_owner }}/${{ matrix.image.name }} | |
| tags: | | |
| # nimmt v1.2.3 und macht 1.2.3 | |
| type=semver,pattern={{version}},prefix= | |
| type=semver,pattern={{major}}.{{minor}},prefix= | |
| type=semver,pattern={{major}},prefix= | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| labels: | | |
| org.opencontainers.image.source=${{ github.repository }} | |
| # Pre-build (amd64) zum Scannen | |
| - name: Pre-build (load for scan) | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ${{ matrix.image.context }} | |
| file: ${{ matrix.image.dockerfile }} | |
| pull: true | |
| push: false | |
| load: true | |
| platforms: linux/amd64 | |
| tags: scan:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Trivy Image (SARIF) | |
| uses: aquasecurity/trivy-action@0.35.0 | |
| with: | |
| image-ref: scan:${{ github.sha }} | |
| format: sarif | |
| output: trivy-release.sarif | |
| exit-code: '0' | |
| hide-progress: true | |
| - name: Trivy Image (enforce severity) | |
| uses: aquasecurity/trivy-action@0.35.0 | |
| with: | |
| image-ref: scan:${{ github.sha }} | |
| # severity: CRITICAL,HIGH | |
| severity: CRITICAL | |
| ignore-unfixed: true | |
| exit-code: '1' | |
| hide-progress: true | |
| - name: Build & Push (multi-arch) | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ${{ matrix.image.context }} | |
| file: ${{ matrix.image.dockerfile }} | |
| platforms: linux/amd64,linux/arm64 | |
| pull: true | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |