Build Docker image #80
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: Build Docker image | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "5 4 1,15 * *" | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| DOCKERFILE_DIR: php8 | |
| jobs: | |
| buildx: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| php_version: ["8.1", "8.2", "8.3", "8.4"] | |
| variant: ["apache-bookworm", "fpm-alpine"] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Inspect builder | |
| run: | | |
| echo "Name: ${{ steps.buildx.outputs.name }}" | |
| echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
| echo "Status: ${{ steps.buildx.outputs.status }}" | |
| echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
| echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: hussainweb | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| if: github.event_name != 'pull_request' | |
| - name: Set Dockerfile directory | |
| if: ${{ matrix.php_version == '8.1' || matrix.php_version == '8.2' || matrix.php_version == '8.3' || matrix.php_version == '8.4' }} | |
| run: echo "DOCKERFILE_DIR=php8" >> $GITHUB_ENV | |
| - name: Build and push Docker image for PHP ${{ matrix.php_version }} | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.DOCKERFILE_DIR }}/${{ matrix.variant }}/ | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: hussainweb/drupal-base:php${{ matrix.php_version }}${{ matrix.variant == 'fpm-alpine' && '-alpine' || '' }}${{ matrix.php_version == '8.4' && ',hussainweb/drupal-base:latest' || '' }} | |
| build-args: | | |
| PHP_VERSION=${{ matrix.php_version }}-${{ matrix.variant }} | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |