drm_hwcomposer: CI: publish docker image to local container registry

drm_hwcomposer provides a .ci/Dockerfile which can be used as a base
image to rebuild drm_hwcomposer.
Unfortunetly, the CI stages (build, tidy, style) do not use this
container image. Instead, it re-installs all the dependencies for
each stage.

To use this container image, we should also build it via the CI.

Add a new build stage to build the container and publish it to the
local (gitlab-provided) docker registry.

This way, it can be reused by the other build stages.

Note: as documented in [1], this requires that the configured Gitlab
runner can run docker in privileged mode.

[1] https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bdbb8be..30ebfd5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,6 +7,7 @@
 
 variables:
   DEBIAN_FRONTEND: noninteractive
+  DOCKER_IMAGE_TAG: $CI_REGISTRY_IMAGE:latest
 
 before_script:
   - apt-get --quiet update --yes >/dev/null
@@ -15,10 +16,26 @@
   - apt-get --quiet install --yes python3-mako python3-jinja2 python3-ply python3-yaml >/dev/null
 
 stages:
+  - build-container
   - build
   - tidy
   - style
 
+build-container:
+  stage: build-container
+  image: docker:27.0.3
+  services:
+    - docker:27.0.3-dind
+  variables:
+    DOCKER_TLS_CERTDIR: ""
+  before_script:
+    - echo "$CI_JOB_TOKEN" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
+  script:
+    - docker build -t $DOCKER_IMAGE_TAG -f .ci/Dockerfile .
+    - docker push $DOCKER_IMAGE_TAG
+  after_script:
+    - docker logout
+
 build:
   stage: build
   script: