Travis-CI: docker image as build environment

徘徊边缘 提交于 2019-12-05 10:39:27

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/

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