|
| 1 | +name: Build and Publish Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: ghcr.io |
| 16 | + IMAGE_NAME_PHP: ${{ github.repository }}-php |
| 17 | + IMAGE_NAME_NGINX: ${{ github.repository }}-nginx |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-and-push: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Log in to GitHub Container Registry |
| 34 | + if: github.event_name != 'pull_request' |
| 35 | + uses: docker/login-action@v3 |
| 36 | + with: |
| 37 | + registry: ${{ env.REGISTRY }} |
| 38 | + username: ${{ github.actor }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Extract metadata for PHP image |
| 42 | + id: meta-php |
| 43 | + uses: docker/metadata-action@v5 |
| 44 | + with: |
| 45 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_PHP }} |
| 46 | + tags: | |
| 47 | + type=ref,event=branch |
| 48 | + type=ref,event=pr |
| 49 | + type=semver,pattern={{version}} |
| 50 | + type=semver,pattern={{major}}.{{minor}} |
| 51 | + type=semver,pattern={{major}} |
| 52 | + type=sha |
| 53 | +
|
| 54 | + - name: Build and push PHP image |
| 55 | + uses: docker/build-push-action@v5 |
| 56 | + with: |
| 57 | + context: .docker/php |
| 58 | + push: ${{ github.event_name != 'pull_request' }} |
| 59 | + tags: ${{ steps.meta-php.outputs.tags }} |
| 60 | + labels: ${{ steps.meta-php.outputs.labels }} |
| 61 | + cache-from: type=gha |
| 62 | + cache-to: type=gha,mode=max |
| 63 | + |
| 64 | + - name: Extract metadata for Nginx image |
| 65 | + id: meta-nginx |
| 66 | + uses: docker/metadata-action@v5 |
| 67 | + with: |
| 68 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_NGINX }} |
| 69 | + tags: | |
| 70 | + type=ref,event=branch |
| 71 | + type=ref,event=pr |
| 72 | + type=semver,pattern={{version}} |
| 73 | + type=semver,pattern={{major}}.{{minor}} |
| 74 | + type=semver,pattern={{major}} |
| 75 | + type=sha |
| 76 | +
|
| 77 | + - name: Build and push Nginx image |
| 78 | + uses: docker/build-push-action@v5 |
| 79 | + with: |
| 80 | + context: .docker/nginx |
| 81 | + build-args: | |
| 82 | + NGINX_CONF=http |
| 83 | + push: ${{ github.event_name != 'pull_request' }} |
| 84 | + tags: ${{ steps.meta-nginx.outputs.tags }} |
| 85 | + labels: ${{ steps.meta-nginx.outputs.labels }} |
| 86 | + cache-from: type=gha |
| 87 | + cache-to: type=gha,mode=max |
0 commit comments