diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e2bba5c72..0c51c61bf 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -687,11 +687,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/base-app:ubuntu-22.04 REFERENCE=ghcr.io/webdevops/base-app:sha-${{ github.sha }}-${{ matrix.arch }}-ubuntu-22.04' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/base-app:sha-${{ github.sha }}-${{ matrix.arch }}-ubuntu-22.04 --config base-app/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -865,11 +860,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/base:ubuntu-22.04 REFERENCE=ghcr.io/webdevops/base:sha-${{ github.sha }}-${{ matrix.arch }}-ubuntu-22.04' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/base:sha-${{ github.sha }}-${{ matrix.arch }}-ubuntu-22.04 --config base/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -1043,11 +1033,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/bootstrap:ubuntu-22.04 REFERENCE=ghcr.io/webdevops/bootstrap:sha-${{ github.sha }}-${{ matrix.arch }}-ubuntu-22.04' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/bootstrap:sha-${{ github.sha }}-${{ matrix.arch }}-ubuntu-22.04 --config bootstrap/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -4526,11 +4511,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.2 REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.2' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.2 --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -4640,11 +4620,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.2-alpine REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.2-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.2-alpine --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -4826,11 +4801,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.3 REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.3' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.3 --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -4940,11 +4910,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.3-alpine REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.3-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.3-alpine --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -5126,11 +5091,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.4 REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.4' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.4 --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -5240,11 +5200,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.4-alpine REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.4-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.4-alpine --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -5426,11 +5381,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.5 REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.5' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.5 --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -5540,11 +5490,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.5-alpine REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.5-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.5-alpine --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -5726,11 +5671,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.6 REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.6' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.6 --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -5840,11 +5780,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-dev:8.6-alpine REFERENCE=ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.6-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-dev:sha-${{ github.sha }}-${{ matrix.arch }}-8.6-alpine --config php-dev/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -7476,11 +7411,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.2 REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.2' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.2 --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -7616,11 +7546,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.2-alpine REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.2-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.2-alpine --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -7828,11 +7753,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.3 REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.3' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.3 --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -7968,11 +7888,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.3-alpine REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.3-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.3-alpine --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -8180,11 +8095,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.4 REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.4' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.4 --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -8320,11 +8230,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.4-alpine REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.4-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.4-alpine --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -8532,11 +8437,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.5 REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.5' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.5 --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -8672,11 +8572,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.5-alpine REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.5-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.5-alpine --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -8884,11 +8779,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.6 REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.6' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.6 --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -9024,11 +8914,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php-nginx:8.6-alpine REFERENCE=ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.6-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php-nginx:sha-${{ github.sha }}-${{ matrix.arch }}-8.6-alpine --config php-nginx/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -9236,11 +9121,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.2 REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.2' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.2 --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -9376,11 +9256,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.2-alpine REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.2-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.2-alpine --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -9592,11 +9467,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.3 REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.3' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.3 --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -9732,11 +9602,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.3-alpine REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.3-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.3-alpine --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -9948,11 +9813,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.4 REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.4' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.4 --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -10088,11 +9948,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.4-alpine REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.4-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.4-alpine --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -10304,11 +10159,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.5 REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.5' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.5 --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -10444,11 +10294,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.5-alpine REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.5-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.5-alpine --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -10660,11 +10505,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.6 REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.6' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.6 --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' @@ -10800,11 +10640,6 @@ jobs: - name: 'run image tests' run: 'make test-image-run IMAGE=webdevops/php:8.6-alpine REFERENCE=ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.6-alpine' - - - name: 'run structure-test' - run: |- - cd tests/structure-test - /usr/local/bin/container-structure-test test --image ghcr.io/webdevops/php:sha-${{ github.sha }}-${{ matrix.arch }}-8.6-alpine --config php/test.yaml - if: "${{github.ref == 'refs/heads/master'}}" name: 'Login to ghcr.io' diff --git a/AGENTS.md b/AGENTS.md index ac0793b91..87ef74bf5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,7 +16,6 @@ | `conf/dockerhub.yml` | Texts of the Docker Hub pages: per repository the short description, the introduction, the example and the links, or for an image that is no longer built the month of its last build and its replacement (source) | | `docs/dockerhub/.md` | Docker Hub pages, generated by `ci/console generate:dockerhub`, never edited by hand; the job `dockerhub-description` in `.github/workflows/build.yaml` uploads them, see [Building in CI](CONTRIBUTING.md#building-in-ci) | | `ci/image-tests/` | Image tests (PHPUnit): a test class per image in `Images/`, the checks as traits in `Checks/`; `ci/console test:image` runs them against a container of the image | -| `tests/` | container-structure-test definitions run by the CI | | `docs/` | User documentation | `webdevops/php-official` is a deprecated name of `webdevops/php`: the CI publishes the image of `docker/php/` under that name too, but only for the tags listed under `docker: aliases` in `conf/console.yml`. Do not add new tags there. The tags that are built are the `-t "webdevops/..."` lines in `.github/workflows/build.yaml`. @@ -33,7 +32,7 @@ Only these commands are known to work: - In an image test, a file that a service writes as `application` and a command of the test writes as root (`docker exec`) belongs in `/app`, not in `/tmp`. The runners of GitHub Actions set `fs.protected_regular`, under which even root may not open a file of another user in a sticky directory with `O_CREAT`; a Docker host without it, as many local ones, lets such a test pass that then fails in the CI. - `make generate`, `make check` and `make test` run as your user, so the files they write belong to you. Do not write into the checkout as root. -Besides `generate`, `check` and `test`, the Makefile has `structure-test`. `make structure-test` runs container-structure-test against your local images of `bootstrap`, `base`, `base-app`, `php`, `php-dev` and `php-nginx`, the images that have a suite in `tests/structure-test`. It tests only the tags in `.github/workflows/build.yaml` and fails if a test fails, if `docker` fails or if no such image exists locally; run it inside `webdevops/dockerfile-build-env` with the Docker socket mounted. The CI runs the image tests for every image except `toolbox`, and container-structure-test for the six images above; to check a change by hand, start the image and try it as described below. +The CI runs the image tests for every image except `toolbox`; they are the only tests of the images. To check a change by hand, start the image and try it as described below. ### Packages come with tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 39374ea36..20f98d889 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,7 +57,7 @@ It does not update the actions in `.github/workflows/build.yaml`, because that f A new push to a pull request cancels the run of its previous commit. Runs on `master`, the nightly run and runs started by hand are never cancelled. -GitHub Actions builds every image independently and runs the image tests and structure tests +GitHub Actions builds every image independently and runs the image tests defined for it before pushing it to Docker Hub. The CI also uses `ghcr.io/webdevops/`, but only internally; pull the images from Docker Hub. @@ -90,7 +90,7 @@ Build all PHP images of one version (default `8.5`), in the order they depend on Then try an image with the [quick start](README.md#quick-start). -The CI runs the image tests for every image except `toolbox`, and the structure tests for `bootstrap`, `base`, `base-app`, `php`, `php-dev` and `php-nginx`. +The CI runs the image tests for every image except `toolbox`. To run the image tests against an image you built locally: ``` @@ -100,18 +100,11 @@ make test-image IMAGE=webdevops/php-nginx:8.5 `REFERENCE` tests another image with the tests and settings of `IMAGE`, e.g. `REFERENCE=my-php-nginx`. The tests use `/var/run/docker.sock`, in rootless Docker the socket of the current Docker context; set `DOCKER_SOCKET` for another one. -To run the structure tests against the images you built locally: - -``` -docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $PWD:/app -w /app webdevops/dockerfile-build-env make structure-test -``` - -It tests the local tags that the CI builds and fails if no such image exists. - ## Image tests The image tests are PHPUnit tests in `ci/image-tests`. They start a container of the image with its own command, so supervisord starts the services as in production, and check it: files and their owner and mode, commands and their output, PHP extensions and settings, the running services and their ports, and requests through Nginx or Apache to PHP-FPM over http and https. +What the image sets for every container, its environment variables with their defaults, entrypoint, command and exposed ports, they read with `docker image inspect`. Most tests of an image run against one container. Its root directory gets the files of `ci/image-tests/Fixtures` first, so `/app` holds the pages that the requests ask for. The tests of environment variables, commands and hooks start more containers of the image: the environment container, which starts with every variable of `ENVIRONMENT` in `ImageTestCase` set to a value other than its default, containers of their own for variables that would get in the way of other tests, e.g. the process manager of PHP-FPM, which `startTestContainer()` removes after their test, and short runs of one command through the entrypoint, e.g. `root id -un`. They check what a variable does, not only that its value ends up in a configuration file: a request that hits the memory limit, a cron job that runs at the hour of `TZ`, a connection of Xdebug to a listener. diff --git a/Makefile b/Makefile index 7c380142d..5646320e2 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ MAKEFLAGS += --silent -.PHONY: generate check test test-image test-image-runner test-image-run structure-test +.PHONY: generate check test test-image test-image-runner test-image-run # The containers run as the user who calls make, so that the files they write belong to them. In rootless Docker, # root in the container already is that user. sh replaces the entrypoint of webdevops/php, which would switch to root. @@ -42,6 +42,3 @@ test-image-runner: test-image-run: docker run --rm --volume "$(DOCKER_SOCKET)":/var/run/docker.sock webdevops-image-tests $(IMAGE) $(if $(REFERENCE),--reference $(REFERENCE)) - -structure-test: - cd tests/structure-test && ./run.sh diff --git a/ci/image-tests/Checks/BaseAppChecks.php b/ci/image-tests/Checks/BaseAppChecks.php index 632b73233..9fc3d0d35 100644 --- a/ci/image-tests/Checks/BaseAppChecks.php +++ b/ci/image-tests/Checks/BaseAppChecks.php @@ -4,8 +4,12 @@ namespace Webdevops\Build\ImageTests\Checks; +use PHPUnit\Framework\Attributes\DataProvider; +use Webdevops\Build\ImageTests\Docker\ImageConfiguration; use Webdevops\Build\ImageTests\ImageTestCase; +use function array_keys; +use function escapeshellarg; use function explode; use function trim; @@ -78,4 +82,62 @@ public function testMoreutils(): void self::assertSame("/usr/bin/sponge\n", $this->stdout('command -v sponge')); } + + public function testApplicationVariablesOfTheImage(): void + { + [$name, $id] = ['application', '1000']; + $expected = [ + 'APPLICATION_USER' => $name, + 'APPLICATION_GROUP' => $name, + 'APPLICATION_PATH' => '/app', + 'APPLICATION_UID' => $id, + 'APPLICATION_GID' => $id, + ]; + self::assertSame($expected, ImageConfiguration::inspect(self::image()->reference)->variables(array_keys($expected))); + } + + /** + * The user application has the UID 1000, its primary group application the GID 1000. + */ + public function testIdOfTheApplicationUser(): void + { + self::assertMatchesRegularExpression( + '/^uid=1000\(application\) gid=1000\(application\) groups=1000\(application\)/', + $this->stdout('id application'), + ); + } + + /** + * /app belongs to UID and GID 1000, with the mode 0755. + */ + public function testApplicationPathPermissions(): void + { + $path = '/app'; + self::assertSame('drwxr-xr-x', $this->file($path)->permissions()); + self::assertSame("1000:1000\n", $this->stdout('stat -c %u:%g ' . $path)); + } + + /** + * @return array + */ + public static function applicationTools(): array + { + return self::cases(['zip', 'unzip', 'bzip2', 'nslookup', 'ssh', 'rsync', 'git', 'patch']); + } + + #[DataProvider('applicationTools')] + public function testApplicationToolIsOnThePath(string $tool): void + { + self::assertSame('/usr/bin/' . $tool . "\n", $this->stdout('command -v ' . escapeshellarg($tool))); + } + + /** + * docker-run-bootstrap ran the scripts in /opt/docker/provision/bootstrap.d at the build and deleted them, e.g. + * 10-user-application.sh and 20-app.sh, which create the user application and /app, and in the PHP images + * 10-php-init.sh and 11-php-conf.sh. + */ + public function testBuildScriptsWereRunAndDeleted(): void + { + self::assertSame('', $this->stdout("find /opt/docker/provision/bootstrap.d -name '*.sh'")); + } } diff --git a/ci/image-tests/Checks/BaseChecks.php b/ci/image-tests/Checks/BaseChecks.php index 262c4b25e..b4304cc36 100644 --- a/ci/image-tests/Checks/BaseChecks.php +++ b/ci/image-tests/Checks/BaseChecks.php @@ -9,6 +9,7 @@ use function escapeshellarg; use function in_array; +use function trim; /** * Checks of the images based on webdevops/base: the layout under /opt/docker, supervisor and the tools. @@ -159,4 +160,70 @@ public function testDockerCronjobAddsAJobThatCronRunsAsItsUser(): void self::assertSame("nobody\n", $this->execute('cat /tmp/image-test-cronjob 2>&1', $container)->stdout); }, 30, 3); } + + /** + * The commands of webdevops/base, where the distribution has them: netstat and sed are in /bin in Alpine. + * + * @return iterable + */ + public static function baseCommands(): iterable + { + $commands = [ + 'supervisord' => '#^/usr/bin/supervisord$#', + 'wget' => '#^/usr/bin/wget$#', + 'curl' => '#^/usr/bin/curl$#', + 'zic' => '#^/usr/sbin/zic$#', + 'netstat' => '#^/(usr/)?bin/netstat$#', + 'sed' => '#^/(usr/)?bin/sed$#', + ]; + foreach ($commands as $command => $path) { + yield $command => [$command, $path]; + } + } + + #[DataProvider('baseCommands')] + public function testBaseCommandIsOnThePath(string $command, string $path): void + { + self::assertMatchesRegularExpression($path, trim($this->stdout('command -v ' . escapeshellarg($command)))); + } + + /** + * The scripts and the configuration of webdevops/base have exactly the modes 0755 and 0644: no setuid, setgid or + * sticky bit. + * + * @return iterable + */ + public static function basePermissions(): iterable + { + $scripts = [ + '/opt/docker/bin/bootstrap.sh', + '/opt/docker/bin/config.sh', + '/opt/docker/bin/control.sh', + '/opt/docker/bin/entrypoint.sh', + '/opt/docker/bin/service.d/supervisor.sh', + ]; + foreach ($scripts as $path) { + yield $path => [$path, '-rwxr-xr-x']; + } + + $configuration = [ + '/opt/docker/etc/supervisor.conf', + '/opt/docker/etc/supervisor.d/cron.conf', + '/opt/docker/etc/supervisor.d/dnsmasq.conf', + '/opt/docker/etc/supervisor.d/postfix.conf', + '/opt/docker/etc/supervisor.d/ssh.conf', + '/opt/docker/etc/supervisor.d/syslog.conf', + '/opt/docker/etc/logrotate.d/syslog-ng', + '/opt/docker/etc/syslog-ng/syslog-ng.conf', + ]; + foreach ($configuration as $path) { + yield $path => [$path, '-rw-r--r--']; + } + } + + #[DataProvider('basePermissions')] + public function testBasePermissions(string $path, string $permissions): void + { + self::assertSame($permissions, $this->file($path)->permissions(), $path); + } } diff --git a/ci/image-tests/Checks/BootstrapChecks.php b/ci/image-tests/Checks/BootstrapChecks.php index 521939ed1..5ff4f42d9 100644 --- a/ci/image-tests/Checks/BootstrapChecks.php +++ b/ci/image-tests/Checks/BootstrapChecks.php @@ -5,8 +5,10 @@ namespace Webdevops\Build\ImageTests\Checks; use PHPUnit\Framework\Attributes\DataProvider; +use Webdevops\Build\ImageTests\Docker\ImageConfiguration; use Webdevops\Build\ImageTests\ImageTestCase; +use function array_keys; use function dirname; use function implode; use function preg_quote; @@ -142,4 +144,64 @@ public function testApkInstallsFromTheCache(): void self::assertStringNotContainsString('ERROR', $result->stdout); self::assertStringNotContainsString('unsatisfiable constraints', $result->stdout); } + + /** + * The variables of the locale and the terminal that webdevops/bootstrap and the PHP images set, and the PATH of the + * distribution and of the official PHP image. + */ + public function testLocaleTerminalAndPathOfTheImage(): void + { + $expected = [ + 'LC_ALL' => 'C.UTF-8', + 'LANG' => 'C.UTF-8', + 'TERM' => 'xterm', + 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + ]; + self::assertSame($expected, ImageConfiguration::inspect(self::image()->reference)->variables(array_keys($expected))); + } + + /** + * The commands from provisioning/baselayout, which every image copies from webdevops/toolbox. + * + * @return array + */ + public static function bootstrapCommands(): array + { + return self::cases([ + '/usr/local/bin/apk-install', + '/usr/local/bin/apk-upgrade', + '/usr/local/bin/apt-add-repository', + '/usr/local/bin/apt-install', + '/usr/local/bin/apt-update', + '/usr/local/bin/apt-upgrade', + '/usr/local/bin/docker-image-cleanup', + '/usr/local/bin/docker-image-info', + '/usr/local/bin/generate-locales', + '/usr/local/bin/generate-dockerimage-info', + '/usr/local/bin/docker-run-bootstrap', + '/usr/local/bin/go-replace', + ]); + } + + /** + * Programs of root with exactly the mode 0755: no setuid, setgid or sticky bit. + */ + #[DataProvider('bootstrapCommands')] + public function testBootstrapCommandPermissions(string $path): void + { + $this->assertRootScript($path); + self::assertSame('-rwxr-xr-x', $this->file($path)->permissions(), $path); + } + + /** + * gosu, with which the entrypoint runs commands as another user, is a program of root with the mode 0755 in the + * running container. webdevops/base and the PHP images build it with the setuid and setgid bits, so that their + * entrypoint can switch to root when the container starts as another user, and the entrypoint removes them. + */ + public function testGosuPermissions(): void + { + $gosu = $this->file('/sbin/gosu'); + $this->assertOwnedByRoot($gosu); + self::assertSame('-rwxr-xr-x', $gosu->permissions()); + } } diff --git a/ci/image-tests/Checks/BuildEnvChecks.php b/ci/image-tests/Checks/BuildEnvChecks.php index 8a95e9a0b..226658473 100644 --- a/ci/image-tests/Checks/BuildEnvChecks.php +++ b/ci/image-tests/Checks/BuildEnvChecks.php @@ -24,7 +24,6 @@ public static function buildTools(): iterable { yield 'make' => ['make --version', '/\AGNU Make \d+\.\d+/']; yield 'docker' => ['docker --version', '/\ADocker version \d+\.\d+\.\d+/']; - yield 'container-structure-test' => ['container-structure-test version', '/\Av\d+\.\d+\.\d+$/m']; yield 'git' => ['git --version', '/\Agit version \d+\.\d+/']; } diff --git a/ci/image-tests/Checks/EntrypointChecks.php b/ci/image-tests/Checks/EntrypointChecks.php index 2ea4eb7e4..1ee7cffe2 100644 --- a/ci/image-tests/Checks/EntrypointChecks.php +++ b/ci/image-tests/Checks/EntrypointChecks.php @@ -5,9 +5,11 @@ namespace Webdevops\Build\ImageTests\Checks; use Webdevops\Build\ImageTests\Docker\Container; +use Webdevops\Build\ImageTests\Docker\ImageConfiguration; use Webdevops\Build\ImageTests\ImageTestCase; use function array_filter; +use function array_keys; use function array_values; use function str_contains; use function trim; @@ -71,4 +73,17 @@ private function commandLineOfProcess1(Container $container): string { return trim($this->stdout('tr "\\000" " " < /proc/1/cmdline', $container)); } + + /** + * The image runs supervisord through the entrypoint, and sets the variables that the entrypoint reads: + * DOCKER_CONF_HOME, and LOG_STDOUT and LOG_STDERR, empty by default. + */ + public function testEntrypointCommandAndLogVariablesOfTheImage(): void + { + $configuration = ImageConfiguration::inspect(self::image()->reference); + self::assertSame(['/entrypoint'], $configuration->entrypoint); + self::assertSame(['supervisord'], $configuration->command); + $expected = ['DOCKER_CONF_HOME' => '/opt/docker/', 'LOG_STDOUT' => '', 'LOG_STDERR' => '']; + self::assertSame($expected, $configuration->variables(array_keys($expected))); + } } diff --git a/ci/image-tests/Checks/PhpChecks.php b/ci/image-tests/Checks/PhpChecks.php index 40e96b432..a86331c5e 100644 --- a/ci/image-tests/Checks/PhpChecks.php +++ b/ci/image-tests/Checks/PhpChecks.php @@ -27,6 +27,8 @@ */ trait PhpChecks { + private const string COMPOSER = '/usr/local/bin/composer'; + /** * The security releases of 2026-11-19, https://www.php.net/ */ @@ -229,13 +231,13 @@ public function testPhpSapiIsCli(): void public function testComposer(): void { - foreach (['/usr/local/bin/composer', '/usr/local/bin/composer1', '/usr/local/bin/composer2'] as $path) { + foreach ([self::COMPOSER, '/usr/local/bin/composer1', '/usr/local/bin/composer2'] as $path) { $file = $this->file($path); self::assertTrue($file->isFile, $path . ' should be a file'); self::assertTrue($file->isExecutable, $path . ' should be executable'); } - $this->assertCommandSucceeds('/usr/local/bin/composer'); + $this->assertCommandSucceeds(self::COMPOSER); } /** @@ -295,4 +297,43 @@ private function phpSettings(array $names): array return array_combine($names, array_map(strval(...), $values)); } + + /** + * PIE is only mounted while the RUN instructions that install extensions run, and they remove its working + * directory. + */ + public function testPieIsOnlyThereDuringTheBuild(): void + { + foreach (['/usr/local/bin/pie', '/tmp/pie'] as $path) { + $file = $this->file($path); + self::assertFalse($file->exists || $file->isSymlink, $path . ' should not exist'); + } + } + + /** + * The scripts of the entrypoint that write the PHP and PHP-FPM settings from the environment. + */ + public function testEntrypointScriptsOfPhp(): void + { + foreach (['/opt/docker/provision/entrypoint.d/20-php.sh', '/opt/docker/provision/entrypoint.d/20-php-fpm.sh'] as $path) { + self::assertTrue($this->file($path)->isFile, $path . ' should be a file'); + } + } + + /** + * @return iterable + */ + public static function phpCommands(): iterable + { + $commands = ['convert' => '/usr/bin/convert', 'gm' => '/usr/bin/gm', 'gs' => '/usr/bin/gs', 'composer' => self::COMPOSER]; + foreach ($commands as $command => $path) { + yield $command => [$command, $path]; + } + } + + #[DataProvider('phpCommands')] + public function testPhpCommandIsOnThePath(string $command, string $path): void + { + self::assertSame($path . "\n", $this->stdout('command -v ' . escapeshellarg($command))); + } } diff --git a/ci/image-tests/Checks/PhpDevelopmentChecks.php b/ci/image-tests/Checks/PhpDevelopmentChecks.php index 91e3f9907..04c2792aa 100644 --- a/ci/image-tests/Checks/PhpDevelopmentChecks.php +++ b/ci/image-tests/Checks/PhpDevelopmentChecks.php @@ -49,4 +49,13 @@ public function testSettingsForDevelopment(): void 'opcache.validate_timestamps', 'opcache.interned_strings_buffer', 'opcache.max_accelerated_files', ])); } + + /** + * The Blackfire CLI, which also runs the Blackfire agent. + */ + public function testBlackfireCli(): void + { + $this->assertRootScript('/usr/bin/blackfire'); + self::assertSame("/usr/bin/blackfire\n", $this->stdout('command -v blackfire')); + } } diff --git a/ci/image-tests/Checks/PhpEnvironmentChecks.php b/ci/image-tests/Checks/PhpEnvironmentChecks.php index 9b5dc4213..c768c47cf 100644 --- a/ci/image-tests/Checks/PhpEnvironmentChecks.php +++ b/ci/image-tests/Checks/PhpEnvironmentChecks.php @@ -247,4 +247,21 @@ public function testComposerVersionFromTheEnvironment(): void { self::assertMatchesRegularExpression('/^Composer version 1\.\d+\.\d+ /m', $this->stdout('composer --version 2>/dev/null', $this->environmentContainer())); } + + /** + * php.session.upload_progress.enabled=On enables the upload progress, which the images disable, in the PHP CLI and + * in PHP-FPM: a running worker of PHP-FPM, asked over FastCGI, has it on, so no setting of its pool turns it off + * again. + */ + public function testSessionUploadProgressFromTheEnvironment(): void + { + $container = $this->startTestContainer('session-upload-progress', ['php.session.upload_progress.enabled' => 'On']); + self::assertSame( + "enabled\n", + $this->stdout("php -r 'echo ini_get(\"session.upload_progress.enabled\") ? \"enabled\" : \"disabled\", PHP_EOL;'", $container), + ); + $worker = json_decode($this->phpFpmBody($container, 'test=session_upload_progress'), true); + self::assertIsArray($worker); + self::assertTrue($worker['upload_progress_enabled'] ?? null, 'the worker of PHP-FPM should have the upload progress on'); + } } diff --git a/ci/image-tests/Checks/PhpFpmChecks.php b/ci/image-tests/Checks/PhpFpmChecks.php index 0fbcaee76..bfe9bc9c7 100644 --- a/ci/image-tests/Checks/PhpFpmChecks.php +++ b/ci/image-tests/Checks/PhpFpmChecks.php @@ -37,4 +37,17 @@ public function testPhpFpmDisablesUploadProgress(): void { self::assertMatchesRegularExpression('/^session\.upload_progress\.enabled => Off => Off$/m', $this->stdout('php-fpm -i')); } + + /** + * php-fpm -m lists the extensions of the CLI, see PhpModules. + */ + public function testPhpFpmCommandListsTheModules(): void + { + $result = $this->assertCommandSucceeds('php-fpm -m'); + self::assertSame('', $result->stderr); + $modules = $this->lines($result->stdout); + foreach (PhpModules::loaded(self::image()) as $module) { + self::assertContains($module, $modules, 'php-fpm -m should list ' . $module); + } + } } diff --git a/ci/image-tests/Checks/PhpFpmPublicChecks.php b/ci/image-tests/Checks/PhpFpmPublicChecks.php index 5c1c08acf..c68f6dd52 100644 --- a/ci/image-tests/Checks/PhpFpmPublicChecks.php +++ b/ci/image-tests/Checks/PhpFpmPublicChecks.php @@ -4,6 +4,7 @@ namespace Webdevops\Build\ImageTests\Checks; +use Webdevops\Build\ImageTests\Docker\ImageConfiguration; use Webdevops\Build\ImageTests\ImageTestCase; /** @@ -19,4 +20,9 @@ public function testPhpFpmListensOnAllAddresses(): void { $this->assertListening(9000, '::', '0.0.0.0'); } + + public function testImageExposesPhpFpm(): void + { + self::assertContains('9000/tcp', ImageConfiguration::inspect(self::image()->reference)->exposedPorts); + } } diff --git a/ci/image-tests/Checks/PhpModules.php b/ci/image-tests/Checks/PhpModules.php index b9ccd16cb..13f0e2977 100644 --- a/ci/image-tests/Checks/PhpModules.php +++ b/ci/image-tests/Checks/PhpModules.php @@ -16,7 +16,7 @@ final class PhpModules 'amqp', 'bcmath', 'bz2', 'calendar', 'Core', 'ctype', 'curl', 'date', 'dom', 'exif', 'excimer', 'FFI', 'fileinfo', 'filter', 'ftp', 'gettext', 'gmp', 'hash', 'iconv', 'imagick', 'intl', 'json', 'ldap', 'libxml', 'mbstring', 'memcached', 'mongodb', 'mysqli', 'mysqlnd', 'openssl', 'opentelemetry', 'pcntl', 'pcre', 'PDO', - 'pdo_mysql', 'pdo_pgsql', 'pdo_sqlite', 'pgsql', 'Phar', 'posix', 'protobuf', 'Reflection', 'session', + 'pdo_mysql', 'pdo_pgsql', 'pdo_sqlite', 'pgsql', 'Phar', 'posix', 'protobuf', 'readline', 'Reflection', 'session', 'SimpleXML', 'soap', 'sockets', 'SPL', 'sqlite3', 'standard', 'sysvmsg', 'sysvsem', 'sysvshm', 'tokenizer', 'xml', 'xmlreader', 'xmlwriter', 'xsl', 'yaml', 'zip', 'zlib', 'gd', 'apcu', 'shmop', 'Zend OPcache', 'redis', ]; diff --git a/ci/image-tests/Checks/PiPageChecks.php b/ci/image-tests/Checks/PiPageChecks.php index c6fdcf6c8..f5026bb7e 100644 --- a/ci/image-tests/Checks/PiPageChecks.php +++ b/ci/image-tests/Checks/PiPageChecks.php @@ -5,6 +5,7 @@ namespace Webdevops\Build\ImageTests\Checks; use PHPUnit\Framework\Attributes\DataProvider; +use Webdevops\Build\ImageTests\Docker\ImageConfiguration; use Webdevops\Build\ImageTests\ImageTestCase; /** @@ -19,4 +20,11 @@ public function testWebServerAnswers(string $scheme): void { self::assertStringContainsString('3.14159265359', $this->request($scheme . '://localhost/pi-number.html')); } + + public function testImageExposesHttpAndHttps(): void + { + $exposedPorts = ImageConfiguration::inspect(self::image()->reference)->exposedPorts; + self::assertContains('80/tcp', $exposedPorts); + self::assertContains('443/tcp', $exposedPorts); + } } diff --git a/ci/image-tests/Checks/ServiceChecks.php b/ci/image-tests/Checks/ServiceChecks.php index 48f9a3446..e0d18b652 100644 --- a/ci/image-tests/Checks/ServiceChecks.php +++ b/ci/image-tests/Checks/ServiceChecks.php @@ -12,6 +12,7 @@ use function array_combine; use function array_keys; +use function array_unique; use function in_array; use function ksort; use function preg_match_all; @@ -42,6 +43,11 @@ trait ServiceChecks 'syslog' => 'syslog-ng.d', ]; + /** + * The services of webdevops/base that docker-service enable installs, see docs/customization.md#services. + */ + private const array INSTALLABLE_SERVICES = ['cron', 'dnsmasq', 'postfix', 'ssh', 'syslog']; + /** * The services run and keep their processes: supervisord restarts a crashed service at once and shows it as RUNNING * again, but with another process. @@ -157,4 +163,58 @@ private function runningServices(?Container $container = null): array ksort($services); return $services; } + + /** + * The services of the image and the services of webdevops/base, each with its configuration in + * /opt/docker/etc/supervisor.d. + * + * @return iterable + */ + public static function supervisorPrograms(): iterable + { + foreach (array_unique([...self::INSTALLABLE_SERVICES, ...self::services()]) as $service) { + yield $service => [$service]; + } + } + + /** + * supervisord starts the services of the image by itself (autostart = true), the other services of webdevops/base + * only once docker-service enable sets it. + */ + #[DataProvider('supervisorPrograms')] + public function testServiceStartsAutomaticallyOnlyIfTheImageRunsIt(string $service): void + { + $autostart = in_array($service, self::services(), true) ? 'true' : 'false'; + self::assertMatchesRegularExpression( + '/^autostart\\s*=\\s*' . $autostart . '\\s*$/m', + $this->stdout('cat /opt/docker/etc/supervisor.d/' . $service . '.conf'), + ); + } + + /** + * @return array + */ + public static function installableServices(): array + { + return self::cases(self::INSTALLABLE_SERVICES); + } + + /** + * The installer of a service in /opt/docker/provision/service.d, a file of root with the mode 0644, stays for + * docker-service enable; the images delete the installers of the services they run when they enable them at their + * build. + */ + #[DataProvider('installableServices')] + public function testInstallerIsKeptOnlyForTheServicesTheImageDoesNotRun(string $service): void + { + $path = '/opt/docker/provision/service.d/' . $service . '.sh'; + $file = $this->file($path); + if (in_array($service, self::services(), true)) { + self::assertFalse($file->exists, $path . ' should be deleted, the image runs ' . $service); + return; + } + + $this->assertOwnedByRoot($file); + self::assertSame('-rw-r--r--', $file->permissions(), $path); + } } diff --git a/ci/image-tests/Checks/WebEnvironmentChecks.php b/ci/image-tests/Checks/WebEnvironmentChecks.php index f53e01f17..7af0dba05 100644 --- a/ci/image-tests/Checks/WebEnvironmentChecks.php +++ b/ci/image-tests/Checks/WebEnvironmentChecks.php @@ -4,8 +4,10 @@ namespace Webdevops\Build\ImageTests\Checks; +use Webdevops\Build\ImageTests\Docker\ImageConfiguration; use Webdevops\Build\ImageTests\ImageTestCase; +use function array_keys; use function escapeshellarg; /** @@ -52,4 +54,16 @@ public function testPhpSocketFromTheEnvironment(): void self::assertStringContainsString('127.0.0.1:9999', $container->logs()); }); } + + public function testWebServerVariablesOfTheImage(): void + { + $expected = [ + 'WEB_DOCUMENT_ROOT' => '/app', + 'WEB_DOCUMENT_INDEX' => 'index.php', + 'WEB_ALIAS_DOMAIN' => '*.vm', + 'WEB_PHP_TIMEOUT' => '600', + 'WEB_PHP_SOCKET' => '127.0.0.1:9000', + ]; + self::assertSame($expected, ImageConfiguration::inspect(self::image()->reference)->variables(array_keys($expected))); + } } diff --git a/ci/image-tests/Docker/FileInfo.php b/ci/image-tests/Docker/FileInfo.php index d0a8f3646..caa740bce 100644 --- a/ci/image-tests/Docker/FileInfo.php +++ b/ci/image-tests/Docker/FileInfo.php @@ -6,11 +6,13 @@ use InvalidArgumentException; +use function array_keys; use function escapeshellarg; use function explode; use function octdec; use function sprintf; use function str_contains; +use function strtoupper; /** * Type, owner and mode of a path in the container, read with one command. The type checks follow symbolic links @@ -22,6 +24,11 @@ private const array CLASS_SHIFT = ['owner' => 6, 'group' => 3, 'others' => 0]; + /** + * Position in permissions(), bit and letter of setuid, setgid and the sticky bit + */ + private const array SPECIAL_BITS = [3 => [04000, 's'], 6 => [02000, 's'], 9 => [01000, 't']]; + public function __construct( public string $path, public bool $exists, @@ -80,4 +87,38 @@ public function permits(string $class, string $access): bool return ($this->mode >> self::CLASS_SHIFT[$class] & self::ACCESS_BITS[$access]) !== 0; } + + /** + * Type and mode as "ls -l" and "stat -c %A" show them, e.g. -rwxr-xr-x for a program, drwxr-xr-x for a directory + * and -rwsr-sr-x for a program with the setuid and setgid bits; empty if the path does not exist. + */ + public function permissions(): string + { + if (!$this->exists && !$this->isSymlink) { + return ''; + } + + $permissions = match (true) { + $this->isSymlink => 'l', + $this->isDirectory => 'd', + $this->isCharacterDevice => 'c', + $this->isFile => '-', + default => '?', + }; + foreach (array_keys(self::CLASS_SHIFT) as $class) { + foreach (array_keys(self::ACCESS_BITS) as $access) { + $permissions .= $this->permits($class, $access) ? $access : '-'; + } + } + + // setuid, setgid and sticky bit take the place of the x of the owner, the group and others, in upper case if + // that x is not set + foreach (self::SPECIAL_BITS as $position => [$bit, $letter]) { + if (($this->mode & $bit) !== 0) { + $permissions[$position] = ($this->mode & (1 << (9 - $position))) !== 0 ? $letter : strtoupper($letter); + } + } + + return $permissions; + } } diff --git a/ci/image-tests/Docker/ImageConfiguration.php b/ci/image-tests/Docker/ImageConfiguration.php new file mode 100644 index 000000000..8ef112c4c --- /dev/null +++ b/ci/image-tests/Docker/ImageConfiguration.php @@ -0,0 +1,113 @@ + $environment the variables of ENV and of the images it builds on, by name + * @param list|null $entrypoint null if the image has none + * @param list|null $command null if the image has none + * @param list $exposedPorts e.g. 80/tcp + */ + public function __construct( + public array $environment, + public ?array $entrypoint, + public ?array $command, + public array $exposedPorts, + ) { + } + + public static function inspect(string $image): self + { + $process = new Process(['docker', 'image', 'inspect', '--format', '{{json .Config}}', $image]); + $process->setTimeout(self::TIMEOUT); + $process->run(); + if (!$process->isSuccessful()) { + throw new RuntimeException(sprintf('docker image inspect %s failed: %s', $image, trim($process->getErrorOutput()))); + } + + return self::parse($process->getOutput()); + } + + /** + * @param string $json the output of docker image inspect --format '{{json .Config}}' + */ + public static function parse(string $json): self + { + $configuration = json_decode($json, true, 512, JSON_THROW_ON_ERROR); + if (!is_array($configuration)) { + throw new RuntimeException('docker image inspect returned no configuration: ' . trim($json)); + } + + $environment = []; + foreach (self::strings($configuration['Env'] ?? null) ?? [] as $variable) { + [$name, $value] = explode('=', $variable, 2) + [1 => '']; + $environment[$name] = $value; + } + + $exposedPorts = $configuration['ExposedPorts'] ?? null; + + return new self( + $environment, + self::strings($configuration['Entrypoint'] ?? null), + self::strings($configuration['Cmd'] ?? null), + is_array($exposedPorts) ? array_map(strval(...), array_keys($exposedPorts)) : [], + ); + } + + /** + * The values of the variables $names, null for a variable that the image does not set. + * + * @param list $names + * @return array + */ + public function variables(array $names): array + { + $variables = []; + foreach ($names as $name) { + $variables[$name] = $this->environment[$name] ?? null; + } + + return $variables; + } + + /** + * @return list|null + */ + private static function strings(mixed $value): ?array + { + if (!is_array($value) || !array_is_list($value)) { + return null; + } + + return array_map(static fn (mixed $item): string => is_string($item) ? $item : '', $value); + } +} diff --git a/ci/src/GithubJobBuilder.php b/ci/src/GithubJobBuilder.php index 925f3494b..3fe554793 100644 --- a/ci/src/GithubJobBuilder.php +++ b/ci/src/GithubJobBuilder.php @@ -136,7 +136,6 @@ public function __construct(private readonly string $rootPath = __DIR__ . '/../. public function getJobsDescription(array $node): array { $imageTests = $this->imageTests($node); - $structuredTests = $this->structuredTests($node); $jobId = GithubJobBuilder::toJobId($node['name']); $hasParent = (bool)($node['parent'] ?? null); @@ -211,10 +210,6 @@ public function getJobsDescription(array $node): array 'name' => 'run image tests', 'run' => $imageTests, ] : null, - $structuredTests ? [ - 'name' => 'run structure-test', - 'run' => implode("\n", $structuredTests), - ] : null, [ 'if' => '${{github.ref == \'refs/heads/master\'}}', ...$this->loginGhcrStep(), @@ -512,27 +507,6 @@ private function imageTests(array $node): ?string . ' REFERENCE=' . $this->archImage($node['image'], $node['tag']); } - /** - * Shell lines of the container-structure-test step, none if the image has no suite. - * - * @param array $node - * @return list - */ - private function structuredTests(array $node): array - { - $script = []; - if (file_exists($this->rootPath . '/tests/structure-test/' . $node['image'] . '/test.yaml')) { - $script[] = 'cd tests/structure-test'; - if (file_exists($this->rootPath . '/tests/structure-test/' . $node['image'] . '/' . $node['tag'] . '/test.yaml')) { - $script[] = '/usr/local/bin/container-structure-test test --image ' . $this->archImage($node['image'], $node['tag']) . ' --config ' . $node['image'] . '/test.yaml --config ' . $node['image'] . '/' . $node['tag'] . '/test.yaml'; - } else { - $script[] = '/usr/local/bin/container-structure-test test --image ' . $this->archImage($node['image'], $node['tag']) . ' --config ' . $node['image'] . '/test.yaml'; - } - } - - return $script; - } - /** * Steps of an image job that provide the image test runner: they load the archive of the job IMAGE_TEST_RUNNER_JOB, * without a request to Docker Hub. Only if there is none or it does not load, e.g. because that job failed, the job diff --git a/ci/tests/Fixtures/repository/tests/structure-test/base/alpine/test.yaml b/ci/tests/Fixtures/repository/tests/structure-test/base/alpine/test.yaml deleted file mode 100644 index 90934da86..000000000 --- a/ci/tests/Fixtures/repository/tests/structure-test/base/alpine/test.yaml +++ /dev/null @@ -1 +0,0 @@ -schemaVersion: 2.0.0 diff --git a/ci/tests/Fixtures/repository/tests/structure-test/base/test.yaml b/ci/tests/Fixtures/repository/tests/structure-test/base/test.yaml deleted file mode 100644 index 90934da86..000000000 --- a/ci/tests/Fixtures/repository/tests/structure-test/base/test.yaml +++ /dev/null @@ -1 +0,0 @@ -schemaVersion: 2.0.0 diff --git a/ci/tests/GithubJobBuilderTest.php b/ci/tests/GithubJobBuilderTest.php index dc081e18a..bdc7d8544 100644 --- a/ci/tests/GithubJobBuilderTest.php +++ b/ci/tests/GithubJobBuilderTest.php @@ -136,7 +136,6 @@ public function testImageWithoutDependenciesIsBuiltOnce(): void 'Load the image test runner', 'Build the image test runner', 'run image tests', - 'run structure-test', 'Login to ghcr.io', 'Push arch image', ], array_keys($steps)); @@ -210,20 +209,6 @@ public function testOfficialPhpImageRunsTheTestsOfPhp(): void ); } - public function testStructureTestUsesTheSuiteOfTheTagToo(): void - { - self::assertSame( - "cd tests/structure-test\n/usr/local/bin/container-structure-test test --image ghcr.io/webdevops/base:sha-\${{ github.sha }}-\${{ matrix.arch }}-alpine" - . ' --config base/test.yaml --config base/alpine/test.yaml', - $this->step($this->jobs(), 'run structure-test')['run'], - ); - self::assertSame( - "cd tests/structure-test\n/usr/local/bin/container-structure-test test --image ghcr.io/webdevops/base:sha-\${{ github.sha }}-\${{ matrix.arch }}-ubuntu-22.04" - . ' --config base/test.yaml', - $this->step($this->jobs(['tag' => 'ubuntu-22.04']), 'run structure-test')['run'], - ); - } - public function testImageWithoutTestsHasNoTestSteps(): void { $steps = $this->steps($this->jobs(['image' => 'php-nginx'])); @@ -232,7 +217,6 @@ public function testImageWithoutTestsHasNoTestSteps(): void self::assertArrayNotHasKey('Load the image test runner', $steps); self::assertArrayNotHasKey('Build the image test runner', $steps); self::assertArrayNotHasKey('run image tests', $steps); - self::assertArrayNotHasKey('run structure-test', $steps); } public function testBranchBuildUsesTheParentImagesOfThisRun(): void @@ -254,7 +238,6 @@ public function testBranchBuildUsesTheParentImagesOfThisRun(): void 'Load the image test runner', 'Build the image test runner', 'run image tests', - 'run structure-test', 'Login to ghcr.io', 'Push arch image', ], array_keys($steps)); diff --git a/ci/tests/ImageTests/DockerTest.php b/ci/tests/ImageTests/DockerTest.php index 4095c7104..b608d3234 100644 --- a/ci/tests/ImageTests/DockerTest.php +++ b/ci/tests/ImageTests/DockerTest.php @@ -5,10 +5,12 @@ namespace Webdevops\Build\Tests\ImageTests; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Webdevops\Build\ImageTests\Docker\CommandResult; use Webdevops\Build\ImageTests\Docker\FileArchive; use Webdevops\Build\ImageTests\Docker\FileInfo; +use Webdevops\Build\ImageTests\Docker\ImageConfiguration; use Webdevops\Build\ImageTests\Docker\ListeningSockets; use Webdevops\Build\Tests\TemporaryRepository; @@ -27,6 +29,7 @@ * The parts of the image test harness that work without a container. */ #[CoversClass(FileInfo::class)] +#[CoversClass(ImageConfiguration::class)] #[CoversClass(ListeningSockets::class)] #[CoversClass(CommandResult::class)] #[CoversClass(FileArchive::class)] @@ -78,6 +81,51 @@ public function testFileInfoOfASymbolicLink(): void self::assertSame(0777, $file->mode); } + /** + * @return iterable + */ + public static function permissions(): iterable + { + yield 'program' => ["root|root|755\nefx\n", '-rwxr-xr-x']; + yield 'file' => ["root|root|644\nef\n", '-rw-r--r--']; + yield 'directory' => ["application|application|755\nedx\n", 'drwxr-xr-x']; + yield 'setuid and setgid' => ["root|root|6755\nefx\n", '-rwsr-sr-x']; + yield 'setgid without x' => ["root|root|2644\nef\n", '-rw-r-Sr--']; + yield 'sticky directory' => ["root|root|1777\nedx\n", 'drwxrwxrwt']; + yield 'symbolic link to a directory' => ["root|root|777\nedLx\n", 'lrwxrwxrwx']; + yield 'character device' => ["root|root|666\nec\n", 'crw-rw-rw-']; + yield 'missing' => ["\n\n", '']; + } + + #[DataProvider('permissions')] + public function testFileInfoPermissionsAsLsShowsThem(string $output, string $expected): void + { + self::assertSame($expected, FileInfo::parse('/path', $output)->permissions()); + } + + public function testImageConfiguration(): void + { + $configuration = ImageConfiguration::parse( + '{"Env":["PATH=/usr/local/bin:/usr/bin","LOG_STDOUT=","WEB_PHP_SOCKET=127.0.0.1:9000","EQUALS=a=b"],' + . '"Entrypoint":["/entrypoint"],"Cmd":["supervisord"],"ExposedPorts":{"443/tcp":{},"80/tcp":{}},"WorkingDir":"/"}', + ); + + self::assertSame(['PATH' => '/usr/local/bin:/usr/bin', 'LOG_STDOUT' => '', 'WEB_PHP_SOCKET' => '127.0.0.1:9000', 'EQUALS' => 'a=b'], $configuration->environment); + self::assertSame(['/entrypoint'], $configuration->entrypoint); + self::assertSame(['supervisord'], $configuration->command); + self::assertSame(['443/tcp', '80/tcp'], $configuration->exposedPorts); + self::assertSame(['EQUALS' => 'a=b', 'TZ' => null], $configuration->variables(['EQUALS', 'TZ']), 'null for a variable the image does not set'); + } + + public function testImageConfigurationWithoutEntrypointAndPorts(): void + { + $configuration = ImageConfiguration::parse('{"Env":["TERM=xterm"],"Entrypoint":null,"Cmd":["/bin/bash"],"ExposedPorts":null}'); + + self::assertNull($configuration->entrypoint); + self::assertSame(['/bin/bash'], $configuration->command); + self::assertSame([], $configuration->exposedPorts); + } + public function testListeningSocketsFromTheKernelTables(): void { $sockets = ListeningSockets::parse(<<<'TABLES' diff --git a/docker/dockerfile-build-env/latest/Dockerfile b/docker/dockerfile-build-env/latest/Dockerfile index 16fbec186..8493ea7da 100644 --- a/docker/dockerfile-build-env/latest/Dockerfile +++ b/docker/dockerfile-build-env/latest/Dockerfile @@ -17,9 +17,6 @@ RUN apt-install \ && add-apt-repository "deb [arch=$TARGETARCH] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \ && apt-install docker-ce \ && usermod -aG docker application \ - && curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-$TARGETARCH \ - && chmod +x container-structure-test-linux-$TARGETARCH \ - && mv container-structure-test-linux-$TARGETARCH /usr/local/bin/container-structure-test \ && docker-image-cleanup WORKDIR /app diff --git a/docker/dockerfile-build-env/latest/Dockerfile.twig b/docker/dockerfile-build-env/latest/Dockerfile.twig index 1331a38fd..76c53c998 100644 --- a/docker/dockerfile-build-env/latest/Dockerfile.twig +++ b/docker/dockerfile-build-env/latest/Dockerfile.twig @@ -13,9 +13,6 @@ RUN apt-install \ && add-apt-repository "deb [arch=$TARGETARCH] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \ && apt-install docker-ce \ && usermod -aG docker application \ - && curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-$TARGETARCH \ - && chmod +x container-structure-test-linux-$TARGETARCH \ - && mv container-structure-test-linux-$TARGETARCH /usr/local/bin/container-structure-test \ {{ docker.cleanup() }} WORKDIR /app diff --git a/tests/structure-test/base-app/test.yaml b/tests/structure-test/base-app/test.yaml deleted file mode 100644 index ed8728d8a..000000000 --- a/tests/structure-test/base-app/test.yaml +++ /dev/null @@ -1,66 +0,0 @@ -schemaVersion: "2.0.0" - -metadataTest: - envVars: - - key: "APPLICATION_USER" - value: "application" - - key: "APPLICATION_GROUP" - value: "application" - - key: "APPLICATION_PATH" - value: "/app" - - key: "APPLICATION_UID" - value: "1000" - - key: "APPLICATION_GID" - value: "1000" - -fileExistenceTests: - - name: 'provision: add application user script was deleted after execution' - path: '/opt/docker/provision/bootstrap.d/10-user-application.sh' - shouldExist: false - - name: 'provision: set permission script was deleted after execution' - path: '/opt/docker/provision/bootstrap.d/20-app.sh' - shouldExist: false - - name: 'app folder exists' - path: '/app' - shouldExist: true - permissions: 'drwxr-xr-x' - uid: 1000 - gid: 1000 - -commandTests: - - name: "application user and group exists" - command: "id" - args: ["application"] - expectedOutput: ['uid\=1000\(application\) gid\=1000\(application\) groups\=1000\(application\)'] - - name: "zip" - command: "which" - args: ["zip"] - expectedOutput: ["/usr/bin/zip"] - - name: "unzip" - command: "which" - args: ["unzip"] - expectedOutput: ["/usr/bin/unzip"] - - name: "nslookup" - command: "which" - args: ["nslookup"] - expectedOutput: ["/usr/bin/nslookup"] - - name: "ssh" - command: "which" - args: ["ssh"] - expectedOutput: ["/usr/bin/ssh"] - - name: "rsync" - command: "which" - args: ["rsync"] - expectedOutput: ["/usr/bin/rsync"] - - name: "git" - command: "which" - args: ["git"] - expectedOutput: ["/usr/bin/git"] - - name: "patch" - command: "which" - args: ["patch"] - expectedOutput: ["/usr/bin/patch"] - - name: "bzip2" - command: "which" - args: ["bzip2"] - expectedOutput: ["/usr/bin/bzip2"] diff --git a/tests/structure-test/base/test.yaml b/tests/structure-test/base/test.yaml deleted file mode 100644 index ce94f23f8..000000000 --- a/tests/structure-test/base/test.yaml +++ /dev/null @@ -1,112 +0,0 @@ -schemaVersion: "2.0.0" - -metadataTest: - entrypoint: ["/entrypoint"] - cmd: ["supervisord"] - envVars: - - key: "DOCKER_CONF_HOME" - value: "/opt/docker/" - - key: "LOG_STDOUT" - value: "" - - key: "LOG_STDERR" - value: "" - -fileExistenceTests: - - name: 'bin: bootstrap script' - path: '/opt/docker/bin/bootstrap.sh' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'bin: config script' - path: '/opt/docker/bin/config.sh' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'bin: control script' - path: '/opt/docker/bin/control.sh' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'bin: entrypoint script' - path: '/opt/docker/bin/entrypoint.sh' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'bin: supervisor entrypoint script' - path: '/opt/docker/bin/service.d/supervisor.sh' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'configfile: supervisor base' - path: '/opt/docker/etc/supervisor.conf' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'configfile: supervisor service cron' - path: '/opt/docker/etc/supervisor.d/cron.conf' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'configfile: supervisor service dnsmasq' - path: '/opt/docker/etc/supervisor.d/dnsmasq.conf' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'configfile: supervisor service postfix' - path: '/opt/docker/etc/supervisor.d/postfix.conf' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'configfile: supervisor service ssh' - path: '/opt/docker/etc/supervisor.d/ssh.conf' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'configfile: supervisor service syslog' - path: '/opt/docker/etc/supervisor.d/syslog.conf' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'configfile: logrotate' - path: '/opt/docker/etc/logrotate.d/syslog-ng' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'configfile: syslog-ng' - path: '/opt/docker/etc/syslog-ng/syslog-ng.conf' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provisioning: cron' - path: '/opt/docker/provision/service.d/cron.sh' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provisioning: dnsmasq' - path: '/opt/docker/provision/service.d/dnsmasq.sh' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provisioning: postfix' - path: '/opt/docker/provision/service.d/postfix.sh' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provisioning: ssh' - path: '/opt/docker/provision/service.d/ssh.sh' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provisioning: syslog' - path: '/opt/docker/provision/service.d/syslog.sh' - shouldExist: true - permissions: '-rw-r--r--' - -commandTests: - - name: "supervisord" - command: "which" - args: ["supervisord"] - expectedOutput: ["/usr/bin/supervisord"] - - name: "wget" - command: "which" - args: ["wget"] - expectedOutput: ["/usr/bin/wget"] - - name: "curl" - command: "which" - args: ["curl"] - expectedOutput: ["/usr/bin/curl"] - - name: "zic" - command: "which" - args: ["zic"] - expectedOutput: ["/usr/sbin/zic"] - - name: "netstat" - command: "which" - args: ["netstat"] - expectedOutput: ["^/(usr/)?bin/netstat\\s*$"] - - name: "sed" - command: "which" - args: ["sed"] - expectedOutput: ["^/(usr/)?bin/sed\\s*$"] diff --git a/tests/structure-test/bootstrap/test.yaml b/tests/structure-test/bootstrap/test.yaml deleted file mode 100644 index 384b2638f..000000000 --- a/tests/structure-test/bootstrap/test.yaml +++ /dev/null @@ -1,66 +0,0 @@ -schemaVersion: "2.0.0" - -metadataTest: - envVars: - - key: "LC_ALL" - value: "C.UTF-8" - - key: "LANG" - value: "C.UTF-8" - - key: "TERM" - value: "xterm" - - key: "PATH" - value: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - -fileExistenceTests: - - name: 'apk add wrapper' - path: '/usr/local/bin/apk-install' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'apk upgrade wrapper' - path: '/usr/local/bin/apk-upgrade' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'apt-add-repository wrapper with auto cleanup' - path: '/usr/local/bin/apt-add-repository' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'apt-get install wrapper with auto cleanup' - path: '/usr/local/bin/apt-install' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'apt-get update wrapper for multiple apt-install runs' - path: '/usr/local/bin/apt-update' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'apt-get upgrade wrapper with auto cleanup' - path: '/usr/local/bin/apt-upgrade' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'Cleanup for docker images after package installations' - path: '/usr/local/bin/docker-image-cleanup' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'Gets information about the current docker images' - path: '/usr/local/bin/docker-image-info' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'Generates system locales' - path: '/usr/local/bin/generate-locales' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'Generates docker image info' - path: '/usr/local/bin/generate-dockerimage-info' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'Bootstrapping script' - path: '/usr/local/bin/docker-run-bootstrap' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'go-replace tool' - path: '/usr/local/bin/go-replace' - shouldExist: true - permissions: '-rwxr-xr-x' - - name: 'gosu tool' - path: '/sbin/gosu' - shouldExist: true - permissions: '-rwxr-xr-x' diff --git a/tests/structure-test/php-dev/test.yaml b/tests/structure-test/php-dev/test.yaml deleted file mode 100644 index 5e95dbe2f..000000000 --- a/tests/structure-test/php-dev/test.yaml +++ /dev/null @@ -1,34 +0,0 @@ -schemaVersion: "2.0.0" - -fileExistenceTests: - - name: 'blackfire should exist' - path: '/usr/bin/blackfire' - shouldExist: true - -fileContentTests: - - name: 'supervisor: syslog service is enabled' - path: '/opt/docker/etc/supervisor.d/syslog.conf' - expectedContents: ['autostart = true'] - - name: 'supervisor: postfix service is enabled' - path: '/opt/docker/etc/supervisor.d/postfix.conf' - expectedContents: ['autostart = true'] - - name: 'supervisor: ssh service is enabled' - path: '/opt/docker/etc/supervisor.d/ssh.conf' - expectedContents: ['autostart = true'] - -commandTests: - - name: "xdebug enabled by default" - setup: [["/entrypoint", "/bin/bash"]] - command: "php" - args: ["-m"] - expectedOutput: ["Xdebug"] - excludedOutput: ["blackfire"] - - name: "PHP_DEBUGGER change to blackfire" - setup: [["/entrypoint", "/bin/bash"]] - envVars: - - key: "PHP_DEBUGGER" - value: "blackfire" - command: "php" - args: ["-m"] - expectedOutput: ["blackfire"] - excludedOutput: ["Xdebug"] diff --git a/tests/structure-test/php-nginx/test.yaml b/tests/structure-test/php-nginx/test.yaml deleted file mode 100644 index 4b298e79b..000000000 --- a/tests/structure-test/php-nginx/test.yaml +++ /dev/null @@ -1,51 +0,0 @@ -schemaVersion: "2.0.0" - -metadataTest: - envVars: - - key: "WEB_DOCUMENT_ROOT" - value: "/app" - - key: "WEB_DOCUMENT_INDEX" - value: "index.php" - - key: "WEB_ALIAS_DOMAIN" - value: "*.vm" - - key: "WEB_PHP_TIMEOUT" - value: "600" - - key: "WEB_PHP_SOCKET" - value: "127.0.0.1:9000" - exposedPorts: ["80", "443"] - -fileExistenceTests: - - name: 'nginx service script should exist' - path: '/opt/docker/bin/service.d/nginx.sh' - shouldExist: true - - name: 'nginx configs should exist' - path: '/opt/docker/etc/nginx/vhost.conf' - shouldExist: true - -fileContentTests: - - name: 'supervisor: nginx service is enabled' - path: '/opt/docker/etc/supervisor.d/nginx.conf' - expectedContents: ['autostart = true'] - -commandTests: - - name: "Nginx configuration test" - setup: [["/entrypoint", "/bin/bash"]] - command: "nginx" - args: ["-t"] - expectedError: ["syntax is ok", "test is successful"] - - name: "WEB_DOCUMENT_ROOT changes according to ENV var" - setup: [["/entrypoint", "/bin/bash"]] - envVars: - - key: "WEB_DOCUMENT_ROOT" - value: "/some/test/dir" - command: "nginx" - args: ["-T"] - expectedOutput: ['root "/some/test/dir";'] - - name: "WEB_DOCUMENT_INDEX changes according to ENV var" - setup: [["/entrypoint", "/bin/bash"]] - envVars: - - key: "WEB_DOCUMENT_INDEX" - value: "somefile.php" - command: "nginx" - args: ["-T"] - expectedOutput: ["index somefile.php;"] diff --git a/tests/structure-test/php/test.yaml b/tests/structure-test/php/test.yaml deleted file mode 100644 index adab1d39f..000000000 --- a/tests/structure-test/php/test.yaml +++ /dev/null @@ -1,255 +0,0 @@ -schemaVersion: "2.0.0" - -metadataTest: - entrypoint: ["/entrypoint"] - cmd: ["supervisord"] - exposedPorts: ["9000"] - envVars: - - key: "LC_ALL" - value: "C.UTF-8" - - key: "LANG" - value: "C.UTF-8" - - key: "TERM" - value: "xterm" - - key: "DOCKER_CONF_HOME" - value: "/opt/docker/" - - key: "LOG_STDOUT" - value: "" - - key: "LOG_STDERR" - value: "" - - key: "APPLICATION_USER" - value: "application" - - key: "APPLICATION_GROUP" - value: "application" - - key: "APPLICATION_PATH" - value: "/app" - - key: "APPLICATION_UID" - value: "1000" - - key: "APPLICATION_GID" - value: "1000" - -fileExistenceTests: - - name: 'PIE is only mounted during builds' - path: '/usr/local/bin/pie' - shouldExist: false - - name: 'PIE working directory was removed after the build' - path: '/tmp/pie' - shouldExist: false - - name: 'provision: image family script was deleted after execution' - path: '/opt/docker/provision/bootstrap.d/10-php-init.sh' - shouldExist: false - - name: 'provision: PHP path variables script was deleted after execution' - path: '/opt/docker/provision/bootstrap.d/11-php-conf.sh' - shouldExist: false - - name: 'provision: cron installer was deleted after enabling the service' - path: '/opt/docker/provision/service.d/cron.sh' - shouldExist: false - - name: 'provision: syslog installer was deleted after enabling the service' - path: '/opt/docker/provision/service.d/syslog.sh' - shouldExist: false - - name: 'provision: fpm config was created' - path: '/opt/docker/etc/php/fpm/php-fpm.conf' - shouldExist: true - - name: 'provision: fpm pool config was created' - path: '/opt/docker/etc/php/fpm/pool.d/application.conf' - shouldExist: true - - name: 'entrypoint: fpm config builder exists' - path: '/opt/docker/provision/entrypoint.d/20-php-fpm.sh' - shouldExist: true - - name: 'entrypoint: ini config builder exists' - path: '/opt/docker/provision/entrypoint.d/20-php.sh' - shouldExist: true - - name: 'supervisor: fpm starter exists' - path: '/opt/docker/etc/supervisor.d/php-fpm.conf' - shouldExist: true - - name: 'provision: dnsmasq installer is retained' - path: '/opt/docker/provision/service.d/dnsmasq.sh' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provision: postfix installer is retained' - path: '/opt/docker/provision/service.d/postfix.sh' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provision: ssh installer is retained' - path: '/opt/docker/provision/service.d/ssh.sh' - shouldExist: true - permissions: '-rw-r--r--' - - name: 'provision: add application user script was deleted after execution' - path: '/opt/docker/provision/bootstrap.d/10-user-application.sh' - shouldExist: false - - name: 'provision: set permission script was deleted after execution' - path: '/opt/docker/provision/bootstrap.d/20-app.sh' - shouldExist: false - - name: 'app folder exists and is owned by the application user' - path: '/app' - shouldExist: true - permissions: 'drwxr-xr-x' - uid: 1000 - gid: 1000 - -fileContentTests: - - name: 'supervisor: syslog service is enabled' - path: '/opt/docker/etc/supervisor.d/syslog.conf' - expectedContents: ['autostart = true'] - - name: 'supervisor: cron service is enabled' - path: '/opt/docker/etc/supervisor.d/cron.conf' - expectedContents: ['autostart = true'] - -commandTests: - - name: "session upload progress can be enabled explicitly for CLI" - setup: [["/entrypoint", "/bin/bash"]] - envVars: - - key: "php.session.upload_progress.enabled" - value: "On" - command: "php" - args: ["-r", "echo ini_get('session.upload_progress.enabled') ? 'enabled' : 'disabled';"] - expectedOutput: ['^enabled$'] - exitCode: 0 - - name: "session upload progress can be enabled explicitly for FPM" - setup: [["/entrypoint", "/bin/bash"]] - envVars: - - key: "php.session.upload_progress.enabled" - value: "On" - command: "/usr/local/bin/php-fpm" - args: ["-i"] - expectedOutput: ['session\.upload_progress\.enabled => On => On'] - exitCode: 0 - - name: "zip" - command: "which" - args: ["zip"] - expectedOutput: ["/usr/bin/zip"] - - name: "unzip" - command: "which" - args: ["unzip"] - expectedOutput: ["/usr/bin/unzip"] - - name: "nslookup" - command: "which" - args: ["nslookup"] - expectedOutput: ["/usr/bin/nslookup"] - - name: "ssh" - command: "which" - args: ["ssh"] - expectedOutput: ["/usr/bin/ssh"] - - name: "rsync" - command: "which" - args: ["rsync"] - expectedOutput: ["/usr/bin/rsync"] - - name: "git" - command: "which" - args: ["git"] - expectedOutput: ["/usr/bin/git"] - - name: "patch" - command: "which" - args: ["patch"] - expectedOutput: ["/usr/bin/patch"] - - name: "PHP version is 8.2 or newer" - command: "php" - args: ["-v"] - expectedOutput: ['PHP 8\.([2-9]|[1-9][0-9]+)\.'] - - name: "fpm config test" - command: "/usr/local/bin/php-fpm" - args: ["-t"] - expectedError: ["test is successful"] - - name: "env variables are available in FPM" - setup: [["/entrypoint", "/bin/bash"]] - command: "/usr/local/bin/php-fpm" - envVars: - - key: "SOME_VAR" - value: "someval" - args: ["-i"] - expectedOutput: ["SOME_VAR => someval"] - - name: "imagemagick convert" - command: "which" - args: ["convert"] - expectedOutput: ["/usr/bin/convert"] - - name: "graphicsmagick" - command: "which" - args: ["gm"] - expectedOutput: ["/usr/bin/gm"] - - name: "ghostscript" - command: "which" - args: ["gs"] - expectedOutput: ["/usr/bin/gs"] - - name: "composer" - command: "which" - args: ["composer"] - expectedOutput: ["/usr/local/bin/composer"] - - name: "php modules" - command: "php" - args: ["-m"] - expectedOutput: &phpModules - - "amqp" - - "apcu" - - "bcmath" - - "bz2" - - "calendar" - - "Core" - - "ctype" - - "curl" - - "date" - - "dom" - - "exif" - - "excimer" - - "FFI" - - "fileinfo" - - "filter" - - "ftp" - - "gd" - - "gettext" - - "gmp" - - "hash" - - "iconv" - - "imagick" - - "intl" - - "json" - - "ldap" - - "libxml" - - "mbstring" - - "memcached" - - "mongodb" - - "mysqli" - - "mysqlnd" - - "openssl" - - "opentelemetry" - - "pcntl" - - "pcre" - - "PDO" - - "pdo_mysql" - - "pdo_pgsql" - - "pdo_sqlite" - - "pgsql" - - "Phar" - - "posix" - - "protobuf" - - "readline" - - "redis" - - "Reflection" - - "session" - - "shmop" - - "SimpleXML" - - "soap" - - "sockets" - - "SPL" - - "sqlite3" - - "standard" - - "sysvmsg" - - "sysvsem" - - "sysvshm" - - "tokenizer" - - "xml" - - "xmlreader" - - "xmlwriter" - - "xsl" - - "yaml" - - "Zend OPcache" - - "zip" - - "zlib" - - name: "fpm modules" - command: "/usr/local/bin/php-fpm" - args: ["-m"] - expectedOutput: *phpModules - # vips and xmlrpc are abandoned upstream and only built up to PHP 8.5 - - name: "vips and xmlrpc modules (PHP 8.5 and older)" - command: "php" - args: ["-r", "exit(PHP_VERSION_ID >= 80600 || (extension_loaded('vips') && extension_loaded('xmlrpc')) ? 0 : 1);"] - exitCode: 0 diff --git a/tests/structure-test/run.sh b/tests/structure-test/run.sh deleted file mode 100755 index b5ae5fbad..000000000 --- a/tests/structure-test/run.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash -# Runs container-structure-test against the local webdevops images that have a suite in this directory. -# Only the tags the CI builds are tested (the -t "webdevops/..." lines in .github/workflows/build.yaml); -# tags that are not built locally are skipped, and a tag that is the same image as one already tested -# with the same suites (for example latest and ubuntu-22.04) is tested once. -# Exits non-zero if a test fails, if docker cannot list the images or if no image was tested. -# Needs Bash 4 or newer (declare -A, mapfile). - -if (( BASH_VERSINFO[0] < 4 )); then - echo "ERROR: run.sh needs Bash 4 or newer, this is Bash $BASH_VERSION." >&2 - echo "Run make structure-test inside webdevops/dockerfile-build-env, or put a newer bash first in PATH." >&2 - exit 1 -fi - -cd "$(dirname "$0")" || exit 1 - -BUILD_YAML="../../.github/workflows/build.yaml" - -if [[ ! -f "$BUILD_YAML" ]]; then - echo "ERROR: $BUILD_YAML not found" >&2 - exit 1 -fi - -# ": " per line -if ! LOCAL_IMAGES="$(docker images --no-trunc --format '{{.Repository}}:{{.Tag}} {{.ID}}')"; then - echo "ERROR: docker images failed" >&2 - exit 1 -fi - -FAILED=0 -TESTED=0 -SUITES=() -declare -A TESTED_AS - -for testRepo in */; do - testRepo="${testRepo%/}" - - if [[ ! -f "$testRepo/test.yaml" ]]; then - continue - fi - SUITES+=("$testRepo") - - mapfile -t BUILT_TAGS < <(grep -oE "\"webdevops/${testRepo}:[^\"]+\"" "$BUILD_YAML" | tr -d '"' | cut -d ':' -f 2 | sort -u) - - for imageTag in "${BUILT_TAGS[@]}"; do - image="webdevops/$testRepo:$imageTag" - imageId="$(awk -v image="$image" '$1 == image { print $2; exit }' <<< "$LOCAL_IMAGES")" - if [[ -z "$imageId" ]]; then - continue - fi - - CONFIGS=(--config "$testRepo/test.yaml") - if [[ -f "$testRepo/$imageTag/test.yaml" ]]; then - CONFIGS+=(--config "$testRepo/$imageTag/test.yaml") - fi - - testKey="$imageId ${CONFIGS[*]}" - if [[ -n "${TESTED_AS[$testKey]:-}" ]]; then - echo "Skipping $image: same image and suites as ${TESTED_AS[$testKey]}" - continue - fi - TESTED_AS[$testKey]="$image" - - echo "==============================================" - echo "Testing: $image" - echo "==============================================" - - TESTED=$((TESTED + 1)) - container-structure-test test --image "$image" "${CONFIGS[@]}" || FAILED=1 - done -done - -if [[ "$TESTED" -eq 0 ]]; then - echo "ERROR: no image was tested. Build at least one tag of these images first: ${SUITES[*]}" >&2 - exit 1 -fi - -echo "Tested $TESTED images" -exit $FAILED