Skip to content

ENH Improve DB service handling and ensure composer cache gets used - #192

Merged
emteknetnz merged 1 commit into
silverstripe:3from
creative-commoners:pulls/3/performance
Nov 18, 2026
Merged

emteknetnz merged 1 commit into
silverstripe:3from
creative-commoners:pulls/3/performance

Conversation

@ChloeSartorelli

@ChloeSartorelli ChloeSartorelli commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

2 changes here:

  1. Currently we install services for ALL databases we test against, even if they're not used in the tests. We also wait for all of the healthchecks before moving on. This commit sets up only the database that's used for the tests (if any) and lets healthchecks run in parallel to the rest of the setup.
  2. Using the same cache name means we never actually save into the cache after it's created, which means we're always downloading almost every package since the cached copy is stale. This commit updates the cache key to include a hash of the composer.json file and the current week, so new cache any time composer.json changes and once a week to prevent stale caches. When we build a new cache it starts from the previous cache, so we're only downloading packages that have changed since that cache was saved.

Issue

@ChloeSartorelli ChloeSartorelli mentioned this pull request Nov 16, 2026

@emteknetnz emteknetnz left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You'll need to validate this actually works in on either a on either creative-commoners or your personal github account using a fork of say silverstripe/campaign-admin (which includes behats) and update it's ci,yml to point at the creative-commers fork of ghi-ci and this branch. Should be able to work out pretty quick if a) it works b) it's not slower (it's unlikely but might be slower since it's dynamically pulling docker images)

@ChloeSartorelli

Copy link
Copy Markdown
Member Author

Have now run in campaign admin

  • attempt 1 - no cache hit for composer because it's a new key - 6m 20s
  • attempt 2 - cache hit for composer - 6m 2s

Compare with a typical run without this PR e.g. https://github.com/silverstripe/silverstripe-campaign-admin/actions/runs/43673523154 - 7m 39s

@emteknetnz emteknetnz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This review compares the diff against the current .github/workflows/ci.yml. The diff fixes both problems in the issue: each job now starts only the database it uses, and the composer cache gets a key that test jobs actually save to. There are no blocking bugs. There are some things to check, though, and a few possible improvements. The change has not been run in CI yet: none of the run logs in z-gha include it.

Database containers

Correct:

  • The images and host ports match the old services for every db value, including mysql57pdo on 3357, and line up with the ports in "Final preparation".
  • The health checks use TCP on purpose (mysqladmin ping --protocol=tcp, pg_isready --host=127.0.0.1). During startup, the MySQL and Postgres images run a temporary server that only listens on a local socket, so a socket check could pass before the real server is up.
  • mysqladmin ping returns 0 even when the login is refused, so leaving out the password is fine.
  • {{.State.Health.Status}} isn't ${{ }}, so GitHub won't try to fill it in.
  • docker ps --filter name=^database$ matches on the name without the leading /, so it finds the container.
  • Saving docker logs in "Copy artifacts" works on failed runs, because that step has if: always().

Worth checking or changing:

  1. Unknown db values now fail the job. "Final preparation" matches with =~ mysql, so before this change something like db: mysql in extra_jobs quietly fell back to MySQL 5.7 on 3357. Now "Start database" exits 1 with "Unknown database". That's probably better behaviour, but check whether gha-generate-matrix (PR #134) already rejects unknown values, and say in the PR that this is now strict.
  2. Jobs that don't need a database may still start one. "Final preparation" skips all database setup when matrix.needs_full_setup == 'false' (linting and JS jobs). If the matrix still gives those jobs a db, they pull and start a container they never use, and "Wait for database" holds them until it's ready. Adding if: matrix.needs_full_setup != 'false' to both steps (or the same check in the shell) would avoid that. It's no worse than today, but it's an easy extra saving.
  3. The comment in "Wait for database" doesn't match how the health check works. It says the status "can be unhealthy while the database initialises". With --health-start-period=180s, failed checks during that period don't count, so the status stays starting. Once the period ends, the default of 3 retries applies (the old services used --health-retries=10). The loop handles every case either way, but the comment should be reworded.
  4. --health-start-interval needs Docker Engine 25 or later. GitHub's runners have Docker 28, so this is fine there. It would fail with "unknown flag" on an older self-hosted runner.
  5. The image download is still on the critical path. docker pull runs before "Install PHP" and finishes before the next step starts; only the database startup overlaps with later steps. It's still a big saving over pulling five images, so this is fine as is. Pulling in the background would save a few more seconds but makes the error handling more complicated, so it's best left as is.
  6. Simpler existence check (optional). "Wait for database" and "Copy artifacts" could use docker inspect database >/dev/null 2>&1, or a step output from "Start database", instead of the docker ps filter.

