Add docker support for pre-commit jobs
We're making increasing use of pre-commit hooks and some hooks required docker to be installed and functioning in order to run applications with complex packaging. An example of this in the (upcoming) Cloud Run v2 terraform module can be found at https://gitlab.developers.cam.ac.uk/uis/devops/infra/terraform/gcp-cloud-run-app/-/blob/3b23e6dda7ea38f01288183ee2011c0ce96659d5/.pre-commit-config.yaml#L46.
It is easy to enable docker for pre-commit jobs (https://gitlab.developers.cam.ac.uk/uis/devops/infra/terraform/gcp-cloud-run-app/-/blob/b2ede128689ccf9d92b65b897b7429aac640cac8/.gitlab-ci.yml#L11) using configuration like the following:
pre-commit:
services:
- docker:24-dind
before_script:
- apk add docker
variables:
# It's worth reading https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300 for the reason
# for disabling TLS.
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
A job using this config can be seen at https://gitlab.developers.cam.ac.uk/uis/devops/infra/terraform/gcp-cloud-run-app/-/jobs/1287920.
Since there's no harm in enabling docker for existing configurations, they just won't use it, add the config snippet above directly to the pre-commit job.