|
| 1 | +name: Build and Release Assistant Docker Image |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - "mucgpt-assistant-*" # Triggers only on mucgpt-assistant tags |
| 9 | + workflow_dispatch: # Allows manual triggering of the workflow |
| 10 | + inputs: |
| 11 | + tag: |
| 12 | + description: "Assistant tag to release (e.g., mucgpt-assistant-1.0.0)" |
| 13 | + required: true |
| 14 | + default: "mucgpt-assistant-latest" |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-and-push-assistant-service: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + actions: write |
| 21 | + packages: write |
| 22 | + steps: |
| 23 | + - name: Harden the runner (Audit all outbound calls) |
| 24 | + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 |
| 25 | + with: |
| 26 | + egress-policy: audit |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 29 | + - name: Set up QEMU |
| 30 | + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 |
| 33 | + - name: Log in to GitHub Container Registry |
| 34 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 35 | + with: |
| 36 | + registry: ghcr.io |
| 37 | + username: ${{ github.actor }} |
| 38 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + - name: Extract version from mucgpt-assistant tag |
| 40 | + id: vars |
| 41 | + run: | |
| 42 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 43 | + FULL_TAG="${{ github.event.inputs.tag }}" |
| 44 | + else |
| 45 | + FULL_TAG=${GITHUB_REF#refs/tags/} |
| 46 | + fi |
| 47 | +
|
| 48 | + # Extract version from mucgpt-assistant-* tag (e.g., mucgpt-assistant-1.0.0 -> 1.0.0) |
| 49 | + if [[ "$FULL_TAG" =~ ^mucgpt-assistant-(.+)$ ]]; then |
| 50 | + VERSION="${BASH_REMATCH[1]}" |
| 51 | + else |
| 52 | + echo "Error: Tag must start with 'mucgpt-assistant-'" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + echo "full_tag=${FULL_TAG}" >> $GITHUB_OUTPUT |
| 57 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 58 | + echo "repo_lowercase=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT |
| 59 | + - name: Set build timestamp |
| 60 | + id: build_ts |
| 61 | + run: echo "BUILD_TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_ENV" |
| 62 | + - name: Build and push mucgpt-assistant Docker image |
| 63 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 |
| 64 | + with: |
| 65 | + context: ./mucgpt-assistant-service |
| 66 | + file: ./mucgpt-assistant-service/Dockerfile |
| 67 | + push: true |
| 68 | + sbom: true |
| 69 | + provenance: true |
| 70 | + tags: | |
| 71 | + ghcr.io/${{ steps.vars.outputs.repo_lowercase }}/mucgpt-assistant:${{ steps.vars.outputs.version }} |
| 72 | + ghcr.io/${{ steps.vars.outputs.repo_lowercase }}/mucgpt-assistant:latest |
| 73 | + cache-from: type=gha |
| 74 | + cache-to: type=gha,mode=max |
| 75 | + build-args: | |
| 76 | + IMAGE_CREATED=${{ github.event.repository.pushed_at || env.BUILD_TS }} |
| 77 | + IMAGE_REVISION=${{ github.sha }} |
| 78 | + IMAGE_VERSION=${{ steps.vars.outputs.version }} |
| 79 | + - name: Image digest |
| 80 | + run: | |
| 81 | + echo "mucgpt-assistant image built and pushed:" |
| 82 | + echo " ghcr.io/${{ github.repository }}/mucgpt-assistant:${{ steps.vars.outputs.version }}" |
| 83 | + echo " ghcr.io/${{ github.repository }}/mucgpt-assistant:latest" |
0 commit comments