Skip to content

Add parameterised Nextcloud PHPUnit test image, GHCR publish workflow, and docs - #1

Merged
charabaruk merged 4 commits into
mainfrom
copilot/setup-docker-test-images
Oct 2, 2026
Merged

charabaruk merged 4 commits into
mainfrom
copilot/setup-docker-test-images

Conversation

Copilot AI commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

This repo had no image build, so this PR adds one. It builds ghcr.io/charabaruk/nextcloud-docker-testing:stable24–stable31. Each tag contains the matching nextcloud/server source, tests/bootstrap.php and composer dev dependencies. This lets docker compose run app phpunit --bootstrap tests/bootstrap.php apps/<app>/tests/. work with an app mounted under apps/.

Only a local stable30 build was attempted. It got through the base image, apt packages and the server clone, then failed at composer install because the sandbox blocks GitHub downloads. Nothing else has been built or run, so the first CI run needs to confirm it, including 24–29 and 31.

Dockerfile

  • A single Dockerfile with ARG NEXTCLOUD_VERSION, based on nextcloud:${NEXTCLOUD_VERSION}. It uses the base image's PHP and its bundled extensions, so there is no per-version package branching.
  • Replaces /var/www/html with git clone --depth=1 --branch stableN --recurse-submodules --shallow-submodules.
  • Installs composer from composer:2 if it's missing, then runs composer install with dev dependencies.
  • Newer branches keep PHPUnit in vendor-bin/phpunit. The Dockerfile also installs there if that directory exists, symlinks phpunit into /usr/local/bin, and fails the build if no binary is found.
  • Sets memory_limit=2048M in zz-memory-limit.ini so it overrides the base image's setting.
  • Runs as www-data and moves Apache to port 8080, since a non-root user can't bind port 80.

Entrypoint (setup.sh, cmd.sh)

  • setup.sh runs occ maintenance:install with SQLite if occ status doesn't report installed. The admin defaults to admin/admin and can be set with NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD.
  • It enables every app in apps/ that has appinfo/info.xml and isn't in /opt/bundled-apps.txt. That file is a list of the server's apps captured at build time, so only mounted apps are enabled. It then runs exec "$@".
  • If started as root, it re-runs itself as www-data.
  • cmd.sh is the default CMD and starts Apache in the foreground.
docker compose run app phpunit --bootstrap tests/bootstrap.php apps/customproperties/tests/.

CI (.github/workflows/docker-publish.yml)

  • Triggers: push to main, a weekly schedule, workflow_dispatch, and pull_request. Pull requests build only.
  • Matrix over versions 24–31 with fail-fast: false, buildx, a GHA layer cache per version, and contents: read / packages: write permissions.
  • For each version it builds locally and then smoke-tests the image:
    • phpunit --version.
    • occ status reports installed: true.
    • A trivial test, smoke/SmokeTest.php, runs through tests/bootstrap.php.
  • On non-PR events it pushes stableN and stableN-<short-sha>, reusing the layer cache from the local build.

Docs

  • README.md covers tags, docker run and compose usage matching the consumer contract, how to add a version, and how to make the GHCR package public.
  • LICENSE is MIT and states the code was written from scratch.

Review notes

  • No version is excluded from the matrix.
  • Action versions (checkout@v4, setup-buildx@v3, login@v3, build-push@v6) should be checked against the latest majors.
Original prompt

Set up this repository to build and publish Docker test images for developing and testing Nextcloud apps with PHPUnit. It replaces SteKoe/nextcloud-docker-testing, which is unmaintained and pinned to Nextcloud 26.

Goal

