Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Commit c5e3c6c

Browse files
committed
docker and docker compose support
Add Docker and Docker Compose support by adding `Dockerfile`s and a `docker-compose.yml`. The Docker setup is a little different for React/Webpacker apps and standard Rails app, so different files are copied depending on whether run with `--webpack=react` or not.
1 parent 55b3295 commit c5e3c6c

9 files changed

+129
-1
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ $ bin/yarn test
5151
- Add Variable.
5252
- Name the variable `PRONTO_GITHUB_ACCESS_TOKEN` with the value from the previous Personal Access Token.
5353

54+
# Usage with Docker
55+
56+
A `Dockerfile` and `docker-compose.yml` file are created by default. When run with `--webpack=react`,
57+
there are two `Dockerfile`s: one for the Rails server and one for the assets server.
58+
59+
To use Docker, run:
60+
61+
```sh
62+
docker-compose build
63+
```
64+
65+
then set up the the database:
66+
67+
```sh
68+
docker-compose run web rails db:create
69+
docker-compose run web rails db:migrate
70+
```
71+
72+
finally, start the server and visit `localhost:3000`:
73+
74+
```sh
75+
docker-compose up
76+
```
77+
5478
# Switching out Capybara Driver
5579
If you'd like to not run your tests headless, for example, to troubleshoot an issue and see what's on the screen, modify the `Capybara.javascript_driver` in `spec/rails_helper.rb` to use `:chome` instead of `:headless_chrome`. After the change, this line should look as follows:
5680

gnarly.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,24 @@ def modify_npm_scripts
213213
"Capybara.default_max_wait_time = 3\n"
214214
end
215215

216+
react = options[:webpack] == "react"
217+
218+
# Docker
219+
copy_file "templates/Dockerfile", "Dockerfile"
220+
221+
if react
222+
copy_file "templates/Dockerfile-assets", "Dockerfile-assets"
223+
copy_file "templates/.env.docker/.env.docker-webpack", ".env.docker"
224+
copy_file "templates/.env.docker-assets", ".env.docker-assets"
225+
copy_file "templates/docker-compose.yml/docker-compose-webpack.yml", "docker-compose.yml"
226+
else
227+
copy_file "templates/.env.docker/.env.docker-standard", ".env.docker"
228+
copy_file "templates/docker-compose.yml/docker-compose-standard.yml", "docker-compose.yml"
229+
end
230+
216231
# Retrieve all gems, set up git, display next steps
217232
after_bundle do
218-
if options[:webpack] == "react"
233+
if react
219234
install_js_deps
220235
add_js_files
221236
modify_npm_scripts

templates/.env.docker-assets

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WEBPACKER_DEV_SERVER_HOST=0.0.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DATABASE_HOST=db
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DATABASE_HOST=db
2+
WEBPACKER_DEV_SERVER_HOST=assets

templates/Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ruby:2.4.2
2+
3+
# use a newer version of Node to use Yarn
4+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
5+
6+
# nodejs: Rails needs a JS runtime
7+
# cmake: required by Rugged, dependency of Pronto
8+
RUN apt-get update -qq \
9+
&& apt-get install -y -qq nodejs cmake
10+
11+
RUN npm install -g yarn
12+
13+
RUN mkdir /app
14+
WORKDIR /app
15+
16+
ADD Gemfile /app/Gemfile
17+
ADD Gemfile.lock /app/Gemfile.lock
18+
RUN bundle install
19+
20+
ADD . /app

templates/Dockerfile-assets

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM ruby:2.4.2
2+
3+
# use a newer version of Node to use Yarn
4+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
5+
6+
# nodejs: Rails needs a JS runtime
7+
# cmake: required by Rugged, dependency of Pronto
8+
RUN apt-get update -qq \
9+
&& apt-get install -y -qq nodejs cmake
10+
11+
RUN npm install -g yarn
12+
13+
RUN mkdir /app
14+
WORKDIR /app
15+
16+
ADD Gemfile /app/Gemfile
17+
ADD Gemfile.lock /app/Gemfile.lock
18+
RUN bundle install
19+
20+
ADD package.json /app/package.json
21+
ADD yarn.lock /app/yarn.lock
22+
RUN yarn install
23+
24+
ADD . /app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3'
2+
services:
3+
db:
4+
image: postgres
5+
web:
6+
build: .
7+
command: bash -c 'rm -f tmp/pids/server.pid && bundle exec rails s --port 3000 --binding 0.0.0.0'
8+
volumes:
9+
- .:/app
10+
ports:
11+
- 3000:3000
12+
depends_on:
13+
- db
14+
env_file:
15+
- .env.docker
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3'
2+
services:
3+
db:
4+
image: postgres
5+
assets:
6+
build:
7+
context: .
8+
dockerfile: Dockerfile-assets
9+
command: yarn start
10+
volumes:
11+
- .:/app
12+
- /app/node_modules
13+
env_file:
14+
- .env.docker-assets
15+
web:
16+
build: .
17+
command: bash -c 'rm -f tmp/pids/server.pid && bundle exec rails s --port 3000 --binding 0.0.0.0'
18+
volumes:
19+
- .:/app
20+
ports:
21+
- 3000:3000
22+
depends_on:
23+
- db
24+
- assets
25+
env_file:
26+
- .env.docker

0 commit comments

Comments
 (0)