首页 文章

使用docker在本地运行Travis

提问于
浏览
12

我正在尝试使用他们的docker图像(Their docker images)在我的本地计算机上运行travis构建 . 他们的指示是here .

我能够下载并运行docker机器,我切换到 travis 用户,并克隆我的repo . 但是我不太明白如何运行travis.yml文件以便开始构建 .

我已经搜索并尝试使用 travis-clitravis-build 但没有成功 . 在开始使用travis( for faster debugging )之前/之后/之后,我愿意接受有关与travis构建(当然使用命令行)交互的建议 .

2 回答

  • -4

    我设法将各种来源的Dockerfile和我自己的一些拼凑在一起 . 有两个图像:一个用于 travis 的基础和一个专用于"org/repo" GitHub项目的项目(确保将实例替换为实际项目名称) . 它使用本地未提交的存储库版本(因此为 sed ) . 在 travis-local-build 启动并运行后 ./build.sh 将触发类似于travis-ci.org的CI构建 .

    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"]
    

    免责声明:我是Docker的新手,只使用它几个小时,所以我可能会弄错一些概念 . 在评论中赞赏任何指针 .

  • 1

    我设法在Travis blog中找到了一个带有docker的解决方案 . 我使用docker来包装整个项目,然后告诉Travis下载docker镜像,运行它并运行测试 .

    通过这种方式,我可以使用我的本地容器进行快速调试,并且知道我的环境是干净的,如果测试在容器上工作,他们肯定可以使用Travis(因为他也使用相同的容器, 生产环境 也使用它) .

相关问题