Skip to content

Instantly share code, notes, and snippets.

@selaromi
Last active June 26, 2017 08:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selaromi/edd01e20ef3aba1cb4d8 to your computer and use it in GitHub Desktop.
Save selaromi/edd01e20ef3aba1cb4d8 to your computer and use it in GitHub Desktop.
wercker.yml for Rails with Postgresql and DATABASE_URL (docker stack)

RAILS & POSTGRES WITH WERCKER AND DATABASE_URL

Basically, if you prefer to use DATABASE_URL in your application better than creating the whole database.yml thing, set the following ENV variable in your wercker app settings:

  • APP_POSTGRES_PASSWORD (required)
  • APP_POSTGRES_USER (optional)
  • APP_POSTGRES_DB (optional)
  • DATABASE_URL (value below)

name: DATABASE_URL

value (text):

postgres://$POSTGRES_ENV_POSTGRES_USER:$POSTGRES_ENV_POSTGRES_PASSWORD@$POSTGRES_PORT_5432_TCP_ADDR:$POSTGRES_PORT_5432_TCP_PORT/$POSTGRES_ENV_POSTGRES_DB

EXAMPLE

this is how I did it for my project with Rails-api, postgres, etc for wercker build (my wercker.yml):

box: ruby:2.2.2
services:
   - id: postgres
     env:
       POSTGRES_PASSWORD: $APP_POSTGRES_PASSWORD
       POSTGRES_USER: $APP_POSTGRES_USER
       POSTGRES_DB: $APP_POSTGRES_DB

build:
    steps:
        - bundle-install
        - script:
            name: create db
            code: bundle exec rake db:create RAILS_ENV=test
        - script:
            name: migrate db
            code: bundle exec rake db:migrate RAILS_ENV=test
        - script:
            name: rspec
            code: bundle exec rake spec RAILS_ENV=test
@hernandesbsousa
Copy link

Thanks, this gist was very helpful!

One thing I find out: if you're using POSTGRES_DB the create db task is made redundant, as the docker container creates it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment