Skip to content

Commit

Permalink
Make the docker-compose env work as a dev environment
Browse files Browse the repository at this point in the history
* Mount the app directory into the container
* Setup the env files on start
* Seed if the sqllite db file is missing
  • Loading branch information
russell committed Aug 22, 2018
1 parent 668c536 commit 92e1118
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ services:
image: zendesk/samson:latest
ports:
- "3000:9080"
volumes:
- .:/app/
environment:
DATABASE_URL: "sqlite3://db/development.sqlite"
DATABASE_URL: "sqlite3:///app/db/development.sqlite3"
RAILS_LOG_TO_STDOUT: 1
# to use .env.virtualbox with 192.168.42.45 host prefix ./bin/decode_dot_env .env.virtualbox && source <(sed -E -n 's/[^#]+/export &/ p' .env.virtualbox) &&
command: ["bash", "-c", "rake db:setup && bundle exec puma -C config/puma.rb"]
command: ["./script/docker_dev_server"]
3 changes: 2 additions & 1 deletion docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ docker-compose up
open http://localhost:3000
```

The local project directory will be mounted into the container, so your changes will be reflected immediately by the server.
When running on virtual the `3000` port forwarding should be configured in virtualbox (Settings -> Network -> Advanced -> Port Forwarding).
When running on virtual `192.168.42.45` use `.env.virtualbox` from `docker-compose.yml`.
When running on neither localhost nor `192.168.42.45` create your own credentials and load them from `docker-compose.yml`.
Expand Down Expand Up @@ -42,7 +43,7 @@ Set up a production block in database.yml with the settings to connect to your D

## Webserver

Configure `config/puma.rb` as you need. See [puma's documentation](https://github.com/puma/puma/) for details.
Configure `config/puma.rb` as you need. See [puma's documentation](https://github.com/puma/puma/) for details.
You can start the server using this file by doing `bundle exec puma -C config/puma.rb`.
To restart the server use `kill -USR1 <pid>` which makes it restart without losing any downtime (lost requests).

Expand Down
17 changes: 17 additions & 0 deletions script/docker_dev_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e

bundle install --local --quiet --jobs 4 || bundle check

if [ ! -f .env ]; then
cp .env.bootstrap .env
# to use .env.virtualbox with 192.168.42.45 host prefix ./bin/decode_dot_env .env.virtualbox && source <(sed -E -n 's/[^#]+/export &/ p' .env.virtualbox) &&
./bin/decode_dot_env .env
fi

if [ -f db/development.sqlite3 ]; then
bundle exec rake db:migrate
else
bundle exec rake db:setup
fi

exec bundle exec puma -C config/puma.rb

0 comments on commit 92e1118

Please sign in to comment.