简体   繁体   English

带有 docker 和 java/gradle 的 Gitlab-ci 图像

[英]Gitlab-ci image with docker and java/gradle

I'm including an integration test into my application using library "https://www.testcontainers.org/".我使用库“https://www.testcontainers.org/”将集成测试包含到我的应用程序中。

This library need a docker environment to run "gradlew test" command.这个库需要一个 docker 环境来运行“gradlew test”命令。

How would you use a docker image (which include docker and Gradle) in a gitlab-ci.yml ?您将如何在gitlab-ci.yml中使用 docker 图像(包括 docker 和 Gradle)?

That looks like what Christos Sotiriou described in " Your Private CI/CD using self-hosted GitLab and Docker " in 2020.这看起来就像Christos Sotiriou在 2020 年“使用自托管 GitLab 和 Docker 的私人 CI/CD ”中所描述的。

It involves a GitLab runner:它涉及一个 GitLab 跑步者:

A GitLab runner has many modes it can operate, which represent how the build will be performed.一个 GitLab 运行器有许多它可以操作的模式,代表构建将如何执行。 Among other modes, there is support for spawning Kube.netes pods, or Docker containers to perform builds.在其他模式中,支持生成 Kube.netes pod 或 Docker 个容器来执行构建。

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)为了简单起见,我们将使用普通的 docker 模式,这将生成一个包含您选择的图像的新容器(由您的 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

And:和:

You can configure your runner to use the host's docker when executing the Dockerfile commands.您可以将运行器配置为在执行 Dockerfile 命令时使用主机的 docker。
You can do that by configuring the gitlab-runner configuration to use the host docker.您可以通过将 gitlab-runner 配置配置为使用主机 docker 来实现。

That involves some security risk, but check if this option would allow you to use the image you want, while using docker commands in your gitlab-ci.yml .这涉及一些安全风险,但请检查此选项是否允许您使用所需的图像,同时在gitlab-ci.yml中使用 docker 命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM