Phi*_*ien 7 gitlab gitlab-ci gitlab-ci-runner
我正在开发一个python项目并使用miniconda来管理我的环境.我使用GitLab进行CI以及以下运行器配置
stages:
- build
- test
build:
stage: build
script:
- if hash $HOME/miniconda/bin/conda 2>/dev/null;
then
export PATH="$HOME/miniconda/bin:$PATH";
else
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
fi
- conda update --yes conda
test:
stage: test
script:
- conda env create --quiet --force --file environment.yml
- source activate myenv
- nosetests --with-coverage --cover-erase --cover-package=mypackage --cover-html
- pylint --reports=n tests/test_final.py
- pep8 tests/test_final.py
- grep pc_cov cover/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
Run Code Online (Sandbox Code Playgroud)
我假设(错误地)我的build舞台将设置我可以运行我的test舞台的正确环境.看看这个问题和这个GitLab问题,我看到了
.gitlab-ci.yml中定义的每个作业都作为单独的构建运行(我们假设没有历史记录)
但是,在一个阶段将所有东西混为一谈的替代方案并不吸引人
stages:
- test
test:
stage: test
script:
- if hash $HOME/miniconda/bin/conda 2>/dev/null;
then
export PATH="$HOME/miniconda/bin:$PATH";
else
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
fi
- conda update --yes conda
- conda env create --quiet --force --file environment.yml
- source activate myenv
- nosetests --with-coverage --cover-erase --cover-package=mypackage --cover-html
- pylint --reports=n tests/test_final.py
- pep8 tests/test_final.py
- grep pc_cov cover/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
Run Code Online (Sandbox Code Playgroud)
我能想到的唯一另一个选择是将环境创建步骤放在before_script阶段,但在每个阶段之前不断重新创建相同的环境似乎是多余的.
tmt*_*tmt 10
工作的独立性是一种设计特征.您可能已经注意到GitLab的界面允许您重新运行单个作业,如果作业相互依赖则无法执行.
我不知道Miniconda的确切表现,但如果它在特定文件夹中构建虚拟环境,您可以使用缓存来保留作业之间这些文件夹的内容.但是,您不能完全依赖它,因为文档说明......
缓存是在尽力而为的基础上提供的,因此不要指望缓存总是存在.有关实施细节,请查看GitLab Runner.
考虑到您的工作绝对取决于正在构建的环境,您需要一种机制来检测(缓存)环境是否存在,并仅在需要时重新创建它.
我认为您正在尝试将环境设置和作业分开,因为它可以节省大量时间,以防您有一天同时运行不同的测试(同一阶段的作业并行运行).
小智 9
您可以将常用命令放在before_script下。它将应用于所有的子阶段。这样,您就不需要重复您的代码。
您可以使用类似以下内容:
stages:
- build
- test
- deploy
before_script:
- if hash $HOME/miniconda/bin/conda 2>/dev/null;
then
export PATH="$HOME/miniconda/bin:$PATH";
else
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
fi
- conda update --yes conda
build:
stage: build
script:
- << Your build script >>
test:
stage: test
script:
- conda env create --quiet --force --file environment.yml
- source activate myenv
- nosetests --with-coverage --cover-erase --cover-package=mypackage --cover-html
- pylint --reports=n tests/test_final.py
- pep8 tests/test_final.py
- grep pc_cov cover/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
deploy:
stage: deploy
before_script:
- << Override to global before_script >>
- << DO something else >>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9006 次 |
| 最近记录: |