Travis-CI: docker image as build environment

人盡茶涼 提交于 2019-12-07 05:25:29

问题


In Travis CI is it possible to run the build process from inside a docker container?

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?


回答1:


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.

Example:

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:

#!/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/



来源:https://stackoverflow.com/questions/38133107/travis-ci-docker-image-as-build-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!