diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index d751193..da02f8f 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -1,4 +1,4 @@ -name: Build and Push Base Image +name: Build and Push Images on: push: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc0f45f..05b4579 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build Base Image +name: Build images on: pull_request: @@ -24,6 +24,19 @@ jobs: id: set-matrix run: echo images="$(jq '."x-build"' base-images/src/*/.devcontainer.json | jq --slurp -c .)" >> "${GITHUB_OUTPUT}" + prepare-others: + name: Prepare list of other images to build + runs-on: ubuntu-latest + outputs: + images: ${{ steps.set-matrix.outputs.images }} + steps: + - name: Check out the source code + uses: actions/checkout@v4.2.2 + + - name: Set matrix + id: set-matrix + run: echo images="$(jq '."x-build"' images/src/*/.devcontainer.json | jq --slurp -c .)" >> "${GITHUB_OUTPUT}" + build: needs: prepare strategy: @@ -76,3 +89,59 @@ jobs: --cache-from type=gha \ --cache-to type=gha,mode=max if: steps.changes.outputs.needs_build == 'true' + + build-other-images: + needs: + - prepare-others + name: 'Build image ${{ matrix.image.name }}' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + fail-fast: false + matrix: + image: ${{ fromJson(needs.prepare-others.outputs.images) }} + steps: + - name: Check out the repo + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + + - name: Check changed files + id: changes + run: | + base="${{ github.event.pull_request.base.sha }}" + head="${{ github.event.pull_request.head.sha }}" + image="images/src/${{ matrix.image.image-name }}" + changes="$(git diff --name-only "${base}" "${head}" -- "${image}" | grep -Fv "${image}/README.md" || true)" + if [ -n "${changes}" ]; then + echo needs_build=true >> "${GITHUB_OUTPUT}" + else + echo needs_build=false >> "${GITHUB_OUTPUT}" + fi + + - name: Expose GitHub Runtime + uses: Automattic/vip-actions/expose-github-runtime@e1faabf165941008de4c0c1381df153e49d8ad2c # v0.6.0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 + if: steps.changes.outputs.needs_build == 'true' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 + if: steps.changes.outputs.needs_build == 'true' + + - name: Install @devcontainers/cli + run: npm install -g @devcontainers/cli + if: ${{ steps.changes.outputs.needs_build == 'true' }} + + - name: Build image + run: | + devcontainer build \ + --workspace-folder images/src/${{ matrix.image.image-name }} \ + --platform linux/amd64,linux/arm64 \ + --output type=image \ + --cache-from type=gha \ + --cache-to type=gha,mode=max + if: ${{ steps.changes.outputs.needs_build == 'true' }} diff --git a/images/src/wpvip-integrations-base/.devcontainer.json b/images/src/wpvip-integrations-base/.devcontainer.json new file mode 100644 index 0000000..1bf1b48 --- /dev/null +++ b/images/src/wpvip-integrations-base/.devcontainer.json @@ -0,0 +1,51 @@ +{ + "build": { + "dockerfile": "./Dockerfile", + "context": "." + }, + "x-build": { + "name": "WPVIP Integrations", + "image-name": "wpvip-integrations-base", + "image-version": "0.0.1" + }, + "remoteUser": "vscode", + "updateContentCommand": "/usr/local/bin/update-content.sh", + "features": { + "ghcr.io/automattic/vip-codespaces/base:latest": {}, + "ghcr.io/automattic/vip-codespaces/entrypoints:latest": {}, + "ghcr.io/automattic/vip-codespaces/nginx:latest": {}, + "ghcr.io/automattic/vip-codespaces/php:latest": {}, + "ghcr.io/automattic/vip-codespaces/mariadb:latest": { + "installDatabaseToWorkspaces": true + }, + "ghcr.io/automattic/vip-codespaces/wp-cli:latest": {}, + "ghcr.io/automattic/vip-codespaces/memcached:latest": {}, + "ghcr.io/automattic/vip-codespaces/vip-cli:latest": {}, + "ghcr.io/automattic/vip-codespaces/mailpit:latest": {}, + "ghcr.io/automattic/vip-codespaces/phpmyadmin:latest": { + "enabled": true + }, + "ghcr.io/automattic/vip-codespaces/xdebug:latest": { + "enabled": true, + "mode": "debug" + }, + "ghcr.io/automattic/vip-codespaces/desktop-lite:latest": {}, + "ghcr.io/automattic/vip-codespaces/playwright:latest": {}, + "ghcr.io/automattic/vip-codespaces/wptl:latest": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "dlech.chmod", + "dbaeumer.vscode-eslint", + "GitHub.copilot", + "esbenp.prettier-vscode", + "timonwong.shellcheck", + "ms-azuretools.vscode-docker", + "zhiayang.tabindentspacealign", + "emilast.LogFileHighlighter", + "automattic.logwatcher" + ] + } + } +} diff --git a/images/src/wpvip-integrations-base/Dockerfile b/images/src/wpvip-integrations-base/Dockerfile new file mode 100644 index 0000000..47c06d2 --- /dev/null +++ b/images/src/wpvip-integrations-base/Dockerfile @@ -0,0 +1,3 @@ +FROM ghcr.io/automattic/vip-codespaces/ubuntu-base:latest@sha256:267898190c939ea82909113bd957cf97d213135c4dcbb277678f9f8f20a6b4c9 + +COPY update-content.sh /usr/local/bin/update-content.sh diff --git a/images/src/wpvip-integrations-base/update-content.sh b/images/src/wpvip-integrations-base/update-content.sh new file mode 100755 index 0000000..9ee0d0a --- /dev/null +++ b/images/src/wpvip-integrations-base/update-content.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +use-wptl latest +if [ -d node_modules ]; then + npm install +else + npm ci +fi