|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + push-image: |
| 7 | + description: Push image to registry. |
| 8 | + required: false |
| 9 | + type: boolean |
| 10 | + default: false |
| 11 | + environment: |
| 12 | + description: GitHub Actions environment to pull variables from (e.g. staging, production). |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: "" |
| 16 | + |
| 17 | +env: |
| 18 | + REGISTRY: ghcr.io |
| 19 | + IMAGE_NAME: ${{ github.repository }} |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-and-push: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + environment: ${{ inputs.environment || null }} |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v6 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Set up QEMU |
| 34 | + uses: docker/setup-qemu-action@v4 |
| 35 | + |
| 36 | + - name: Log in to GitHub Container Registry |
| 37 | + if: ${{ inputs.push-image }} |
| 38 | + uses: docker/login-action@v3 |
| 39 | + with: |
| 40 | + registry: ${{ env.REGISTRY }} |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + - name: Extract metadata (tags, labels) |
| 45 | + id: meta |
| 46 | + uses: docker/metadata-action@v5 |
| 47 | + with: |
| 48 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 49 | + tags: | |
| 50 | + type=ref,event=branch |
| 51 | + type=raw,value=staging,enable={{is_default_branch}} |
| 52 | + type=semver,pattern={{version}} |
| 53 | + type=semver,pattern={{major}}.{{minor}} |
| 54 | + type=sha |
| 55 | +
|
| 56 | + - name: Build and push Docker image |
| 57 | + id: push |
| 58 | + uses: docker/build-push-action@v6 |
| 59 | + with: |
| 60 | + context: . |
| 61 | + push: ${{ inputs.push-image }} |
| 62 | + platforms: linux/amd64,linux/arm64 |
| 63 | + tags: ${{ steps.meta.outputs.tags }} |
| 64 | + labels: ${{ steps.meta.outputs.labels }} |
| 65 | + cache-from: type=gha |
| 66 | + cache-to: type=gha,mode=max |
| 67 | + build-args: | |
| 68 | + VITE_CLIENT_ID=${{ vars.VITE_CLIENT_ID || '' }} |
| 69 | + VITE_TENANT_ID=${{ vars.VITE_TENANT_ID || '' }} |
| 70 | + VITE_API_SCOPE=${{ vars.VITE_API_SCOPE || '' }} |
| 71 | + VITE_AUTHORITY=${{ vars.VITE_AUTHORITY || '' }} |
| 72 | + VITE_BUILD_COMMIT=${{ github.sha }} |
| 73 | + VITE_BUILD_TAG=${{ github.ref_type == 'tag' && github.ref_name || '' }} |
| 74 | + VITE_BUILD_BRANCH=${{ github.ref_name }} |
| 75 | + VITE_BUILD_TIME=${{ github.event.head_commit.timestamp || github.event.repository.updated_at }} |
0 commit comments