是否可以从Cloud Build步骤启动PubSub仿真器 [英] Is it possible to start PubSub Emulator from Cloud Build step
问题描述
正如标题所述,我想知道是否可以从Cloud Build步骤中启动并使用pubsub仿真器?
As the title mentions, I would like to know if, from a Cloud Build step, I can start and use the pubsub emulator?
options:
env:
- GO111MODULE=on
- GOPROXY=https://proxy.golang.org
- PUBSUB_EMULATOR_HOST=localhost:8085
volumes:
- name: "go-modules"
path: "/go"
steps:
- name: "golang:1.14"
args: ["go", "build", "."]
# Starts the cloud pubsub emulator
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args: [
'-c',
'gcloud beta emulators pubsub start --host-port 0.0.0.0:8085 &'
]
- name: "golang:1.14"
args: ["go", "test", "./..."]
对于我需要的测试,它可以在本地运行,而不是使用云构建中的专用pubsub,而是要使用仿真器。
For a test I need it, it works locally and instead of using a dedicated pubsub from cloud build, I want to use an emulator.
谢谢
推荐答案
我找到了解决方法和有趣的git仓库,我想与您分享解决方案。
As I found a workaround and an interesting git repository, I wanted to share with you the solution.
根据需要,您需要 cloud-build.yaml
,您想添加启动仿真器的步骤:
As required, you need a cloud-build.yaml
and you want to add a step where the emulator will get launched:
options:
env:
- GO111MODULE=on
- GOPROXY=https://proxy.golang.org
- PUBSUB_EMULATOR_HOST=localhost:8085
volumes:
- name: "go-modules"
path: "/go"
steps:
- name: "golang:1.14"
args: ["go", "build", "."]
- name: 'docker/compose'
args: [
'-f',
'docker-compose.cloud-build.yml',
'up',
'--build',
'-d'
]
id: 'pubsub-emulator-docker-compose'
- name: "golang:1.14"
args: ["go", "test", "./..."]
如您所见,我运行了一个docker-compose命令,该命令实际上将启动模拟器。
As you can see, I run a docker-compose command which will actually start the emulator.
version: "3.7"
services:
pubsub:
# Required for cloudbuild network access (when external access is required)
container_name: pubsub
image: google/cloud-sdk
ports:
- '8085:8085'
command: ["gcloud", "beta", "emulators", "pubsub", "start", "--host-port", "0.0.0.0:8085"]
network_mode: cloudbuild
networks:
default:
external:
name: cloudbuild
设置容器名称以及网络很重要,否则您将无法从另一个云构建步骤访问pubsub模拟器。
It is important to set the container name as well as the network, otherwise you won't be able to access the pubsub emulator from another cloud build step.
这篇关于是否可以从Cloud Build步骤启动PubSub仿真器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!