Publish multi-version images to GHCR:
ghcr.io/charabaruk/nextcloud-docker-testing:stable24 ... :stable31
Each stableN tag is based on the official nextcloud:N image (N = 24..31) and contains the matching Nextcloud server source (git branch stableN of https://github.com/nextcloud/server, with submodules) in /var/www/html. It must include the server's tests/ directory, tests/bootstrap.php, and composer dev dependencies (PHPUnit etc.), so that official server tests and app tests can be run.

Consumer contract (must keep working)

The consuming app repo (charabaruk/nextcloud-customproperties) runs:
docker compose run app phpunit --bootstrap tests/bootstrap.php apps/customproperties/tests/.
with its repo mounted at /var/www/html/apps/customproperties, and ~/.nextcloud mounted at /.nextcloud. App tests' bootstrap does require_once "../../tests/bootstrap.php" relative to the app dir. So:

  • phpunit must be on PATH, and the working directory must be /var/www/html.
  • The container must install Nextcloud (SQLite is fine), enable the mounted app, and then execute the given command. The entrypoint should run setup and then exec the command passed as arguments, so that docker compose run app phpunit ... works.
  • The container must run correctly as the existing www-data user, and the setup must handle file permissions for the mounted volume.

Dockerfile

  • A single parameterised Dockerfile with ARG NEXTCLOUD_VERSION. It starts from nextcloud:${NEXTCLOUD_VERSION}, so check which official tag exists for each version (e.g. nextcloud:24, 25, ... 31), and uses the base image's matching PHP version.
  • Install git, unzip and the PHP extensions needed. Replace /var/www/html with a clone of nextcloud/server at branch stable${NEXTCLOUD_VERSION} (--depth=1, submodules initialised). Run composer install including dev dependencies. Install composer if absent.
  • Set a PHP memory limit of 2048M.
  • Include setup.sh (entrypoint: occ maintenance:install with SQLite, an admin user, enable apps found in /var/www/html/apps, then exec "$@") and cmd.sh as the default CMD (start Apache). Make them idempotent.
  • Keep it working for older versions (24-27) as well as newer ones (28-31); adjust package/PHP handling per version as necessary rather than dropping versions. If a version genuinely cannot be built, document why in the README and exclude it from the matrix explicitly rather than failing silently.

GitHub Actions (.github/workflows/docker-publish.yml)

  • Triggers: push to main, a weekly schedule, workflow_dispatch, and pull_request (build only, no push).
  • Matrix over versions 24..31 with fail-fast: false. Use docker/setup-buildx-action, docker/login-action (ghcr.io, GITHUB_TOKEN), docker/build-push-action with the NEXTCLOUD_VERSION build-arg, and GHA layer cache. Permissions: contents: read, packages: write. Pin the actions to current major versions.
  • Tag each image stableN, and also push it with a short-SHA tag. Don't push on pull_request.
  • After building, run a smoke test in CI for each version: start the image and verify phpunit --version works and that occ status reports installed, and run a trivial PHPUnit test through tests/bootstrap.php.

Docs

  • README covering: purpose, available tags, local usage (docker run and a docker-compose example matching the consumer contract above), how to add a new Nextcloud version (extend the matrix), and how to make the GHCR package public so other repos' CI can pull it without extra auth.
  • Add a LICENSE (AGPL-3.0 or MIT, your choice, noting that the code is derived from nothing in SteKoe's repo or is rewritten from scratch).

Acceptance criteria

  • The workflow builds all eight tags successfully on the main branch, or each exclusion is documented with reasons.
  • docker run --rm ghcr.io/charabaruk/nextcloud-docker-testing:stable30 phpunit --version works.
  • Mounting an app into /var/www/html/apps/ and running phpunit --bootstrap tests/bootstrap.php apps/<app>/tests/. runs that app's tests.

Co-authored-by: charabaruk <130681+charabaruk@users.noreply.github.com>
Copilot AI changed the title [WIP] Set up Docker test images for Nextcloud apps Add parameterised Nextcloud PHPUnit test image, GHCR publish workflow, and docs Oct 2, 2026
Copilot AI requested a review from charabaruk October 2, 2026 17:04
Comment thread LICENSE Outdated
@@ -0,0 +1,23 @@
MIT License

Copyright (c) 2026 charabaruk

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full name should be used, not GitHub user name: "Chris Charabaruk"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to "Chris Charabaruk" in LICENSE.

@charabaruk

Copy link
Copy Markdown
Owner

@copilot resolve failures for versions 24 through 27 and address review comments.

…full name in LICENSE

Co-authored-by: charabaruk <130681+charabaruk@users.noreply.github.com>
…uite

Co-authored-by: charabaruk <130681+charabaruk@users.noreply.github.com>
@charabaruk
charabaruk marked this pull request as ready for review October 2, 2026 17:41
@charabaruk
charabaruk merged commit 4c38872 into main Oct 2, 2026
8 checks passed
@charabaruk
charabaruk deleted the copilot/setup-docker-test-images branch October 2, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants