gpt4 book ai didi

.net - 问:如何配置cloudbuild.yaml以运行测试?

转载 作者:行者123 更新时间:2023-12-02 19:18:10 29 4
gpt4 key购买 nike

我想在GCP上建立一个完全自动化的CI / CD管道。在Cloud Build中,我已经有了一个cloudbuild.yaml,它可以构建Dockerfile并将构建的Docker镜像推送到Container Registry。但是,在构建Dockerfile之前,我找不到运行xUnit测试的解决方案,并且如果任何测试失败,则Cloud Build不应构建Dockerfile并退出并返回错误/异常。

我目前正在使用的cloudbuild.yaml:

steps:
- name: gcr.io/cloud-builders/dotnet
entrypoint: 'bash'
args:
- '-c'
- |
dotnet test --no-build -c ${_BUILD_CONFIG} $REPO_NAME\\TestCore
id: Test
- name: gcr.io/cloud-builders/docker
args:
- build
- '-t'
- '$_IMAGE_NAME:$COMMIT_SHA'
- .
- '-f'
- $_DOCKERFILE_NAME
dir: $_DOCKERFILE_DIR
id: Build
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_IMAGE_NAME:$COMMIT_SHA'
id: Push
- name: gcr.io/cloud-builders/gke-deploy
args:
- prepare
- '--filename=$_K8S_YAML_PATH'
- '--image=$_IMAGE_NAME:$COMMIT_SHA'
- '--app=$_K8S_APP_NAME'
- '--version=$COMMIT_SHA'
- '--namespace=$_K8S_NAMESPACE'
- '--label=$_K8S_LABELS'
- '--annotation=$_K8S_ANNOTATIONS,gcb-build-id=$BUILD_ID'
- '--create-application-cr'
- >-
--links="Build
details=https://console.cloud.google.com/cloud-build/builds/$BUILD_ID?project=$PROJECT_ID"
- '--output=output'
id: Prepare deploy
- name: gcr.io/cloud-builders/gsutil
args:
- '-c'
- |-
if [ "$_OUTPUT_BUCKET_PATH" != "" ]
then
gsutil cp -r output/suggested gs://$_OUTPUT_BUCKET_PATH/config/$_K8S_APP_NAME/$BUILD_ID/suggested
gsutil cp -r output/expanded gs://$_OUTPUT_BUCKET_PATH/config/$_K8S_APP_NAME/$BUILD_ID/expanded
fi
id: Save configs
entrypoint: sh
- name: gcr.io/cloud-builders/gke-deploy
args:
- apply
- '--filename=output/expanded'
- '--cluster=$_GKE_CLUSTER'
- '--location=$_GKE_LOCATION'
- '--namespace=$_K8S_NAMESPACE'
id: Apply deploy
images:
- '$_IMAGE_NAME:$COMMIT_SHA'
options:
substitutionOption: ALLOW_LOOSE
substitutions:
_IMAGE_NAME: gcr.io/resolute-land-274909/github_nagydominik_onlineretailer_partial
_GKE_LOCATION: europe-west3-a
_K8S_NAMESPACE: default
_OUTPUT_BUCKET_PATH: resolute-land-274909_cloudbuild/deploy
_K8S_APP_NAME: productapi
_K8S_LABELS: ''
_DOCKERFILE_DIR: ''
_DOCKERFILE_NAME: Dockerfile_productapi
_K8S_YAML_PATH: Kubernetes/productapi.yaml
_GKE_CLUSTER: onlineretailer-cluster
_K8S_ANNOTATIONS: gcb-trigger-id=cb8757e5-7dce-4aa9-bd43-6c4418f9dacb
tags:
- gcp-cloud-build-deploy
- $_K8S_APP_NAME

Cloud Source Repository tree

我知道“测试”步骤根本不起作用,只是失败了,我尝试了几种方法,但坦率地说,我不知道它的语法。

任何建议都非常欢迎!

最佳答案

可能的方法是使用docker-compose在构建步骤中运行测试,并从test_main服务(运行测试的服务容器)中获取退出代码。

- id: testingWithDockerCompose
name: 'docker/compose:1.22.0'
args: ['-f', 'docker-compose-test.yml', 'up', '--abort-on-container-exit', '--exit-code-from' , 'test_main']

要了解有关使用xUnit和 docker-compose进行测试的更多信息,请阅读中级文章 here

关于.net - 问:如何配置cloudbuild.yaml以运行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61999426/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com