Skip to content

A docker container to run goose database migrations

License

Notifications You must be signed in to change notification settings

cstroe/docker-goose

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-goose

This image allows you to run your Goose migrations from a Docker container.

Use

  • Create a Dockerfile in the directory that has your dbconf.yml

    • TIP: Your dbconf.yml is a lot more useful if it uses environment variables that you can set when you run the migration. For example, this should work for any postgres installation:
      default:
          driver: postgres
          open: $DATABASE_URL
      
  • Your Dockerfile should contain FROM cstroe/docker-goose:latest. Most won't need anything more.

  • Build and run your new container. The Docker engine will ADD your dbconf.yml and migrations directory using the ONBUILD triggers, then execute goose up. You can pass a command to execute something other than up.

Configuration

The following environment variables can be passed to the container:

  • GOOSE_ENV - customizes the goose -env flag value. Defaults to default.
  • DEBUG - if this environment variable is defined, print values of environment variables.

Example

Given a project with a db directory at the root of the project containing SQL migration scripts and the following dbconf.yml:

myenv:
    driver: mysql
    open: myuser:mypass@tcp(${DB_URL})/mydb

And the following Dockerfile-goose:

FROM cstroe/docker-goose:latest

And a docker-compose.yml file similar to this:

version: "2.4"

services:
  db:
    <... your database container here ...>

  goose:
    build:
      dockerfile: ./Dockerfile-goose
      context: .
    environment:
      DATABASE_URL: db:3306
      GOOSE_ENV: myenv
    depends_on:
      db:
        condition: service_healthy

Then run:

docker-compose up -d --build

That will start the database and run the migrations.

Links

About

A docker container to run goose database migrations

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dockerfile 54.4%
  • Shell 35.1%
  • Makefile 10.5%