Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 907
Nirgn Avatar asked Mar 07 '16 06:03

Nirgn


1 Answers

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 seds). 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.

like image 112
TWiStErRob Avatar answered Oct 26 '22 05:10

TWiStErRob