From fe7097c6f64574908cf1f97b44a1dd539d9e1e7d Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:28:26 -0300 Subject: [PATCH 1/2] feat: use registry to build image Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/docker-php.yml | 98 ++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/docker-php.yml diff --git a/.github/workflows/docker-php.yml b/.github/workflows/docker-php.yml new file mode 100644 index 00000000..87c726a8 --- /dev/null +++ b/.github/workflows/docker-php.yml @@ -0,0 +1,98 @@ +name: Docker PHP Publish + +on: + schedule: + - cron: '0 2 * * *' + pull_request: + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + push_to_registry: + name: Build and publish image + runs-on: ubuntu-latest + env: + IMAGE_NAME: ghcr.io/librecodecoop/site-php + permissions: + packages: write + contents: read + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + id: docker-cache + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: php-buildx-${{ github.sha }} + restore-keys: | + php-buildx- + + - name: Log in to GitHub Container Registry + if: github.ref == 'refs/heads/main' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + + - name: Set Dockerfile path + id: dockerfile + run: | + DOCKERFILE=$([[ -f ".docker/php/Dockerfile" ]] && echo ".docker/php/Dockerfile" || echo ".docker/Dockerfile.php") + echo "DOCKERFILE=$DOCKERFILE" >> "$GITHUB_OUTPUT" + + - name: Build container image + uses: docker/build-push-action@v6 + with: + push: false + context: .docker/php + platforms: linux/amd64,linux/arm64 + file: ${{ steps.dockerfile.outputs.DOCKERFILE }} + tags: | + ${{ env.IMAGE_NAME }}:${{ github.sha }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + - name: Push container image + if: github.ref == 'refs/heads/main' + uses: docker/build-push-action@v6 + with: + push: true + context: .docker/php + platforms: linux/amd64,linux/arm64 + file: ${{ steps.dockerfile.outputs.DOCKERFILE }} + tags: | + ${{ env.IMAGE_NAME }}:${{ github.sha }} + ${{ env.IMAGE_NAME }}:latest + 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 + + - name: Save Docker cache + if: steps.docker-cache.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: php-buildx-${{ github.sha }} From 9f10f878dead549c74dedad00560590348aee096 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:28:47 -0300 Subject: [PATCH 2/2] chore: replace manual build by image Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 749d38e0..e7dd43fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,8 +9,9 @@ services: - ./build_local:/var/www/html php: - build: - context: .docker/php + image: ghcr.io/librecodecoop/site-php:${PHP_IMAGE_TAG:-latest} + # build: + # context: .docker/php ports: - "127.0.0.1:${HTTP_PORT_PHP:-3000}:3000" - "127.0.0.1:${HTTP_PORT_BROWSERSYNC:-3001}:3001"