Composer cache

Correct:

  • The new key never matches shared-composer-cache, so the small cache that the matrix job saves is no longer picked up.
  • Changing the key every ISO week (%G-%V) works around GitHub never overwriting an existing cache entry. Each week's first run restores last week's cache through restore-keys.
  • hashFiles('composer.json') is calculated before the Composer step edits the file, so every job in a run gets the same key.
  • If matrix.composer_args isn't set, contains() returns false and the key falls back to highest. That's correct.

Worth checking:

  1. Jobs that need different packages share one key. Within a run, every job with the same PHP version and lowest/highest setting has the same key. The first one to finish saves the cache; the others get a "cache already exists" warning and don't save. If a plain phpunit job finishes first, that week's cache won't have the recipe-testing/behat packages that endtoend jobs need, or the postgresql/sqlite3 packages that those jobs need. They'll still get most packages from the cache, so this is a reasonable trade-off. Adding matrix.endtoend to the key would fix the largest gap, but it doubles the number of entries.
  2. The cache could outgrow GitHub's limit. Because silverstripe/* and similar packages are installed from source, Composer keeps a git copy of each one, and nothing caps the size of those copies. Entries for recipes like kitchen-sink could be hundreds of MB. Multiplied by PHP versions × lowest/highest × branches × weeks, they could exceed the 10 GB per-repo limit and push each other out. After a couple of weeks of runs on a large recipe, check the entry sizes in the repo's Actions → Caches page.
  3. The comment doesn't say why gha-generate-matrix uses that key. "gha-generate-matrix saves a small cache with that key" is accurate, but a short note on why (gha-generate-matrix runs Composer itself) would save the next reader from hunting for it.

Suggested before merging

  • Add the needs_full_setup check (point 2).
  • Reword the comment about the health status (point 3).
  • Confirm that gha-generate-matrix validates db values (point 1).
  • Run it on one repo per database (mysql57pdo, mysql80, mysql84, pgsql, mariadb, sqlite3) and on an endtoend job. Then check the "Start database" and "Wait for database" timings, and that the second run gets a cache hit.

@ChloeSartorelli

ChloeSartorelli commented Nov 17, 2026 •

Copy link
Copy Markdown
Member Author

Well that's an AI review if I ever saw one 😅
I'm gonna assume the "Suggested before merging" is the stuff you want me to change.

Ideally in future please don't just copy paste the AI review and instead give me a clear indication of what you want me to actually do.

@ChloeSartorelli

ChloeSartorelli commented Nov 17, 2026 •

Copy link
Copy Markdown
Member Author

For point 1, generate matrix does not validate the db. Sounds like you don't want it to so I'll leave that alone.

Run it on one repo per database (mysql57pdo, mysql80, mysql84, pgsql, mariadb, sqlite3) and on an endtoend job. Then check the "Start database" and "Wait for database" timings, and that the second run gets a cache hit.

I feel like that's just a AI suggestion and not a Steve suggestion since that's a lot more strict than you'd usually request for a fairly straight forward CI change like this.

I've made the first two changes. I ran that in CI - see https://github.com/creative-commoners/silverstripe-campaign-admin/actions/runs/43978511573/attempts/3 and saw that the JS and phplinting jobs still set up a DB so point 2 wasn't quite right.

I've updated the checks so that only phpunit, behat, and code coverage jobs include DBs. That ran on https://github.com/creative-commoners/silverstripe-campaign-admin/actions/runs/43978511573/attempts/4

- Only set up DB that is used and run healthcheck in parallel
- Skip DB setup for jobs that don't use it
- Use rolling cache key for composer to avoid stale cache

The cache doesn't get updated if the key already exists, so it needs to
be updated if composer.json changes, plus periodically so new versions
of packages don't need to ge re-downloaded.
@emteknetnz
emteknetnz merged commit 57b6888 into silverstripe:3 Nov 18, 2026
2 checks passed
@emteknetnz
emteknetnz deleted the pulls/3/performance branch November 18, 2026 05:23
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