我有一个 CircleCi 配置,我现在正在尝试并行运行我的测试,因为包含大约 2,000 个测试的测试套件目前大约需要 30 分钟。我想减少运行时间而不增加运行时间,resource_class
因为我认为不需要这样做(而且需要更多的积分)。
我有一个 docker 环境,我自己的 Dockerfile 托管在 GitHub 中,因此我的测试可以运行。pytest
我使用这个环境进行开发,因此如果没有构建我的 Dockerfile ,系统就无法运行。
我遇到的问题是定义我的jobs
,以便他们可以使用我构建的 docker 容器。例如,我想构建我的执行环境,然后将其用于测试,这样我就可以在配置中并行运行它们,如下所示,但这是无效的配置,因为执行程序没有正确定义,它只是显示更多-或-少我所追求的:
version: 2.1
executors:
dev-container:
machine: true
resource_class: medium
steps:
- checkout
# setup
- run:
no_output_timeout: 1h
name: NPM install and NPM Serve
background: true
command: npm install && npm run serve
- run:
no_output_timeout: 1h
name: Build Docker Dev
command: docker-compose build # build for dev, this allows local tests to run...
# normal setup for circleCI
- run:
name: Create Default Databases Needed for CircleCI Testing
command: docker-compose run --rm web sh -c "python manage.py create_default_databases_dev"
- run:
name: Initial Migration
command: docker-compose run --rm web sh -c "python manage.py migrate_all"
working_directory: ~/repo
jobs:
# docker_build:
# machine: true
# working_directory: ~/repo
# resource_class: medium
# steps:
# - checkout
# # setup
# - run:
# no_output_timeout: 1h
# name: NPM install and NPM Serve
# background: true
# command: npm install && npm run serve
# - run:
# no_output_timeout: 1h
# name: Build Docker Dev
# command: docker-compose build # build for dev, this allows local tests to run...
# # normal setup for circleCI
# - run:
# name: Create Default Databases Needed for CircleCI Testing
# command: docker-compose run --rm web sh -c "python manage.py create_default_databases_dev"
# - run:
# name: Initial Migration
# command: docker-compose run --rm web sh -c "python manage.py migrate_all"
testing:
executor: dev-container
parallelism: 4
steps:
# now testing...
- run:
name: Run All Back-End Tests
command: docker-compose run --rm web sh -c pytest -n auto -s
- run:
name: Application Create Tests (Front-End)
command: docker-compose run --rm web sh -c "npm test ExactEstate/static/js/vue/views/__tests__/application_create"
- run:
name: Dashboard Tests (Front-End)
command: docker-compose run --rm web sh -c "npm test ExactEstate/static/js/vue/views/__tests__/dashboard"
- run:
name: File Explorer Tests (Front-End)
command: docker-compose run --rm web sh -c "npm test ExactEstate/static/js/vue/views/__tests__/file_manager"
- run:
name: Prospects Tests (Front-End)
command: docker-compose run --rm web sh -c "npm test ExactEstate/static/js/vue/views/__tests__/prospects"
- store_test_results:
path: test-results
- store_artifacts:
path: test-results
staging_deploy:
executor: dev-container
steps:
# deploy to staging now...
- run:
background: true
name: Run Docker so it is quicker for FrontEnd Tests to access
command: docker-compose down && docker-compose up cypress
- run:
no_output_timeout: 1h
name: Deploy ExactEstate to Staging
command: |
ssh root@165.227.124.71 -i ~/.ssh/id_rsa "/deploy/deploy_site_staging.sh"
# front end e2e tests live on staging.exactestate.com with CYPRESS...
- run:
name: Login Tests E2E Cypress
# run all tests that have ".live.js" in them in the login folder
command: docker-compose run cypress --spec cypress/integration/login/*.live.js --browser chrome --headless
# we can now merge staging and production on GitHub
- run:
name: Merge Staging and Production
command: |
ssh root@321.45.555.321 -i ~/.ssh/id_rsa "/deploy/merge_staging_and_production.sh"
production_deploy:
executor: dev-container
steps:
# now deploy to production
- run:
no_output_timeout: 1h
name: Deploy ExactEstate
command: |
ssh root@123.45.555.123 -i ~/.ssh/id_rsa_root "/deploy/deploy_site.sh"
workflows:
staging:
jobs:
- testing:
filters:
branches:
only:
- staging
- staging_deploy:
requires:
- testing
filters:
branches:
only:
- staging
- production_deploy:
requires:
- staging_deploy
filters:
branches:
only:
- staging
我也试过用另一种方式写这个,我正在使用一份工作,但它似乎没有用,所以我觉得某种类型的执行者是要走的路,有人可以帮忙吗?