This has happened to me so many times, I'm writing a blog post just to vent about it.
Today, BLOG FROG's CI failed after I pushed an update. However, it wasn't due to the new code I pushed. To explain what happened, I'll have to give a brief background.
The first step in BLOG FROG's CI is to build its docker image. BLOG FROG's Dockerfile does this in two steps:
- Using the Composer 2.4 docker image, install dependencies.
- Build BLOG FROG's image from the PHP 8.1 with Apache image, copying dependencies from the previous step.
The CI was failing on the first of these steps: installing dependencies with Composer 2.4. Looking more closely, one of the dependencies was giving this error:
nette/schema v1.2.2 requires php >=7.1 <8.2 -> your php version (8.2.4) does not satisfy that requirement.
Apparently, at some point, the composer:2.4
image updated to use PHP version 8.2 instead of 8.1, and this was causing a problem with my dependencies. Looking at the Dockerfile for composer:2.4
confirmed that it's built off of php:8-alpine
, which must have updated its version in the time between now and the last BLOG FROG update.
This is not the first time I've had CI fail because of a base docker image changing software versions from under my feet. It's one of the gripes I have with docker, or more technically, how docker is used. It's for this reason that I think building your images off of :latest
is an antipattern; if you do so, you risk things breaking when the version updates unexpectedly. This is why I try to pin my docker images to specific versions.
However, in this case, pinning to a specific Composer version still introduced the same bug. My error was not pinning to the specific PHP version I needed. I should have realized that the Composer image would be pinned to PHP latest.
To fix the issue, I copied the composer:2.4
Dockerfile contents into my build step and changed the first line so that it builds from php8.1-alpine
specifically. This fixed the issue and should hopefully prevent any more unexpected version mismatches moving forward.