Run node.js database migrations on Google Cloud SQL during Google Cloud Build

后端 未结 5 1705
我寻月下人不归
我寻月下人不归 2020-12-16 01:45

I would like to run database migrations written in node.js during the Cloud Build process.

Currently, the database migration command is being executed but it seems

5条回答
  •  攒了一身酷
    2020-12-16 01:53

    As of tag 1.16 of gcr.io/cloudsql-docker/gce-proxy, the currently accepted answer no longer works. Here is a different approach that keeps the proxy in the same step as the commands that need it:

      - id: cmd-with-proxy
        name: [YOUR-CONTAINER-HERE]
        timeout: 100s
        entrypoint: sh
        args:
          - -c
          - '(/workspace/cloud_sql_proxy -dir=/workspace -instances=[INSTANCE_CONNECTION_NAME] & sleep 2) && [YOUR-COMMAND-HERE]'
    

    The proxy will automatically exit once the main process exits. Additionally, it'll mark the step as "ERROR" if either the proxy or the command given fails.

    This does require the binary is in the /workspace volume, but this can be provided either manually or via a prereq step like this:

      - id: proxy-install
        name: alpine:3.10
        entrypoint: sh
        args:
          - -c
          - 'wget -O /workspace/cloud_sql_proxy https://storage.googleapis.com/cloudsql-proxy/v1.16/cloud_sql_proxy.linux.386 &&  chmod +x /workspace/cloud_sql_proxy'
    

    Additionally, this should work with TCP since the proxy will be in the same container as the command.

提交回复
热议问题