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
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
Thanks, this gist was very helpful!
One thing I find out: if you're using
POSTGRES_DB
thecreate db
task is made redundant, as the docker container creates it.