google-app-engine - 问:如何从 Travis 部署到 Google Cloud Build?
问题描述
我在 Google Cloud Build 上有一个触发器,用于构建 docker 映像并将其部署到 Container Registry,并且我有一个 Travis CI 来运行测试。我的目的是以Travis 的方式连接它们首先运行测试,当它完成后,当然所有测试都通过了,它会将其部署到 Google Cloud,Cloud Build 将完成 docker build 和其余工作。
目前,我有一个如下所示的 travis.yml:
language: csharp
mono: none
dotnet: 3.1.202
sudo: required
addons:
apt:
packages:
- dotnet-sdk-3.0
before_install:
- openssl aes-256-cbc -K $encrypted_a3c2492b5906_key -iv $encrypted_a3c2492b5906_iv -in gce.json.enc -out gce.json -d
install:
- dotnet restore OnlineRetailer.sln
branches:
only:
- Testing
script:
- dotnet build OnlineRetailer.sln
- dotnet test TestCore/TestCore.csproj
deploy:
provider: gae
project: resolute-land-274909
keyfile: gce.json
我添加了在 Google 服务密钥加密之后得到的 OpenSSL 行。它gce.json.enc
也在 GitHub 上,所以我想 Travis 应该会看到这个文件。一件奇怪的事情:如果我的 travis 文件包含 deploy 字段,那么 Travis 不会做任何事情。甚至没有注意到变化。
我遵循了这 3 种不同的描述:
https://docs.travis-ci.com/user/deployment/google-app-engine/
https://cloud.google.com/solutions/continuous-delivery-with-travis- ci
https://unhashable.com/continuous-deployment-to-google-app-engine-using-travis-ci/
他们都没有以某种方式为我工作。
我错过了什么,或者做错了什么?任何建议都非常受欢迎!
编辑:
或者如果我不能以这种方式解决,有什么办法可以在 Google Cloud 上拥有一个完全正常工作的 CI/CD 管道?
我知道触发器应该像 CD,但我找不到有关如何在 Google Cloud 上设置 CI 的适当文档。
更新:
昨天,我设法用 .travis.yml 文件中的 deploy 字段点击 Travis,但是当它点击 CI 中的- openssl aes256-cbc...
命令时before_install
失败。正如我所看到的,由于 Windows 加密方法,这自 2016 年以来一直是一个大问题。解决方案是设置一个 Linux VM 并在那里进行文件加密,然后它可能会工作。所以我放弃了 Travis CI-Google Build 组合。
我宁愿在 Google Build 上完成整个 CI/CD。这是我目前正在使用的 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
云源存储库树
我非常确定测试步骤不正确-我在论坛上找到了该代码。我的目标是:运行测试,如果测试失败,整个过程应该停止,所以它会构建一个新的 docker 镜像并将其推送到 Container Registry。
你能给我一些帮助吗,如何在测试步骤中编写这个参数?
解决方案
推荐阅读
- sql-server - SQL FOR XML PATH 返回“非法名称字符”错误
- java - Java 命令提示符命令抛出“没有这样的文件或目录”
- swift - CoreData 崩溃错误 Xcode 11 Beta, IOS 13 Beta
- knockout.js - 为什么我在 viewModel 中的函数在文档就绪时被调用?
- android - 如何忽略 android volley http 请求上的 ssl 错误?
- python - 查找数据帧是否是另一个数据帧的子集,同时忽略索引
- php - 无法将正确的“语音文件(mp3)”插入数据库
- python - 根据其他数据帧中的索引列表从其他数据帧向数据帧添加新列
- react-native - 是否有某种方法可以在带有 expo 的暂停应用程序上运行任务?
- java - 简单的 ESAPI 目录路径验证示例不起作用