sha256:19a08363802cc66e7d656b84ce3de8269297ebe50a8c843d7773da75976bbf09
Last pushed
about 22 hours by bpantelis
Type
Sandbox Kit
Manifest digest
sha256:19a08363802cc66e7d656b84ce3de8269297ebe50a8c843d7773da75976bbf09
schemaVersion: "3"
displayName: WordPress plugin development
description: Network policy and Docker build trust for wp-env, Composer, npm and Playwright inside a sandbox.
kind: mixin
capabilities:
- type: com.docker.sandbox/network-policy@1
config:
runtime:
allow:
- wordpress.org
- downloads.wordpress.org
- api.wordpress.org
- getcomposer.org
- composer.github.io
- deb.debian.org
- dl-cdn.alpinelinux.org
- pecl.php.net
- repo.packagist.org
- packagist.org
- github.com
- api.github.com
- codeload.github.com
- objects.githubusercontent.com
- gitlab.com
- registry.npmjs.org
- registry-1.docker.io
- auth.docker.io
- production.cloudflare.docker.com
- mcr.microsoft.com
- '*.data.mcr.microsoft.com'
- type: com.docker.sandbox/lifecycle@1
config:
files:
- content: |
#!/usr/bin/env bash
# Makes `docker build` inside this sandbox work through the proxy:
# - ~/.docker/config.json "proxies", so RUN steps use the proxy;
# - the proxy CA installed into the wordpress base images wp-env
# builds FROM, re-tagged under their upstream names.
# Idempotent: an image already carrying this CA (label) is skipped.
# Log: ~/.local/state/wp-plugin-dev/docker-build-trust.log
set -uo pipefail
PHP_VERSIONS="${WP_PLUGIN_DEV_PHP_VERSIONS:-8.1 8.5}"
LABEL="dev.wp-plugin-kit.proxy-ca-sha256"
PROXY_URL="${HTTPS_PROXY:-${https_proxy:-http://gateway.docker.internal:3128}}"
NO_PROXY_LIST="localhost,127.0.0.1,::1,gateway.docker.internal"
STATE="$HOME/.local/state/wp-plugin-dev"
mkdir -p "$STATE"
exec >>"$STATE/docker-build-trust.log" 2>&1
echo "=== $(date -u +%FT%TZ) start"
if [ -z "${PROXY_CA_CERT_B64:-}" ]; then
echo "PROXY_CA_CERT_B64 is not set: nothing to do (not a proxied sandbox?)"
exit 0
fi
# The daemon may still be starting: wait up to 3 minutes.
for _ in $(seq 1 90); do docker info >/dev/null 2>&1 && break; sleep 2; done
if ! docker info >/dev/null 2>&1; then
echo "FAIL: docker daemon not reachable after 3 minutes"
exit 1
fi
# 1. Build-time proxy, merged into any existing client config.
python3 - "$PROXY_URL" "$NO_PROXY_LIST" <<'PY'
import json, os, sys
path = os.path.expanduser("~/.docker/config.json")
os.makedirs(os.path.dirname(path), exist_ok=True)
try:
cfg = json.load(open(path))
except (FileNotFoundError, ValueError):
cfg = {}
cfg.setdefault("proxies", {})["default"] = {
"httpProxy": sys.argv[1], "httpsProxy": sys.argv[1], "noProxy": sys.argv[2]}
json.dump(cfg, open(path, "w"), indent=2)
print("docker build proxy:", sys.argv[1])
PY
# 2. The CA, and its fingerprint for the idempotency label.
ctx="$(mktemp -d)"; trap 'rm -rf "$ctx"' EXIT
printf '%s' "$PROXY_CA_CERT_B64" | base64 -d > "$ctx/proxy-ca.crt"
if ! openssl x509 -in "$ctx/proxy-ca.crt" -noout >/dev/null 2>&1; then
echo "FAIL: PROXY_CA_CERT_B64 is not a valid certificate"
exit 1
fi
fp="$(sha256sum "$ctx/proxy-ca.crt" | cut -d' ' -f1)"
# Image ID or our label, without Go templates (kept out of the kit file).
inspect() { # image id|label
docker image inspect "$1" 2>/dev/null | python3 -c '
import json, sys
try:
img = json.load(sys.stdin)[0]
except (ValueError, IndexError):
sys.exit(0)
if sys.argv[1] == "id":
print(img["Id"])
else:
print(((img.get("Config") or {}).get("Labels") or {}).get(sys.argv[2], ""))
' "$2" "$LABEL"
}
trust() { # image dockerfile-body
local image="$1" body="$2" have
have="$(inspect "$image" label)"
if [ "$have" = "$fp" ]; then echo "ok $image (already trusts this CA)"; return 0; fi
# Pull pristine upstream under a temporary local tag (BuildKit cannot
# build FROM a bare image ID), build on it, then take the real tag.
local upstream="wp-plugin-kit-upstream/${image/:/_}:latest"
docker pull -q "$image" >/dev/null || { echo "FAIL $image: pull failed"; return 1; }
docker tag "$image" "$upstream"
printf 'FROM %s\n%s\nLABEL %s=%s\n' "$upstream" "$body" "$LABEL" "$fp" > "$ctx/Dockerfile"
if docker build -q -t "$image" "$ctx" >/dev/null; then
echo "built $image"
else
echo "FAIL $image: build failed"; docker rmi -f "$upstream" >/dev/null 2>&1; return 1
fi
docker rmi "$upstream" >/dev/null 2>&1 || true
}
status=0
for v in $PHP_VERSIONS; do
# Debian base. apt over HTTPS: the sandbox allows deb.debian.org on 443.
# The apt-get update proves the proxy + CA wiring at build time.
trust "wordpress:php${v}" "$(printf '%s\n' \
'COPY proxy-ca.crt /usr/local/share/ca-certificates/sandbox-proxy-ca.crt' \
'RUN update-ca-certificates' \
'RUN sed -i "s|http://deb.debian.org|https://deb.debian.org|g" /etc/apt/sources.list.d/debian.sources && apt-get -qy update >/dev/null')" || status=1
# Alpine CLI base.
trust "wordpress:cli-php${v}" "$(printf '%s\n' \
'USER root' \
'COPY proxy-ca.crt /usr/local/share/ca-certificates/sandbox-proxy-ca.crt' \
'RUN apk add --no-cache ca-certificates >/dev/null && update-ca-certificates' \
'USER www-data')" || status=1
done
echo "=== $(date -u +%FT%TZ) done (status $status)"
exit "$status"
mode: "0755"
path: ${{ kit.env.HOME }}/.local/share/wp-plugin-dev/docker-build-trust.sh
startup:
- background: true
command:
- bash
- -c
- '"$HOME/.local/share/wp-plugin-dev/docker-build-trust.sh"'
description: Let docker build inside the sandbox use the proxy and trust its CA (wordpress base images for wp-env)
env:
- PROXY_CA_CERT_B64
- HTTPS_PROXY
- https_proxy
- WP_PLUGIN_DEV_PHP_VERSIONS