ci: 追加 circleci 配置
This commit is contained in:
parent
8cf7f956d6
commit
d2be34bc61
116
.circleci/config.yml
Normal file
116
.circleci/config.yml
Normal file
@ -0,0 +1,116 @@
|
||||
version: 2.1
|
||||
orbs:
|
||||
aws-ecr: circleci/aws-ecr@7.0.0
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
machine:
|
||||
image: ubuntu-2204:current
|
||||
resource_class: medium
|
||||
parameters:
|
||||
docker-tag:
|
||||
type: string
|
||||
path:
|
||||
type: string
|
||||
repo:
|
||||
type: string
|
||||
dockerfile:
|
||||
type: string
|
||||
steps:
|
||||
- aws-ecr/build-and-push-image:
|
||||
checkout: true
|
||||
account-url: AWS_ECR_ACCOUNT_URL
|
||||
aws-access-key-id: AWS_ACCESS_KEY_ID
|
||||
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
|
||||
create-repo: false
|
||||
dockerfile: <<parameters.dockerfile>>
|
||||
path: <<parameters.path>>
|
||||
region: AWS_REGION
|
||||
repo: <<parameters.repo>>
|
||||
tag: '<<parameters.docker-tag>>${CIRCLE_SHA1}'
|
||||
deploy:
|
||||
machine:
|
||||
image: ubuntu-2204:current
|
||||
resource_class: medium
|
||||
parameters:
|
||||
docker-tag:
|
||||
type: string
|
||||
path:
|
||||
type: string
|
||||
deploy-name:
|
||||
type: string
|
||||
deploy-namespace:
|
||||
type: string
|
||||
steps:
|
||||
- run:
|
||||
name: kubectl apply
|
||||
command: |
|
||||
CMD='/home/ubuntu/cluster-for-B/deploy.sh <<parameters.path>> <<parameters.docker-tag>>'${CIRCLE_SHA1}' <<parameters.deploy-name>> <<parameters.deploy-namespace>>'
|
||||
echo $CMD
|
||||
ssh ${USER_NAME}@${HOST_NAME} ${CMD}
|
||||
|
||||
# 判断正则表达式是否匹配,匹配规则从下面的示例中提取,示例:2023.wk42,2023.wk43
|
||||
if [[ "${CIRCLE_BRANCH}" =~ ^([0-9]{4}.wk[0-9]{2},?)+$ ]]; then
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"'${CIRCLE_USERNAME}' 触发了正式环境分支 '${CIRCLE_BRANCH}' 更新与部署"}}' https://open.larksuite.com/open-apis/bot/v2/hook/68004e4a-1381-4886-a982-cd77d5f2e6a1
|
||||
fi
|
||||
# 判断正则表达式是否匹配,匹配规则从下面的示例中提取,示例:canary.2023.wk42,canary.2023.wk43
|
||||
if [[ "${CIRCLE_BRANCH}" =~ ^canary.([0-9]{4}.wk[0-9]{2},?)+$ ]]; then
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"'${CIRCLE_USERNAME}' 触发了灰度环境分支 '${CIRCLE_BRANCH}' 更新与部署"}}' https://open.larksuite.com/open-apis/bot/v2/hook/68004e4a-1381-4886-a982-cd77d5f2e6a1
|
||||
fi
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
backend_build_and_push:
|
||||
jobs:
|
||||
- build-and-push:
|
||||
name: build-for-test
|
||||
context:
|
||||
- ecr-new
|
||||
path: .
|
||||
dockerfile: Dockerfile
|
||||
repo: catalog-agent
|
||||
docker-tag: ''
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
- deploy:
|
||||
name: deploy-for-test
|
||||
docker-tag: ''
|
||||
path: '/home/ubuntu/cluster-for-B/gbase-dev/catalog-agent/deploy.yaml'
|
||||
deploy-name: catalog-agent
|
||||
deploy-namespace: gbase-dev
|
||||
context:
|
||||
- ecr-new
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
requires:
|
||||
- build-for-test
|
||||
- build-and-push:
|
||||
name: build-for-prod
|
||||
context:
|
||||
- ecr-new
|
||||
path: .
|
||||
dockerfile: Dockerfile
|
||||
repo: catalog-agent
|
||||
docker-tag: ''
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
- deploy:
|
||||
name: deploy-for-prod
|
||||
docker-tag: ''
|
||||
path: '/home/ubuntu/cluster-for-B/default/catalog-agent/deploy.yaml'
|
||||
deploy-name: catalog-agent
|
||||
deploy-namespace: gbase-dev
|
||||
context:
|
||||
- ecr-new
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
requires:
|
||||
- build-for-prod
|
||||
Loading…
Reference in New Issue
Block a user