From fbc66021b5fbfad048e758d230d612bea77ec91a Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Wed, 11 Nov 2026 20:29:39 +0100 Subject: [PATCH 1/2] feat(templates): add app deployment template (image, compose, Helm) templates/app-deploy renders, per app id, an evaluation Dockerfile (official Nextcloud 33 image with the app built from the repo and the newest stable OpenRegister release, SHA-256 checked), an entrypoint hook that syncs and enables the baked apps, a docker-compose.yml with PostgreSQL and Redis, a Helm chart over the official Nextcloud chart and an image workflow that pushes ghcr.io/conductionnl/ (stable: version and latest; prerelease: edge). The release workflows keep these files out of the app tarball. Assisted-by: ClaudeCode:claude-opus-5-5 --- .github/workflows/release-beta.yml | 3 + .github/workflows/release-stable.yml | 3 + .github/workflows/release.yml | 3 + templates/app-deploy/.dockerignore | 20 ++++ templates/app-deploy/Dockerfile | 109 ++++++++++++++++++ templates/app-deploy/README-section.md | 22 ++++ templates/app-deploy/README.md | 37 ++++++ .../app-deploy/charts/__APP_ID__/.gitignore | 2 + .../app-deploy/charts/__APP_ID__/.helmignore | 5 + .../app-deploy/charts/__APP_ID__/Chart.yaml | 18 +++ .../charts/__APP_ID__/templates/NOTES.txt | 10 ++ .../app-deploy/charts/__APP_ID__/values.yaml | 53 +++++++++ templates/app-deploy/docker-compose.yml | 93 +++++++++++++++ .../before-starting/10-image-apps.sh | 54 +++++++++ templates/app-deploy/render.sh | 71 ++++++++++++ .../app-deploy/workflows/container-image.yml | 89 ++++++++++++++ 16 files changed, 592 insertions(+) create mode 100644 templates/app-deploy/.dockerignore create mode 100644 templates/app-deploy/Dockerfile create mode 100644 templates/app-deploy/README-section.md create mode 100644 templates/app-deploy/README.md create mode 100644 templates/app-deploy/charts/__APP_ID__/.gitignore create mode 100644 templates/app-deploy/charts/__APP_ID__/.helmignore create mode 100644 templates/app-deploy/charts/__APP_ID__/Chart.yaml create mode 100644 templates/app-deploy/charts/__APP_ID__/templates/NOTES.txt create mode 100644 templates/app-deploy/charts/__APP_ID__/values.yaml create mode 100644 templates/app-deploy/docker-compose.yml create mode 100755 templates/app-deploy/docker/entrypoint-hooks/before-starting/10-image-apps.sh create mode 100755 templates/app-deploy/render.sh create mode 100644 templates/app-deploy/workflows/container-image.yml diff --git a/.github/workflows/release-beta.yml b/.github/workflows/release-beta.yml index 55beb49c..f42976ad 100644 --- a/.github/workflows/release-beta.yml +++ b/.github/workflows/release-beta.yml @@ -220,6 +220,9 @@ jobs: --exclude='/.nextcloud' \ --exclude='/docker' \ --exclude='/docker-compose.yml' \ + --exclude='/Dockerfile' \ + --exclude='/.dockerignore' \ + --exclude='/charts' \ --exclude='/docs' \ --exclude='/website' \ --exclude='/node_modules' \ diff --git a/.github/workflows/release-stable.yml b/.github/workflows/release-stable.yml index 9a5920e3..fae7cae8 100644 --- a/.github/workflows/release-stable.yml +++ b/.github/workflows/release-stable.yml @@ -191,6 +191,9 @@ jobs: --exclude='/.nextcloud' \ --exclude='/docker' \ --exclude='/docker-compose.yml' \ + --exclude='/Dockerfile' \ + --exclude='/.dockerignore' \ + --exclude='/charts' \ --exclude='/docs' \ --exclude='/website' \ --exclude='/node_modules' \ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b660213b..b1ce62e6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1453,6 +1453,9 @@ jobs: --exclude='/.nextcloud' \ --exclude='/docker' \ --exclude='/docker-compose.yml' \ + --exclude='/Dockerfile' \ + --exclude='/.dockerignore' \ + --exclude='/charts' \ --exclude='/docs' \ --exclude='/docusaurus' \ --exclude='/website' \ diff --git a/templates/app-deploy/.dockerignore b/templates/app-deploy/.dockerignore new file mode 100644 index 00000000..ec2ed7ce --- /dev/null +++ b/templates/app-deploy/.dockerignore @@ -0,0 +1,20 @@ +# Build context for the evaluation image. The image installs vendor/ and +# builds js/ itself, so local dependencies stay out. +# Rendered from ConductionNL/.github templates/app-deploy. +.git +**/node_modules +vendor +coverage +.phpunit.cache +.phpunit.result.cache +tests/e2e/results +playwright-report +test-results +*.log +.env +# The deployment files themselves, so editing them does not rebuild the app. +Dockerfile +.dockerignore +docker-compose*.yml +charts +.github diff --git a/templates/app-deploy/Dockerfile b/templates/app-deploy/Dockerfile new file mode 100644 index 00000000..decf558a --- /dev/null +++ b/templates/app-deploy/Dockerfile @@ -0,0 +1,109 @@ +# syntax=docker/dockerfile:1 +# +# Evaluation image for __APP_ID__: the official Nextcloud image with this app, +# built from this repository, and OpenRegister, taken from its release. +# +# docker build -t ghcr.io/conductionnl/__APP_ID__ . +# +# The supported production install is still the Nextcloud App Store. This image +# is for trying the app out, for demos and for test environments. +# +# Rendered from ConductionNL/.github templates/app-deploy. Change the template, +# not this copy, and render it again. +# +# SPDX-FileCopyrightText: 2026 Conduction B.V. +# SPDX-License-Identifier: EUPL-1.2 + +# Nextcloud 33 is the newest major whose image still ships PHP 8.3. The 34 and +# 35 images ship PHP 8.5, which some apps in the fleet do not support yet. +ARG NEXTCLOUD_IMAGE=nextcloud:33.0.10-apache +ARG APP_ID=__APP_ID__ + +# ── Frontend: the same steps the release workflow runs ── +FROM node:22-bookworm-slim AS frontend +WORKDIR /app +COPY . . +# Honour engines.npm: Node 22 bundles npm 10, several apps require npm 11. +RUN set -eu; \ + range="$(node -p "((require('./package.json').engines)||{}).npm||''")"; \ + if [ -n "$range" ]; then npm install -g "npm@$range"; fi; \ + npm ci --no-audit --no-fund; \ + npm run build; \ + rm -rf node_modules + +# ── Backend: runtime composer dependencies only ── +FROM composer:2 AS vendor +WORKDIR /app +COPY --from=frontend /app /app +# The lock was resolved for the app's own platform; the composer image does not +# carry Nextcloud's PHP extensions, so platform checks are left to Nextcloud. +RUN composer install --no-dev --no-interaction --no-progress \ + --optimize-autoloader --classmap-authoritative --ignore-platform-reqs + +# ── Package: the same file set as the release tarball ── +FROM alpine:3.20 AS package +ARG APP_ID +# hadolint ignore=DL3018 +RUN apk add --no-cache rsync +COPY --from=vendor /app /app +RUN mkdir -p "/out/${APP_ID}" && rsync -a \ + --exclude='/.git*' --exclude='/.github' --exclude='/.claude' \ + --exclude='/.hydra' --exclude='/.vscode' --exclude='/.nextcloud' \ + --exclude='/docker' --exclude='/charts' \ + --exclude='/Dockerfile' --exclude='/.dockerignore' \ + --exclude='/docker-compose*.yml' --exclude='/*-compose.yaml' \ + --exclude='/docs' --exclude='/docusaurus' --exclude='/website' \ + --exclude='/node_modules' \ + --include='/src/' --include='/src/manifest.json' --exclude='/src/*' \ + --exclude='/tests' --exclude='/test-scenarios' --exclude='/openspec' \ + --exclude='/data' --exclude='/resources' --exclude='/phpcs-custom-sniffs' \ + --exclude='/package*.json' --exclude='/composer.*' \ + --exclude='/*.config.js' --exclude='/*.config.mjs' --exclude='/*.config.ts' \ + --exclude='/php*.xml' --exclude='/psalm.xml' --exclude='/phpstan*' \ + --exclude='/sbom.cdx.json' --exclude='/.phpunit*' \ + /app/ "/out/${APP_ID}/" + +# ── OpenRegister: the newest stable release, checked against its SHA-256 ── +FROM alpine:3.20 AS openregister +ARG APP_ID +# Empty means the newest stable release at build time. Prereleases are refused. +# Pin it for a reproducible build: --build-arg OPENREGISTER_VERSION=2.1.0 +ARG OPENREGISTER_VERSION= +SHELL ["/bin/ash", "-euo", "pipefail", "-c"] +# hadolint ignore=DL3018 +RUN apk add --no-cache curl jq tar +RUN mkdir -p /out; \ + if [ "${APP_ID}" = "openregister" ]; then exit 0; fi; \ + version="${OPENREGISTER_VERSION#v}"; \ + if [ -z "$version" ]; then \ + version="$(curl -fsSL https://api.github.com/repos/ConductionNL/openregister/releases/latest \ + | jq -r '.tag_name' | sed 's/^v//')"; \ + fi; \ + case "$version" in \ + ''|*-*) echo "OpenRegister '$version' is not a stable release" >&2; exit 1 ;; \ + esac; \ + base="https://github.com/ConductionNL/openregister/releases/download/v${version}/openregister-${version}.tar.gz"; \ + curl -fsSL -o /tmp/or.tar.gz "$base"; \ + sha="$(curl -fsSL "${base}.sha256" | cut -d' ' -f1)"; \ + echo "${sha} /tmp/or.tar.gz" | sha256sum -c -; \ + mkdir /tmp/stage && tar -xzf /tmp/or.tar.gz -C /tmp/stage; \ + mv "$(find /tmp/stage -mindepth 1 -maxdepth 1 -type d | head -n 1)" /out/openregister; \ + printf '%s sha256:%s\n' "$version" "$sha" > /out/openregister/.image-release + +# ── Runtime ── +# hadolint ignore=DL3006 +FROM ${NEXTCLOUD_IMAGE} +ARG APP_ID +LABEL org.opencontainers.image.title="${APP_ID}" \ + org.opencontainers.image.description="Nextcloud with ${APP_ID} and OpenRegister, for evaluation" \ + org.opencontainers.image.source="https://github.com/ConductionNL/${APP_ID}" \ + org.opencontainers.image.vendor="Conduction B.V." +# The entrypoint copies these into the custom_apps volume on first start; the +# before-starting hook keeps that copy in step with the image afterwards. +COPY --from=openregister --chown=www-data:www-data /out/ /usr/src/nextcloud/custom_apps/ +COPY --from=package --chown=www-data:www-data /out/ /usr/src/nextcloud/custom_apps/ +COPY --chmod=0755 docker/entrypoint-hooks/before-starting/ /docker-entrypoint-hooks.d/before-starting/ +# Enabled in this order: OpenRegister owns the registers the app declares into. +ENV NEXTCLOUD_IMAGE_APPS="openregister ${APP_ID}" +# Apache starts as root to bind port 80 and serves every request as www-data; +# the entrypoint and its hooks run occ as www-data too. diff --git a/templates/app-deploy/README-section.md b/templates/app-deploy/README-section.md new file mode 100644 index 00000000..49de9854 --- /dev/null +++ b/templates/app-deploy/README-section.md @@ -0,0 +1,22 @@ +### Try it with Docker + +The repository builds an evaluation image: the official Nextcloud image with __APP_ID__ and OpenRegister installed and enabled. It is meant for trying the app out and for test environments. For production, install the app from the Nextcloud App Store. + +```bash +docker compose -f __COMPOSE_FILE__ up -d --build +``` + +Open http://localhost:8080/apps/__APP_ID__/ and sign in as `admin` with password `admin`. The first start takes a minute or two. Set `NEXTCLOUD_ADMIN_PASSWORD` and `APP_PORT` to change the password and the port; `__COMPOSE_FILE__` lists every setting. `docker compose -f __COMPOSE_FILE__ down -v` removes the stack and its data. + +Released versions are published as `ghcr.io/conductionnl/__APP_ID__`, so leaving out `--build` uses the published image. + +### Run it on Kubernetes + +`charts/__APP_ID__` wraps the official [Nextcloud Helm chart](https://github.com/nextcloud/helm) and runs the same image with PostgreSQL: + +```bash +helm dependency build charts/__APP_ID__ +helm install __APP_ID__ charts/__APP_ID__ --set nextcloud.nextcloud.host=__APP_ID__.example.org +``` + +Change the passwords in `charts/__APP_ID__/values.yaml` before you install it anywhere that matters. diff --git a/templates/app-deploy/README.md b/templates/app-deploy/README.md new file mode 100644 index 00000000..765d1de8 --- /dev/null +++ b/templates/app-deploy/README.md @@ -0,0 +1,37 @@ +# App deployment template + +One set of deployment artefacts for every Conduction Nextcloud app, parameterised by the app id only: + +| File in the app | What it is | +|---|---| +| `Dockerfile` | Evaluation image: the official Nextcloud image (pinned) with the app built from the repository and OpenRegister from its release, checked against the release SHA-256. Nothing secret is baked in. | +| `.dockerignore` | Keeps local `node_modules` and `vendor` out of the build. | +| `docker/entrypoint-hooks/before-starting/10-image-apps.sh` | Entrypoint hook: on every start, copies a newer baked app over the persistent copy, runs `occ upgrade` when needed and enables OpenRegister and the app. | +| `docker-compose.yml` | Nextcloud from that image, PostgreSQL and Redis, with every setting documented in the file. Written to `docker/docker-compose.yml` instead when the app already has a root `docker-compose.yml`, which is then left alone. | +| `charts//` | Helm chart over the official [Nextcloud chart](https://github.com/nextcloud/helm), running the same image with PostgreSQL. | +| `.github/workflows/container-image.yml` | Builds and pushes `ghcr.io/conductionnl/` for every release, a stable release as its version and `latest`, a beta or unstable release as `edge`. | + +The image is for trying an app out and for test environments. Production installs still come from the Nextcloud App Store, and production Kubernetes runs one Nextcloud with many apps rather than a chart per app. + +## Rendering + +```bash +templates/app-deploy/render.sh +``` + +The script checks the id against `appinfo/info.xml`, writes the files above and prints a README section for the app. It only overwrites files it wrote before, so running it again brings an app up to the current template. Change the template here, then render it into the apps; do not edit the copies. + +## Checking a render + +```bash +docker build -t ghcr.io/conductionnl/:test . +docker compose -f docker-compose.yml config -q +helm dependency build charts/ && helm lint charts/ && helm template t charts/ +``` + +## Choices + +- **Nextcloud 33.** The newest image that still ships PHP 8.3; the 34 and 35 images ship PHP 8.5, which not every app supports yet. Every fleet app supports 32 to 34 or later. +- **OpenRegister version.** The newest stable release at build time, never a prerelease, checked against its published SHA-256. Pass `--build-arg OPENREGISTER_VERSION=` to pin it; the baked version and hash are written to `custom_apps/openregister/.image-release`. +- **Root.** Apache starts as root to bind port 80 and serves every request as `www-data`; the entrypoint and the hook run `occ` as `www-data`. +- **Image visibility.** A new GHCR package is private until an organisation owner makes it public. diff --git a/templates/app-deploy/charts/__APP_ID__/.gitignore b/templates/app-deploy/charts/__APP_ID__/.gitignore new file mode 100644 index 00000000..93b4d6e1 --- /dev/null +++ b/templates/app-deploy/charts/__APP_ID__/.gitignore @@ -0,0 +1,2 @@ +# Fetched by `helm dependency build`; Chart.lock pins the version. +charts/ diff --git a/templates/app-deploy/charts/__APP_ID__/.helmignore b/templates/app-deploy/charts/__APP_ID__/.helmignore new file mode 100644 index 00000000..19965bae --- /dev/null +++ b/templates/app-deploy/charts/__APP_ID__/.helmignore @@ -0,0 +1,5 @@ +.DS_Store +.git/ +*.tgz.prov +*.orig +*.swp diff --git a/templates/app-deploy/charts/__APP_ID__/Chart.yaml b/templates/app-deploy/charts/__APP_ID__/Chart.yaml new file mode 100644 index 00000000..7129048e --- /dev/null +++ b/templates/app-deploy/charts/__APP_ID__/Chart.yaml @@ -0,0 +1,18 @@ +# Rendered from ConductionNL/.github templates/app-deploy. +apiVersion: v2 +name: __APP_ID__ +description: Nextcloud with __APP_ID__ and OpenRegister, on the official Nextcloud chart. For evaluation and test environments. +type: application +version: 0.1.0 +appVersion: "latest" +home: https://github.com/ConductionNL/__APP_ID__ +sources: + - https://github.com/ConductionNL/__APP_ID__ + - https://github.com/nextcloud/helm +maintainers: + - name: Conduction B.V. + email: info@conduction.nl +dependencies: + - name: nextcloud + version: 9.4.1 + repository: https://nextcloud.github.io/helm/ diff --git a/templates/app-deploy/charts/__APP_ID__/templates/NOTES.txt b/templates/app-deploy/charts/__APP_ID__/templates/NOTES.txt new file mode 100644 index 00000000..6e9a3e16 --- /dev/null +++ b/templates/app-deploy/charts/__APP_ID__/templates/NOTES.txt @@ -0,0 +1,10 @@ +{{- /* Rendered from ConductionNL/.github templates/app-deploy. */ -}} +__APP_ID__ is starting on Nextcloud (image {{ .Values.nextcloud.image.registry }}/{{ .Values.nextcloud.image.repository }}:{{ .Values.nextcloud.image.tag }}). + +The first start installs Nextcloud and enables OpenRegister and __APP_ID__, +which takes a few minutes. Follow it with: + + kubectl logs -f -n {{ .Release.Namespace }} deploy/{{ .Release.Name }}-nextcloud + +Then open https://{{ .Values.nextcloud.nextcloud.host }}/apps/__APP_ID__/ and sign in as +{{ .Values.nextcloud.nextcloud.username }}. diff --git a/templates/app-deploy/charts/__APP_ID__/values.yaml b/templates/app-deploy/charts/__APP_ID__/values.yaml new file mode 100644 index 00000000..cb19badb --- /dev/null +++ b/templates/app-deploy/charts/__APP_ID__/values.yaml @@ -0,0 +1,53 @@ +# Values for the __APP_ID__ evaluation chart. Everything under `nextcloud:` is +# passed to the official Nextcloud chart; see +# https://github.com/nextcloud/helm/tree/main/charts/nextcloud for all options. +# +# The image is ghcr.io/conductionnl/__APP_ID__: the official Nextcloud image +# with __APP_ID__ and OpenRegister baked in. Its before-starting hook enables +# both apps, so no hook or app list is needed here. +# +# helm dependency build charts/__APP_ID__ +# helm install __APP_ID__ charts/__APP_ID__ \ +# --set nextcloud.nextcloud.host=__APP_ID__.example.org \ +# --set nextcloud.nextcloud.password= \ +# --set nextcloud.postgresql.global.postgresql.auth.password= +# +# Rendered from ConductionNL/.github templates/app-deploy. + +nextcloud: + image: + registry: ghcr.io + repository: conductionnl/__APP_ID__ + # Pin a released version for anything you want to keep. + tag: latest + pullPolicy: IfNotPresent + + nextcloud: + host: __APP_ID__.local + username: admin + # Set your own, or point existingSecret at a Secret you manage. + password: changeme + + # OpenRegister needs a real database; SQLite is not supported. + internalDatabase: + enabled: false + externalDatabase: + enabled: true + type: postgresql + user: nextcloud + database: nextcloud + postgresql: + enabled: true + global: + postgresql: + auth: + username: nextcloud + password: changeme + database: nextcloud + primary: + persistence: + enabled: true + + persistence: + enabled: true + size: 8Gi diff --git a/templates/app-deploy/docker-compose.yml b/templates/app-deploy/docker-compose.yml new file mode 100644 index 00000000..66ab285d --- /dev/null +++ b/templates/app-deploy/docker-compose.yml @@ -0,0 +1,93 @@ +# Evaluation stack for __APP_ID__: Nextcloud with __APP_ID__ and OpenRegister, +# PostgreSQL and Redis. +# +# docker compose -f __COMPOSE_FILE__ up -d --build +# +# Then open http://localhost:8080/apps/__APP_ID__/ and sign in as admin. The +# first start installs Nextcloud and enables the apps, which takes a minute or +# two; `docker compose -f __COMPOSE_FILE__ logs -f nextcloud` shows progress. +# Remove the stack and its data with `docker compose -f __COMPOSE_FILE__ down -v`. +# +# Without --build, Compose uses the published ghcr.io/conductionnl/__APP_ID__ +# image. This is for trying the app out; production installs come from the +# Nextcloud App Store. +# +# Settings, all optional (environment or a .env file next to this file): +# APP_PORT host port, default 8080, bound to 127.0.0.1 only +# APP_IMAGE_TAG image tag, default latest +# NEXTCLOUD_ADMIN_USER first admin account, default admin +# NEXTCLOUD_ADMIN_PASSWORD its password, default admin; set your own +# POSTGRES_PASSWORD database password, default nextcloud +# OPENREGISTER_VERSION OpenRegister release baked in by --build, +# default the newest +# +# Rendered from ConductionNL/.github templates/app-deploy. +# +# SPDX-FileCopyrightText: 2026 Conduction B.V. +# SPDX-License-Identifier: EUPL-1.2 + +name: __APP_ID__-eval + +services: + nextcloud: + image: ghcr.io/conductionnl/__APP_ID__:${APP_IMAGE_TAG:-latest} + build: + context: __BUILD_CONTEXT__ + args: + OPENREGISTER_VERSION: ${OPENREGISTER_VERSION:-} + restart: unless-stopped + ports: + - "127.0.0.1:${APP_PORT:-8080}:80" + depends_on: + db: + condition: service_healthy + redis: + condition: service_healthy + environment: + POSTGRES_HOST: db + POSTGRES_DB: nextcloud + POSTGRES_USER: nextcloud + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nextcloud} + REDIS_HOST: redis + NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER:-admin} + NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD:-admin} + # Nextcloud refuses a Host header it does not trust, and the port is part + # of the host. + NEXTCLOUD_TRUSTED_DOMAINS: "localhost localhost:${APP_PORT:-8080} 127.0.0.1 127.0.0.1:${APP_PORT:-8080}" + OVERWRITECLIURL: "http://localhost:${APP_PORT:-8080}" + volumes: + - nextcloud:/var/www/html + healthcheck: + test: ["CMD-SHELL", "curl -fsS http://localhost/status.php | grep -q '\"installed\":true'"] + interval: 15s + timeout: 5s + start_period: 5m + retries: 10 + + db: + image: postgres:16-alpine + restart: unless-stopped + environment: + POSTGRES_DB: nextcloud + POSTGRES_USER: nextcloud + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nextcloud} + volumes: + - db:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U nextcloud -d nextcloud"] + interval: 5s + timeout: 3s + retries: 20 + + redis: + image: redis:7-alpine + restart: unless-stopped + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 3s + retries: 20 + +volumes: + nextcloud: + db: diff --git a/templates/app-deploy/docker/entrypoint-hooks/before-starting/10-image-apps.sh b/templates/app-deploy/docker/entrypoint-hooks/before-starting/10-image-apps.sh new file mode 100755 index 00000000..d11b5d0a --- /dev/null +++ b/templates/app-deploy/docker/entrypoint-hooks/before-starting/10-image-apps.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# +# Runs as www-data on every container start, after Nextcloud is installed or +# upgraded. Brings the apps baked into the image into the persistent +# custom_apps directory and enables them, in the order NEXTCLOUD_IMAGE_APPS +# lists them. Rendered from ConductionNL/.github templates/app-deploy. +# +# The official entrypoint copies custom_apps from the image only into an empty +# volume, so without this a newer image would keep running the old app code. +# +# SPDX-FileCopyrightText: 2026 Conduction B.V. +# SPDX-License-Identifier: EUPL-1.2 + +set -eu + +baked=/usr/src/nextcloud/custom_apps +live=/var/www/html/custom_apps +occ="php /var/www/html/occ" + +version_of() { + [ -f "$1/appinfo/info.xml" ] || return 0 + sed -n 's:.*\(.*\).*:\1:p' "$1/appinfo/info.xml" | head -n 1 +} + +if ! $occ status --output=json | grep -q '"installed":true'; then + echo "==> Nextcloud is not installed yet, leaving the image apps alone" + exit 0 +fi + +synced=false +for app in ${NEXTCLOUD_IMAGE_APPS:-}; do + [ -d "$baked/$app" ] || continue + from="$(version_of "$baked/$app")" + to="$(version_of "$live/$app")" + if [ "$from" != "$to" ]; then + echo "==> $app: ${to:-absent} -> $from" + rsync -rlD --delete "$baked/$app/" "$live/$app/" + synced=true + fi +done + +if [ "$synced" = true ] && $occ status --output=json | grep -q '"needsDbUpgrade":true'; then + $occ upgrade +fi + +enabled="$($occ app:list --enabled)" +for app in ${NEXTCLOUD_IMAGE_APPS:-}; do + if printf '%s\n' "$enabled" | grep -q "^ - $app:"; then + continue + fi + echo "==> enabling $app" + $occ app:enable "$app" + enabled="$(printf '%s\n - %s:' "$enabled" "$app")" +done diff --git a/templates/app-deploy/render.sh b/templates/app-deploy/render.sh new file mode 100755 index 00000000..088f83ef --- /dev/null +++ b/templates/app-deploy/render.sh @@ -0,0 +1,71 @@ +#!/bin/sh +# +# Renders the deployment artefacts into an app repository: +# +# templates/app-deploy/render.sh +# +# Writes the root Dockerfile and .dockerignore, the image's entrypoint hook, +# an evaluation docker-compose.yml, the Helm chart charts// and the +# image workflow. The compose file goes to the repository root, or to +# docker/docker-compose.yml when the root already has a docker-compose.yml of +# its own (usually the developer stack, which is left untouched). +# +# A file is only overwritten when it came from this template, so running it +# again updates an app to the current template. Prints the README section to +# add by hand. +# +# SPDX-FileCopyrightText: 2026 Conduction B.V. +# SPDX-License-Identifier: EUPL-1.2 + +set -eu + +[ $# -eq 2 ] || { echo "usage: $0 " >&2; exit 2; } +app="$1" +repo="$2" +here="$(cd "$(dirname "$0")" && pwd)" +marker="templates/app-deploy" + +case "$app" in + *[!a-z0-9_]*|'') echo "!! '$app' is not a Nextcloud app id" >&2; exit 2 ;; +esac + +declared="$(sed -n 's:.*\([a-z0-9_]*\).*:\1:p' "$repo/appinfo/info.xml" | head -n 1)" +[ "$declared" = "$app" ] || { echo "!! $repo/appinfo/info.xml declares '$declared', not '$app'" >&2; exit 1; } + +compose=docker-compose.yml +context=. +if [ -f "$repo/docker-compose.yml" ] && ! grep -q "$marker" "$repo/docker-compose.yml"; then + compose=docker/docker-compose.yml + context=.. +fi + +render() { + src="$here/$1" + dst="$repo/$2" + if [ -e "$dst" ] && ! grep -q "$marker" "$dst"; then + echo "!! $2 exists and did not come from this template; leaving it alone" >&2 + return 1 + fi + mkdir -p "$(dirname "$dst")" + sed -e "s|__APP_ID__|$app|g" \ + -e "s|__COMPOSE_FILE__|$compose|g" \ + -e "s|__BUILD_CONTEXT__|$context|g" \ + "$src" > "$dst" + echo " $2" +} + +echo "==> rendering $app into $repo" +render Dockerfile Dockerfile +render .dockerignore .dockerignore +render docker/entrypoint-hooks/before-starting/10-image-apps.sh docker/entrypoint-hooks/before-starting/10-image-apps.sh +chmod 0755 "$repo/docker/entrypoint-hooks/before-starting/10-image-apps.sh" +render docker-compose.yml "$compose" +render "charts/__APP_ID__/Chart.yaml" "charts/$app/Chart.yaml" +render "charts/__APP_ID__/values.yaml" "charts/$app/values.yaml" +render "charts/__APP_ID__/templates/NOTES.txt" "charts/$app/templates/NOTES.txt" +cp "$here/charts/__APP_ID__/.helmignore" "$repo/charts/$app/.helmignore" +cp "$here/charts/__APP_ID__/.gitignore" "$repo/charts/$app/.gitignore" +render workflows/container-image.yml .github/workflows/container-image.yml + +echo "==> README section:" +sed -e "s|__APP_ID__|$app|g" -e "s|__COMPOSE_FILE__|$compose|g" "$here/README-section.md" diff --git a/templates/app-deploy/workflows/container-image.yml b/templates/app-deploy/workflows/container-image.yml new file mode 100644 index 00000000..cbf1cae8 --- /dev/null +++ b/templates/app-deploy/workflows/container-image.yml @@ -0,0 +1,89 @@ +name: Container image + +# Builds the evaluation image (root Dockerfile) for a release and pushes it to +# ghcr.io/conductionnl/__APP_ID__. A stable release gets its version and +# `latest`; a beta or unstable release only moves `edge`. +# +# Releases are created by the Release workflow with the workflow token, and a +# release made that way starts no other workflow. So this one follows the +# Release run instead, and builds the newest release it finds. +# +# Rendered from ConductionNL/.github templates/app-deploy. + +on: + workflow_run: + workflows: [Release] + types: [completed] + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: "Release tag to build, for example v1.2.3 (empty: the newest release)" + required: false + type: string + +permissions: + contents: read + packages: write + +concurrency: + group: container-image + cancel-in-progress: false + +jobs: + image: + if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + steps: + - name: Resolve the release + id: release + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + EVENT_TAG: ${{ github.event.release.tag_name }} + INPUT_TAG: ${{ inputs.tag }} + run: | + set -euo pipefail + tag="${EVENT_TAG:-${INPUT_TAG:-}}" + if [ -z "$tag" ]; then + tag="$(gh release list --repo "$REPO" --limit 1 --exclude-drafts --json tagName --jq '.[0].tagName')" + fi + [ -n "$tag" ] || { echo "::error::No release to build."; exit 1; } + version="${tag#v}" + image=ghcr.io/conductionnl/__APP_ID__ + case "$version" in + *-*) tags="$image:edge" ;; + *) tags="$image:$version,$image:latest" ;; + esac + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "tags=$tags" >> "$GITHUB_OUTPUT" + echo "Building $tag as $tags" + + - uses: actions/checkout@v4 + with: + ref: ${{ steps.release.outputs.tag }} + + - name: Record the commit + id: commit + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.release.outputs.tags }} + labels: | + org.opencontainers.image.version=${{ steps.release.outputs.version }} + org.opencontainers.image.revision=${{ steps.commit.outputs.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max From c001fcf6c7741d88c801d583a94dc9cd8a0ad46a Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Fri, 20 Nov 2026 11:41:27 +0100 Subject: [PATCH 2/2] ci(templates): scope packages: write to the app-deploy image job The workflow-level permissions now grant contents: read only; the image job, which pushes to ghcr.io, gets packages: write. Same change as ConductionNL/openregister#10938, so a re-render keeps it. Assisted-by: ClaudeCode:claude-opus-5-5 --- templates/app-deploy/workflows/container-image.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/app-deploy/workflows/container-image.yml b/templates/app-deploy/workflows/container-image.yml index cbf1cae8..c09eb692 100644 --- a/templates/app-deploy/workflows/container-image.yml +++ b/templates/app-deploy/workflows/container-image.yml @@ -25,7 +25,6 @@ on: permissions: contents: read - packages: write concurrency: group: container-image @@ -35,6 +34,9 @@ jobs: image: if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - name: Resolve the release id: release