Development Tip

디버깅을 위해 travis-ci 빌드 환경을 재현하는 방법

yourdevel 2020. 11. 28. 12:34
반응형

디버깅을 위해 travis-ci 빌드 환경을 재현하는 방법


로컬 컴퓨터에서 재현 할 수없는 travis-ci에서 빌드 실패가 표시됩니다. travis-ci linux 빌드 환경과 동일한 VM을 설정하기위한 지침이 있습니까? travis-ci가 이미 새로운 버그를 공개하게되어 기쁩니다.하지만 디버그 코드를 추가하는 커밋을 보내서 디버그하는 것에 덜 흥분됩니다.


컨테이너 기반 빌드의 경우 이제 Docker 이미지를 로컬로 설정하는 방법에 대한 지침이 있습니다 .

불행히도 많은 단계가 여전히 수동입니다. 다음은이를 시작하고 실행하는 데 필요한 명령입니다.

# change the image according to the language chosen in .travis.yml
$ docker run -it -u travis quay.io/travisci/travis-jvm /bin/bash

# now that you are in the docker image, switch to the travis user
sudo su - travis

# Install a recent ruby (default is 1.9.3)
rvm install 2.3.0
rvm use 2.3.0

# Install travis-build to generate a .sh out of .travis.yml
cd builds
git clone https://github.com/travis-ci/travis-build.git
cd travis-build
gem install travis
travis # to create ~/.travis
ln -s `pwd` ~/.travis/travis-build
bundle install

# Create project dir, assuming your project is `me/project` on GitHub
cd ~/builds
mkdir me
cd me
git clone https://github.com/me/project.git
cd project
# change to the branch or commit you want to investigate
travis compile > ci.sh
# You most likely will need to edit ci.sh as it ignores matrix and env
bash ci.sh

나는 지금 같은 문제에 직면하고 있습니다. 전에는 ssh를 통해 VM에 로그인 할 수있는 CircleCI를 사용했지만 Travis-CI VM에서는 작동하지 않습니다.

Travis-Cookbooks 를 통해 Travis- ci VM 복제를 설정하여 (특정 지점까지) 디버그 할 수있었습니다 . 이 저장소를 복제하기 전에 먼저 VirtualBoxVagrant 를 컴퓨터에 설치해야 합니다.

Travis-Cookbooks를 복제했으면 폴더를 열고 command prompt | terminal을 실행 하고 vagrant up. Vagrant가 머신에서 VM 설정을 마치면 (시간이 오래 걸릴 수 있음),를 실행하여 ssh를 통해 연결할 수 있습니다 vagrant ssh.

거기에서 자신의 저장소를 복제 (또는 코드를 VM에 복사)하고 .travis.yml파일 의 단계를 적용해야 합니다.


당신은 사용할 수 트래비스 빌드 (당신이 그것을 배치했습니다 의미 라이브러리입니다 ~/.travis/쉘 기반의 빌드 스크립트를 생성하는)를 ( travis compile) 다음 SSH를 사용하여 VM에 업로드하고 실행할 수있다.

아래 단계는 올바른 경로로 이동하기위한 지침 일뿐입니다 (누락 된 항목이 있으면 알려주세요).

Docker

컨테이너를 실행하는 예제 명령 ( Docker Hub 에서 찾을 수 있음 ) :

docker run -it travisci/ubuntu-ruby:18.04 /bin/bash

컨테이너를 실행하고 저장소를 복제 한 다음 수동으로 테스트하십시오.

참조 : 컨테이너 기반 Docker 이미지를 로컬로 실행

SSH 액세스

답변을 확인하십시오 . 기본적으로 바운스 호스트를 설정 한 다음 SSH 터널을 실행하도록 빌드를 구성해야합니다.

다음은 그 예입니다 .travis.yml.

sudo: required
dist: trusty

language: python
python: "2.7"

script:
- echo travis:$sshpassword | sudo chpasswd
- sudo sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
- sudo service ssh restart
- sudo apt-get install sshpass
- sshpass -p $sshpassword ssh -R 9999:localhost:22 -o StrictHostKeyChecking=no travisci@$bouncehostip

로컬 설정

다음은 로컬 환경에서 테스트하는 단계입니다.

cd ~
git clone https://github.com/travis-ci/travis-build.git
ln -s ~/travis-build/ ~/.travis/travis-build
sudo gem install bundler
bundle install --gemfile ~/.travis/travis-build/Gemfile
cd repo-dir/
travis login -g <github_token>
vim .travis.yaml
travis lint # to validate script
travis compile # to transform into shell script

Vagrant/VM

After you did travis compile which would produce the bash script as result of your .travis.yml, you can use use vagrant to run this script into virtualized environment using provided Vagrantfile and the following steps:

vagrant up
vagrant ssh
cd /vagrant
bundle exec rspec spec

You probably need to install more tools in order to test it.


Here is some git hint which avoids you to generates unnecessary commits when doing trial & errors commits for Travis CI testing:

  1. Fork the repo (or use separate branch).
  2. After initial commit, keep adding --amend to replace your previous commit:

    git commit --amend -m 'Same message.' -a
    
  3. Push the amended commit by force (e.g. into already opened PR):

    git push fork -f
    
  4. Now Travis CI would re-check the same commit over and over again.


See also: How to run travis-ci locally.


Eregon's answer failed for me at travis compile, there error looks like:

/home/travis/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- travis/support (LoadError)

I got it working with the following adjustments: (Adjustments marked with # CHANGED. I'm using the node environment)

# change the image according to the language chosen in .travis.yml
# Find images at https://quay.io/organization/travisci
docker run -it quay.io/travisci/travis-node-js /bin/bash

# now that you are in the docker image, switch to the travis user
su travis

# Install a recent ruby (default is 1.9.3) to make bundle install work
rvm install 2.3.0 
rvm use 2.3.0

# Install travis-build to generate a .sh out of .travis.yml
sudo mkdir builds         # CHANGED
cd builds
sudo git clone https://github.com/travis-ci/travis-build.git
cd travis-build
gem install travis
travis # to create ~/.travis
ln -s `pwd` ~/.travis/travis-build
bundle install
bundler add travis        # CHANGED
sudo mkdir bin            # CHANGED
sudo chmod a+w bin/       # CHANGED
bundler binstubs travis   # CHANGED

# Create project dir, assuming your project is `me/project` on GitHub
cd ~/builds
mkdir me
cd me
git clone https://github.com/me/project.git
cd project
# change to the branch or commit you want to investigate
~/.travis/travis-build/bin/travis compile > ci.sh # CHANGED
# You most likely will need to edit ci.sh as it ignores matrix and env
# In particular I needed to edit --branch=’’ to the branch name
bash ci.sh

참고URL : https://stackoverflow.com/questions/29753560/how-to-reproduce-a-travis-ci-build-environment-for-debugging

반응형