diff --git a/.tangled/workflows/check.yml b/.tangled/workflows/check.yml index e436130..8e3e5ec 100644 --- a/.tangled/workflows/check.yml +++ b/.tangled/workflows/check.yml @@ -21,5 +21,37 @@ steps: - name: "Initialize devenv" command: devenv shell true + - name: "Prime Dagger base image cache" + command: | + devenv shell -- bash -c ' + set -euo pipefail + export DAGGER_NO_NAG=1 + export DOCKER_BUILDKIT=1 + BASE_HASH="$(sha256sum \ + application/Dockerfile \ + application/frankenphp/conf.d/10-app.ini \ + application/frankenphp/docker-entrypoint.sh \ + application/frankenphp/Caddyfile \ + | sha256sum | cut -c1-16)" + BASE_REF="${DAGGER_PHP_BASE_REF:-ttl.sh/rssbase-application-dagger-frankenphp-base-${BASE_HASH}:24h}" + BASE_CACHE_REF="${DAGGER_PHP_BASE_CACHE_REF:-ttl.sh/rssbase-application-dagger-frankenphp-base-build-cache:24h}" + + if docker buildx imagetools inspect "${BASE_REF}" >/dev/null 2>&1; then + echo "Using cached Dagger base image: ${BASE_REF}" + else + echo "Building and publishing Dagger base image: ${BASE_REF}" + docker buildx create --use --name rssbase-ci-builder >/dev/null 2>&1 || docker buildx use rssbase-ci-builder + docker buildx inspect --bootstrap + docker buildx build application \ + --target frankenphp_base \ + --tag "${BASE_REF}" \ + --cache-from "type=registry,ref=${BASE_CACHE_REF}" \ + --cache-to "type=registry,ref=${BASE_CACHE_REF},mode=max" \ + --push + fi + + dagger settings --env ci application phpBaseImageRef "${BASE_REF}" + ' + - name: "Run checks" - command: DAGGER_NO_NAG=1 devenv shell dagger check + command: DAGGER_NO_NAG=1 devenv shell dagger --env ci check diff --git a/application/.dagger/main.dang b/application/.dagger/main.dang index a8adbc8..9679cfb 100644 --- a/application/.dagger/main.dang +++ b/application/.dagger/main.dang @@ -2,15 +2,34 @@ Dagger workflows for rssbase.io/application. """ type Application { - let source: Directory! @defaultPath(path: "/application") @ignorePatterns(patterns: [ - ".dagger", - "var", - "vendor", - ]) + pub source: Directory! + pub phpBaseImageRef: String! + + new( + ws: Workspace!, + """ + Optional prebuilt frankenphp_base image to use instead of building the Dockerfile in Dagger. + Useful in ephemeral CI where the Dagger engine cache starts empty. + """ + phpBaseImageRef: String! = "", + ) { + self.source = ws.directory("/application", exclude: [ + ".dagger", + "var", + "vendor", + ]) + self.phpBaseImageRef = phpBaseImageRef + self + } let phpBase: Container! { - source - .dockerBuild(target: "frankenphp_base") + let base = if (phpBaseImageRef != "") { + container.from(phpBaseImageRef) + } else { + source.dockerBuild(target: "frankenphp_base") + } + + base .withDirectory("/app", source) .withWorkdir("/app") .withMountedCache("/tmp/composer-cache", cacheVolume("composer-cache"))