From d2be34bc61ce0b4327e3ff557cc2148da8004667 Mon Sep 17 00:00:00 2001 From: shuirong Date: Wed, 22 Oct 2025 17:53:00 +0900 Subject: [PATCH] =?UTF-8?q?ci:=20=E8=BF=BD=E5=8A=A0=20circleci=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .circleci/config.yml | 116 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..2189809 --- /dev/null +++ b/.circleci/config.yml @@ -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: <> + path: <> + region: AWS_REGION + repo: <> + 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 <> <>'${CIRCLE_SHA1}' <> <>' + 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 \ No newline at end of file