Continuous integration 如何将CD与CircleCI集成?
我一直在关注很多关于使用Python的CI的教程,但这些教程似乎到此为止,很少进入CD的下一步。我也是唯一的开发者 我在Github上设置了一个项目,它在我的PC上本地运行,不是一个web应用程序。我已经将它连接到CircleCI for CI。这是我的Continuous integration 如何将CD与CircleCI集成?,continuous-integration,circleci,continuous-delivery,Continuous Integration,Circleci,Continuous Delivery,我一直在关注很多关于使用Python的CI的教程,但这些教程似乎到此为止,很少进入CD的下一步。我也是唯一的开发者 我在Github上设置了一个项目,它在我的PC上本地运行,不是一个web应用程序。我已经将它连接到CircleCI for CI。这是我的config.yml文件 version: 2 jobs: build: docker: - image: circleci/python:3.7 working_directory: ~
config.yml
文件
version: 2
jobs:
build:
docker:
- image: circleci/python:3.7
working_directory: ~/repo
steps:
# Step 1: obtain repo from GitHub
- checkout
- run:
name: install dependencies
command: |
sudo apt-get update
pip install -r requirements.txt
- run:
name: run tests
command: |
python -m pytest -v
一切都运行得很好,我收到CircleCI的一封电子邮件,当我在github上推到master时,它警告我构建失败,其中一个pytests失败
所以我的问题是,下一步是什么?我有一些想法,但老实说,我对其中任何一个都不确定
有人能在这里提供一些关于下一步的指导吗?目前您只有一个作业
构建
,因此您可以在作业部分下添加更多作业。因此,您在这里要做的是:
version: 2.1
jobs:
build:
docker:
- image: circleci/python:3.7
working_directory: ~/repo
steps:
# Step 1: obtain repo from GitHub
- checkout
- run:
name: install dependencies
command: |
sudo apt-get update
pip install -r requirements.txt
- run:
name: run tests
command: |
python -m pytest -v
test:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run: echo "do your test here"
build-prod:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run: echo "build your app"
push-to-dockerhub:
docker:
- image: circleci/python:3.7
steps:
- checkout
- setup_remote_docker # this is necessary to use docker daemon
- run: echo "do docker login and docker push here"
workflows:
build-and-push:
jobs:
- build
- test
requires:
- build
- build-prod
requires:
- test
- push-to-dockerhub
requires:
- build-prod
请确保仅当所需作业成功完成时,我们才使用requires
运行该作业
当然,我还没有测试过配置,但它就像上面的配置一样。这里有更多的配置文档,所以请仔细查看,以使其完美工作。
非常感谢。如果你不介意的话,我只有几个问题。1) Python中没有按需构建,因此省略这一点是否正确?2) 如果成功推送Dockerhub,Dockerhub上是否会自动下载代码以PROD?您可以根据需要更改图像-不确定是否是您要求的。只需更改配置并使用circleci cli进行验证。您不需要按下按钮来触发构建来验证配置。我也不知道你想为2做什么。。