问题描述
在 Travis CI 中是否可以从Docker容器内部运行构建过程?
In Travis CI is it possible to run the build process from inside a docker container?
在这是默认设置。我们可以简单地在 .gitlab-ci.yml
中定义映像,然后所有构建/测试/部署将在该容器中运行。但是,特拉维斯(Travis)似乎对docker使用情况有完全不同的看法。如何在Travis中实现类似的行为?
In GitLab CI this is the default. We can simply define the image in .gitlab-ci.yml
then all the build/test/deploy will run inside that container. However, Travis seems to have totally different view about docker usage. How can I achieve a similar behavior in Travis?
推荐答案
事实证明,使用Travis-CI比起第一次出现要容易得多。您要做的就是使用 docker exec
调用编写常规的构建脚本。进行一些棘手的第三方服务集成可能需要专用的shell脚本,如下面的codecov.io示例中所示。
It turns out this is easier to do with Travis-CI than it first appears. All you have to do is write your normal build script using docker exec
calls. Doing some of the trickier third-party service integrations may require dedicated shell scripts, as in the codecov.io example below.
示例:
sudo: required
language: cpp
services:
- docker
before_install:
- docker pull user/build:latest
- docker run -it -d --name build user/build bash
- docker exec build git clone https://github.com/user/product.git
script:
- docker exec build cmake -H/product -B/_build
- docker exec build cmake --build /_build
- docker exec build cmake --build /_build --target documentation
- docker exec build cmake --build /_build --target run-tests
after_success:
- docker exec build bash /project/codecov.sh
codecov.sh:
codecov.sh:
#!/usr/bin/env bash
cd /project && \
bash <(curl -s https://codecov.io/bash) \
-f /_build/app.coverage.txt \
-t uuid-project-token \
-X gcov \
-X coveragepy \
-X search \
-X xcode \
-R /project \
-F unittests \
-Z
使用可以在此处找到此技术:
A real-life project using this technique can be found here: https://github.com/qbradq/tales-of-sosaria/tree/e28eb9877fd7071adae9ab03f40a82ea8317a7df
我在这里写了一篇有关整个过程的文章:
And I wrote an article about the whole process here: https://normanblancaster.wordpress.com/2017/01/31/leading-edge-c-build-environments-with-docker-and-travis-ci/
这篇关于Travis-CI:Docker映像作为构建环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!