我的CI中有2个工作:
我已经设置了一个工作流程,在该工作流程中,需要运行构建作业才能运行测试作业。我的问题是,我想使构建作业容器继续运行以进行测试,因为一旦作业成功,容器就会关闭,并且我无法通过测试作业容器来访问它。
我遇到的另一个查询是,即使我找到了一种方法来持久保存测试作业的构建容器映像,也如何在它们之间进行通信? CircleCi文档指出,主要容器可以访问同一作业中的辅助容器,但是关于如何从不同作业中访问容器(如果可能的话)则无济于事。
这是我的circleci配置(忽略我刚刚检查过某些部分的双//
):
version: 2.1
orbs:
aws-s3: circleci/aws-s3@1.0.11
jobs:
build:
working_directory: ~/FE
environment:
NODE_ENV: test
STAGE: test
docker:
- image: circleci/python:latest-node
steps:
- checkout
- run:
name: Update npm
command: sudo npm install -g npm@latest
- restore_cache:
key: v1-fe-dependency-cache-{{ checksum "package.json" }}
- run:
name: Install Dependencies
command: npm install
- save_cache:
key: v1-fe-dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: Run Frontend server
command: npm run start
background: true
- add_ssh_keys:
fingerprints:
- "xx:xx:xx"
- run:
name: Clone Backend
command: git clone git@github.com:<user_name>/BE.git ~/BE
- restore_cache:
key: v1-be-dependency-cache-{{ checksum "~/BE//requirements.txt" }}
- run:
name: Run Backend Server
command: |
cd ~/BE
source ./ci-deploy.sh
- save_cache:
key: v1-be-dependency-cache-{{ checksum "~/BE//requirements.txt" }}
paths:
- ~/BE//venv
test:
working_directory: ~/Automation
environment:
NODE_ENV: test
docker:
- image: circleci/node:latest-browsers
steps:
- run:
name: Add Github RSA Key To Known Hosts
command: |
mkdir ~/.ssh
touch ~/.ssh/known_hosts
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
- add_ssh_keys:
fingerprints:
- "xx:xx:xx"
- run:
name: Clone Automation
command: git clone git@github.com:<user_name>/Automation.git ~/Automation
- restore_cache:
key: v1-automation-dependency-cache-{{ checksum "package.json" }}
- run:
name: Install Dependencies
command: npm install
- save_cache:
key: v1-automation-dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: Test
command: npm test
deploy:
working_directory: ~/FE
docker:
- image: circleci/node:latest
environment:
S3_BUCKET_NAME: walty-presentation
steps:
- checkout
- run:
name: Install Dependencies
command: npm install
- run:
name: Build
command: npm run build
- aws-s3/sync:
from: build
to: 's3://${S3_BUCKET_NAME}'
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
aws-region: AWS_REGION
overwrite: true
workflows:
version: 2
build_and_test:
jobs:
- build
- test:
requires:
- build
- deploy:
requires:
- test
filters:
branches:
only:
- master
- develop
nightly:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- master
- develop
jobs:
- test