Skip to content

Instantly share code, notes, and snippets.

@apstndb
Last active January 10, 2023 22:22
Show Gist options
  • Save apstndb/f362881ac2335f10a5ebe5456e5c4cec to your computer and use it in GitHub Desktop.
Save apstndb/f362881ac2335f10a5ebe5456e5c4cec to your computer and use it in GitHub Desktop.
Datastore Emulator on Cloud Build
steps:
# Cloud Build uses cloudbuild network
# https://cloud.google.com/cloud-build/docs/overview#build_configuration_and_build_steps
- name: gcr.io/cloud-builders/docker
args: ['run', '-d', '--network=cloudbuild', '--name=cds-emulator', 'google/cloud-sdk:248.0.0', 'gcloud', 'beta', 'emulators', 'datastore', 'start', '--host-port=0.0.0.0:8081']
- name: jwilder/dockerize:0.6.1
args: ['dockerize', '-timeout=60s', '-wait=tcp://cds-emulator:8081']
- name: google/cloud-sdk:248.0.0
env:
- DATASTORE_EMULATOR_HOST=cds-emulator:8081
args: ['sh', '-c', 'curl $${DATASTORE_EMULATOR_HOST}/v1/projects/example-project/indexes']
# for cloud-build-local
- name: gcr.io/cloud-builders/docker
args: ['rm', '--force', 'cds-emulator']
# it is not success because docker stopped step returns 137
steps:
- name: google/cloud-sdk:248.0.0
args: ['gcloud', 'beta', 'emulators', 'datastore', 'start', '--host-port=0.0.0.0:8081']
- name: jwilder/dockerize:0.6.1
id: dockerize
args: ['dockerize', '-timeout=60s', '-wait=tcp://step_0:8081']
waitFor: ['-']
- name: gcr.io/cloud-builders/docker
args: ['ps']
waitFor: ['dockerize']
- name: google/cloud-sdk:248.0.0
id: main
env:
- DATASTORE_EMULATOR_HOST=step_0:8081
args: ['sh', '-c', 'curl $${DATASTORE_EMULATOR_HOST}/v1/projects/example-project/indexes']
waitFor: ['dockerize']
- name: gcr.io/cloud-builders/docker
env:
- DATASTORE_EMULATOR_HOST=step_0:8081
args: ['stop', "step_0"]
waitFor: ['main']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment