|
| 1 | +name: Build and Push Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + tags: [ 'v*.*.*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ main, master ] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-push: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + packages: write |
| 17 | + |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - dockerfile: Dockerfile |
| 23 | + image: ghcr.io/${{ github.repository }} |
| 24 | +# - dockerfile: frontend/.docker/Dockerfile |
| 25 | +# image: ghcr.io/${{ github.repository }}/frontend |
| 26 | +# context: frontend |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@v3 |
| 34 | + |
| 35 | + - name: Login to GitHub Container Registry |
| 36 | + uses: docker/login-action@v3 |
| 37 | + with: |
| 38 | + registry: ghcr.io |
| 39 | + username: ${{ github.actor }} |
| 40 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Extract metadata for Docker |
| 43 | + id: meta |
| 44 | + uses: docker/metadata-action@v5 |
| 45 | + with: |
| 46 | + images: ${{ matrix.image }} |
| 47 | + tags: | |
| 48 | + type=ref,event=branch |
| 49 | + type=ref,event=pr |
| 50 | + type=semver,pattern={{version}} |
| 51 | + type=sha,format=short |
| 52 | +
|
| 53 | + - name: Build and push Docker image |
| 54 | + uses: docker/build-push-action@v5 |
| 55 | + with: |
| 56 | + context: ${{ matrix.context }} |
| 57 | + file: ${{ matrix.dockerfile }} |
| 58 | + push: ${{ github.event_name != 'pull_request' }} |
| 59 | + tags: ${{ steps.meta.outputs.tags }} |
| 60 | + labels: ${{ steps.meta.outputs.labels }} |
| 61 | + cache-from: type=gha |
| 62 | + cache-to: type=gha,mode=max |
| 63 | + build-args: | |
| 64 | + BUILD_TIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} |
| 65 | + BUILD_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} |
| 66 | + BUILD_REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} |
| 67 | +
|
0 commit comments