Gitlab-ci 图像 docker 和 java/gradle

Gitlab-ci image with docker and java/gradle

我正在使用库“https://www.testcontainers.org/”将集成测试包含到我的应用程序中。

此库需要 docker 环境才能 运行 “gradlew test” 命令。

您如何在 gitlab-ci.yml 中使用 docker 图像(包括 docker 和 Gradle)?

这看起来像 2020 年的 Christos Sotiriou described in "Your Private CI/CD using self-hosted GitLab and Docker"。

它涉及一个 GitLab runner:

A GitLab runner has many modes it can operate, which represent how the build will be performed. Among other modes, there is support for spawning Kubernetes pods, or Docker containers to perform builds.

For the sake of simplicity, we will use the plain docker mode, which will spawn a new container with an image of your choice (determined by your Dockerfile)

Run the following to your terminal:

docker run -d --name gitlab-runner --restart always \
 -v /srv/gitlab-runner/config:/etc/gitlab-runner \
 -v /var/run/docker.sock:/var/run/docker.sock \
 gitlab/gitlab-runner:latest

并且:

You can configure your runner to use the host's docker when executing the Dockerfile commands.
You can do that by configuring the gitlab-runner configuration to use the host docker.

这涉及一些安全风险,但请检查此选项是否允许您在 gitlab-ci.yml.

中使用 docker 命令时使用您想要的图像