https://github.com/travelaudience/docker-cloudsql-goose
Docker image for running goose transactions on a cloudsql database
https://github.com/travelaudience/docker-cloudsql-goose
cloudsql docker goose owner-det
Last synced: 10 months ago
JSON representation
Docker image for running goose transactions on a cloudsql database
- Host: GitHub
- URL: https://github.com/travelaudience/docker-cloudsql-goose
- Owner: travelaudience
- Created: 2020-09-16T09:02:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-08T18:37:48.000Z (about 1 year ago)
- Last Synced: 2024-11-08T19:45:53.340Z (about 1 year ago)
- Topics: cloudsql, docker, goose, owner-det
- Language: Shell
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# docker-cloudsql-goose
Docker image for running [goose ](https://github.com/pressly/goose) migrations on a cloudsql database
# Usage
## CircleCI
## Configuration (Local)
Parameters are passed as environment variables, so the image can easily be used from CircleCI (See below). For local development it is recommended to set up a `.env.local` file with the following contents:
```bash
# Contents of the service account json file. (put everything on 1 line. dot env files don't support multiline variables)
# https://cloud.google.com/iam/docs/creating-managing-service-account-keys
CLOUDSQL_PROXY_SA=SERVICE_ACCOUNT_SECRET_JSON
# The cloudsql instance you want to connect to
GCLOUD_SQL_INSTANCE=project:region:cloudsql_instance=tcp:localhost:port
# Goose & postgres connection configuration
POSTGRES_USER=postgres
POSTGRES_PASSWORD=XXXXXX
POSTGRES_PORT=5536
POSTGRES_DATABASE=goose_demo
GOOSE_DRIVER=postgres
```
## Build & Run (local)
```bash
# Build the image
docker build -t travelaudience/cloudsql-goose .
# For local executions we mount the goose migration folder
docker run --rm -it --name goose \
--env-file .env.local \
--mount type=bind,source="$(pwd)"/db/migrations,target=/db/migrations \
-u $(id -u ${USER}):$(id -g ${USER}) \
cloudsql-goose
# cd into the directory we mounted
cd migrations/
```
### Create a new sql migration
This might create the file as root on your host system
```bash
goose create sql
```
### Apply migrations
```bash
goose up
```
### Remove everything
```bash
goose reset
```