简体   繁体   中英

Running Travis locally using docker

I'm trying to run travis build on my local machine using their docker images ( Their docker images ). Their instructions are here .

I was able to download and run the docker machine, I switched to travis user, and clone my repo. But I don't quite understand how to run the travis.yml file so that the build will start.

I already searched and try using travis-cli and travis-build but with no success. I'm open to suggestions about interacting with travis build (using the command line of course) before/while/after running travis ( for faster debugging ).

I managed to puzzle together a Dockerfile from various sources and some on my own. There are two images: one base for travis being available and one project specific for "org/repo" GitHub project (make sure occurrences are replaced with a real project name). It uses the local uncommitted repository version (hence the sed s). After travis-local-build is up and running ./build.sh will trigger a CI build similar to travis-ci.org.

Dockerfile.travis-local

#!docker build -f Dockerfile.travis-local -t travis-local .

FROM travisci/ci-amethyst:packer-1512508255-986baf0
USER travis

WORKDIR /home/travis
RUN git clone https://github.com/travis-ci/travis-build.git

WORKDIR travis-build
RUN bash -lc "gem install travis"
RUN bash -lc travis # to create ~/.travis
RUN ln -s $(pwd) ~/.travis/travis-build
RUN bash -lc "bundle install"
#RUN bash -lc "bundler add travis"
RUN bash -lc "bundler binstubs travis"
RUN echo alias travis="~/.travis/travis-build/bin/travis" >> ~/.bashrc

Dockerfile.travis-local-build

#!docker build -f Dockerfile.travis-local-build -t travis-local-build . && docker run -ti travis-local-build

FROM travis-local
USER travis

WORKDIR /home/travis/build
ADD --chown=travis . org/repo

WORKDIR org/repo
RUN chmod +x gradlew
# Alias not recognized, but in interactive mode `travis compile` works without path.
RUN bash -lc "~/.travis/travis-build/bin/travis compile --no-interactive > build.sh"
RUN sed -re 's/^.*travis_wait_for_network '\''.*$/echo DISABLED &/mg' build.sh --in-place
RUN sed -re 's/^.*apt-get update.*$/echo DISABLED &/mg' build.sh --in-place
RUN sed -re 's/^.*travis_cmd git.*(fetch|reset|checkout).*$/echo DISABLED &/mg' build.sh --in-place
RUN chmod +x build.sh

WORKDIR /home/travis/build
RUN sudo ln -s org/repo/build.sh build.sh
CMD ["bash"]

Disclaimer: I'm new to Docker, only been using it for a few hours, so I might have gotten some concepts wrong. Any pointers appreciated in comments.

I manage to find a sort of a solution with docker in Travis blog . I use docker to wrap the whole project and then tells Travis to download the docker image, run it, and run the tests.

In that way I can use my local container for fast debugging and know my environment is clean and if the tests work on the container they sure work on Travis (because he uses the same container as well, and the production uses it as well).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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