Repository navigation
ENH Improve DB service handling and ensure composer cache gets used - #192
Conversation
There was a problem hiding this comment.
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)
|
Have now run in campaign admin
Compare with a typical run without this PR e.g. https://github.com/silverstripe/silverstripe-campaign-admin/actions/runs/43673523154 - 7m 39s |
emteknetnz
left a comment
There was a problem hiding this comment.
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
servicesfor everydbvalue, includingmysql57pdoon 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 pingreturns 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 logsin "Copy artifacts" works on failed runs, because that step hasif: always().
Worth checking or changing:
- Unknown
dbvalues now fail the job. "Final preparation" matches with=~ mysql, so before this change something likedb: mysqlinextra_jobsquietly 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. - 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 adb, they pull and start a container they never use, and "Wait for database" holds them until it's ready. Addingif: 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. - 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 staysstarting. 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. --health-start-intervalneeds 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.- The image download is still on the critical path.
docker pullruns 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. - 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 thedocker psfilter.
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 throughrestore-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_argsisn't set,contains()returns false and the key falls back tohighest. That's correct.
Worth checking:
- 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 thepostgresql/sqlite3packages that those jobs need. They'll still get most packages from the cache, so this is a reasonable trade-off. Addingmatrix.endtoendto the key would fix the largest gap, but it doubles the number of entries. - 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. - 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_setupcheck (point 2). - Reword the comment about the health status (point 3).
- Confirm that gha-generate-matrix validates
dbvalues (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.
|
Well that's an AI review if I ever saw one 😅 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. |
00825dd to
3cc56c0
Compare
|
For point 1, generate matrix does not validate the db. Sounds like you don't want it to so I'll leave that alone.
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.
3cc56c0 to
6ecd93a
Compare
2 changes here:
Issue