Fix base image #5
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: CI/CD build docker image for php | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - 8.3-fpm | |
| - 8.2-fpm | |
| pull_request: | |
| branches: | |
| - main | |
| - 8.3-fpm | |
| - 8.2-fpm | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| build-test-push: | |
| name: Build, Test and Push Docker Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetches full history for better caching/context | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Extract metadata | |
| id: meta | |
| run: | | |
| echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> "$GITHUB_OUTPUT" | |
| echo "SHORT_SHA=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" | |
| BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}" | sed 's/[^a-zA-Z0-9_.-]/-/g') | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> "$GITHUB_OUTPUT" # | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push production image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| push: true | |
| platforms: linux/amd64 | |
| tags: | | |
| ${{ github.ref == 'refs/heads/main' && format('{0}/{1}:latest', secrets.DOCKER_USERNAME, secrets.DOCKERHUB_PROJECT_NAME) || '' }} | |
| ${{ github.ref != 'refs/heads/main' && format('{0}/{1}:{2}', secrets.DOCKER_USERNAME, secrets.DOCKERHUB_PROJECT_NAME, steps.meta.outputs.BRANCH_NAME) || '' }} | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new | |
| - name: Move cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |