Run a migration
This job runs a migration against a private Cloud SQL instance:my-project, my-db, the service account, and ./migrate up with your own.
Setup creates the provider, the service account, and the variables that the job uses.
The run command runs with bash:
- It gets the local address in
BQTO_HOSTandBQTO_PORT, andPGHOSTandPGPORTfor Cloud SQL and AlloyDB. - The step fails when the command fails.
- bqto deletes the bastion VM when the command ends.
Use the session in later steps
Withoutrun, the step ends when the session is ready. Later steps of the same job can use the session:
BQTO_HOST and BQTO_PORT, and PGHOST and PGPORT for Cloud SQL and AlloyDB.
The step also sets its outputs. At the end of the job, the action stops bqto, which
deletes the bastion VM.
The session listens on 127.0.0.1 of the runner:
- Steps of the same job can reach it. Another job must run the action itself.
services:containers anduses: docker://steps cannot reach it.- In a job with
container:, the session runs inside that container. The image needs gcloud 550.0.0 or later.
Requirements
- A Linux runner, amd64 or arm64, that supports
node24actions. - gcloud 550.0.0 or later. GitHub-hosted Ubuntu runners have it. On other runners,
google-github-actions/setup-gcloudinstalls it. google-github-actions/authwithservice_account, thengoogle-github-actions/setup-gcloud, before this action. Workload Identity Federation without a service account does not work with bqto.- The APIs, the firewall rule for IAP, and the roles that bqto needs in your project. See First connection.
Setup
Someone who can grant IAM roles in the project does this once. The provider below gives a token only to theproduction environment of .github/workflows/deploy.yml, run from main of your
repository. Change the condition to match your own workflow.
REPO back from GitHub, because the condition compares names case-sensitively.
After you rename the repository, update the condition and the binding.
Roles
Give the service account the minimal custom role of bqto. Limit it to VMs and disks namedbqto-* with the condition in
Narrowing the grant. Save the role as bqto-role.yaml and
the condition as bqto-condition.yaml. Then run:
roles/editor.
Repository settings
- Environments: create
production, with required reviewers and deployments limited tomain. PutDB_PASSWORDin its secrets. - Secrets and variables, Actions, Variables: set
WIF_PROVIDERtoprojects/NUMBER/locations/global/workloadIdentityPools/github-deploy/providers/github.
Inputs
All inputs are optional. Setinstance, or with bqto Pro, profile or stack.
The action always passes
--no-input. When runner debug logging is on, it also passes --debug.
Outputs
The action sets outputs only withoutrun. They describe the first service of the session.
sessions has one entry for each service.
To read one field of
sessions, use an expression such as
fromJSON(steps.db.outputs.sessions)[0].tls.
bqto Pro
This section needs bqto Pro.
edition: pro, the action runs the bqto Pro build that it carries. Save the key of a bqto Pro
seat as a repository or organization secret, and pass it in license-key:
- In CI, the key of a seat works in every job and repository of your organization. It does not take one of the computers of the seat.
- The action hides the key in the log. The command in
runand later steps do not get the key in their environment. - Without a key, or if bqto Pro cannot use the key, the job runs as the free bqto. A Pro feature then shows the reason.
- Cloud Run, Managed Kafka, and Memorystore clusters go through a SOCKS5 proxy. With
run, the command getsALL_PROXYandHTTPS_PROXY. Withoutrun, later steps getBQTO_PROXY, and theproxyoutput issocks5. - Profiles and stacks come from the
configfile in your repository, which holds no secrets. To use several services, leave outrunand use the session in later steps. - With
run, the action refuses--web, because bqto prints the secret of the web proxy. Withoutrun, the action masksweb_tokenin the log.
Security
- The job needs no service account key. It signs in with Workload Identity Federation.
- bqto deletes the bastion VM when the command ends, when the job ends, and when someone
cancels the job. If the runner kills bqto first, Compute Engine deletes the VM when
durationruns out. Keepdurationas short as the job allows. - Every port that bqto opens listens on
127.0.0.1. On a self-hosted runner that runs several jobs on one machine, another job can use your session. Use runners that run one job for each VM.
v1.x.y tag. The v1 tag moves to the newest v1.x.y release. A change that
can break a working workflow gets v2.