Skip to content

Commit d258b39

Browse files
committed
added webpacker with all the needed changes to Dockerfile and docker-compose
1 parent 160ed2e commit d258b39

22 files changed

+7617
-75
lines changed

.babelrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": "> 1%",
7+
"uglify": true
8+
},
9+
"useBuiltIns": true
10+
}]
11+
],
12+
13+
"plugins": [
14+
"syntax-dynamic-import",
15+
"transform-object-rest-spread",
16+
["transform-class-properties", { "spec": true }]
17+
]
18+
}

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.git*
22
db/*.sqlite3
33
db/*.sqlite3-journal
4+
db-data
45
log/*
56
tmp/*
67
Dockerfile

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ Dockerfile.*
2626
docker-compose.*.yml
2727

2828
app_variables.env
29+
/public/packs
30+
/public/packs-test
31+
/node_modules
32+
yarn-debug.log*
33+
.yarn-integrity

.postcssrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins:
2+
postcss-import: {}
3+
postcss-cssnext: {}

Dockerfile

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
11
FROM ruby:2.4
22
33

4-
# Install apt based dependencies required to run Rails as
5-
# well as RubyGems. As the Ruby image itself is based on a
6-
# Debian image, we use apt-get to install those.
7-
RUN apt-get update && apt-get install -y \
8-
build-essential \
9-
nodejs
4+
# Download all the dependencies including node and yarn. Also, set localtime
5+
# TODO: do this also in staging and production
6+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
7+
&& curl -sL https://deb.nodesource.com/setup_9.x | bash - \
8+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
9+
&& apt-get update \
10+
&& apt-get install -qq -y --no-install-recommends build-essential nodejs yarn \
11+
&& rm -rf /var/lib/apt/lists/* \
12+
&& cp /usr/share/zoneinfo/Europe/Rome /etc/localtime
1013

1114
# Configure the main working directory. This is the base
1215
# directory used in any further RUN, COPY, and ENTRYPOINT
1316
# commands.
1417
RUN mkdir -p /app
1518
WORKDIR /app
1619

20+
ENV BUNDLE_PATH=/bundle \
21+
BUNDLE_BIN=/bundle/bin \
22+
GEM_HOME=/bundle
23+
ENV PATH="${BUNDLE_BIN}:${PATH}"
24+
# Bundle installs with binstubs to our custom /bundle/bin volume path. Let system use those stubs.
25+
1726
# Copy the Gemfile as well as the Gemfile.lock and install
1827
# the RubyGems. This is a separate step so the dependencies
1928
# will be cached unless changes to one of those two files
2029
# are made.
2130
COPY Gemfile Gemfile.lock ./
22-
RUN gem install bundler && bundle install --jobs 20 --retry 5
31+
RUN gem install bundler \
32+
&& bundle install --jobs 20 --retry 5
2333

2434
# Copy the main application.
2535
COPY . ./
2636

37+
RUN bin/yarn
38+
2739
# Expose port 3000 to the Docker host, so we can access it
2840
# from the outside.
2941
EXPOSE 3000
3042

31-
# Configure an entry point, so we don't need to specify
32-
# "bundle exec" for each of our commands.
33-
ENTRYPOINT ["bundle", "exec"]
43+
# Entrypoint
44+
COPY ./docker-entrypoint.sh /
45+
RUN chmod +x /docker-entrypoint.sh
46+
ENTRYPOINT ["/docker-entrypoint.sh"]
3447

35-
# The main command to run when the container starts. Also
36-
# tell the Rails dev server to bind to all interfaces by
37-
# default.
38-
CMD ["rails", "server", "-b", "0.0.0.0"]
48+
CMD bundle exec puma

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ gem 'piwik_analytics'
9494
# Cookie Law
9595
gem 'cookies_eu'
9696

97+
# Webpacker
98+
gem 'webpacker'
99+
gem 'webpacker-react'
100+
97101
group :development, :test do
98102
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
99103
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

Gemfile.lock

+10-11
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ GEM
131131
rails (>= 4.2.0)
132132
responders
133133
execjs (2.7.0)
134-
fast_gettext (1.5.1)
135134
ffi (1.9.18)
136135
font-awesome-rails (4.7.0.2)
137136
railties (>= 3.2, < 5.2)
@@ -141,13 +140,6 @@ GEM
141140
gettext (3.2.4)
142141
locale (>= 2.0.5)
143142
text (>= 1.3.0)
144-
gettext_i18n_rails (1.8.0)
145-
fast_gettext (>= 0.9.0)
146-
gettext_i18n_rails_js (1.2.0)
147-
gettext (>= 3.0.2)
148-
gettext_i18n_rails (>= 0.7.1)
149-
po_to_json (>= 1.0.0)
150-
rails (>= 3.2.0)
151143
globalid (0.4.0)
152144
activesupport (>= 4.2.0)
153145
high_voltage (3.0.0)
@@ -215,8 +207,6 @@ GEM
215207
actionpack
216208
activesupport
217209
rails (>= 3.0.0)
218-
po_to_json (1.0.1)
219-
json (>= 1.6.0)
220210
polyamorous (1.3.1)
221211
activerecord (>= 3.0)
222212
popper_js (1.11.1)
@@ -229,6 +219,8 @@ GEM
229219
public_suffix (3.0.0)
230220
puma (3.10.0)
231221
rack (2.0.3)
222+
rack-proxy (0.6.4)
223+
rack
232224
rack-test (0.6.3)
233225
rack (>= 1.0)
234226
rails (5.1.3)
@@ -341,6 +333,12 @@ GEM
341333
activemodel (>= 5.0)
342334
bindex (>= 0.4.0)
343335
railties (>= 5.0)
336+
webpacker (3.3.0)
337+
activesupport (>= 4.2)
338+
rack-proxy (>= 0.6.1)
339+
railties (>= 4.2)
340+
webpacker-react (0.3.2)
341+
webpacker
344342
websocket-driver (0.6.5)
345343
websocket-extensions (>= 0.1.0)
346344
websocket-extensions (0.1.2)
@@ -369,7 +367,6 @@ DEPENDENCIES
369367
friendly_id (~> 5.2.0)
370368
friendly_id-globalize!
371369
geocoder
372-
gettext_i18n_rails_js (~> 1.2.0)
373370
globalize!
374371
high_voltage (~> 3.0.0)
375372
i18n_data
@@ -399,6 +396,8 @@ DEPENDENCIES
399396
tzinfo-data
400397
uglifier (>= 1.3.0)
401398
web-console (>= 3.3.0)
399+
webpacker
400+
webpacker-react
402401

403402
BUNDLED WITH
404403
1.16.1

app/javascript/packs/application.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint no-console:0 */
2+
// This file is automatically compiled by Webpack, along with any other files
3+
// present in this directory. You're encouraged to place your actual application logic in
4+
// a relevant structure within app/javascript and only use these pack files to reference
5+
// that code so it'll be compiled.
6+
//
7+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8+
// layout file, like app/views/layouts/application.html.erb
9+
10+
console.log('Hello World from Webpacker')

app/views/layouts/application.html.erb

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
1414
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
15+
16+
<%# packs %>
17+
<%= javascript_pack_tag 'application' %>
18+
<%#= stylesheet_pack_tag 'application' %>
19+
1520
<%= render 'application/favicon' %>
1621
<%= piwik_tracking_tag %>
1722
</head>

bin/webpack

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "rubygems"
11+
require "bundler/setup"
12+
13+
require "webpacker"
14+
require "webpacker/webpack_runner"
15+
Webpacker::WebpackRunner.run(ARGV)

bin/webpack-dev-server

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "rubygems"
11+
require "bundler/setup"
12+
13+
require "webpacker"
14+
require "webpacker/dev_server_runner"
15+
Webpacker::DevServerRunner.run(ARGV)

config/environments/development.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Rails.application.configure do
2+
# Verifies that versions and hashed value of the package contents in the project's package.json
3+
config.webpacker.check_yarn_integrity = true
4+
25
# Settings specified here will take precedence over those in config/application.rb.
36

47
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

config/environments/production.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Rails.application.configure do
2+
# Verifies that versions and hashed value of the package contents in the project's package.json
3+
config.webpacker.check_yarn_integrity = false
4+
25
# Settings specified here will take precedence over those in config/application.rb.
36

47
# Mail settings

config/webpack/development.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const environment = require('./environment')
2+
3+
module.exports = environment.toWebpackConfig()

config/webpack/environment.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { environment } = require('@rails/webpacker')
2+
3+
module.exports = environment

config/webpack/production.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const environment = require('./environment')
2+
3+
module.exports = environment.toWebpackConfig()

config/webpack/test.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const environment = require('./environment')
2+
3+
module.exports = environment.toWebpackConfig()

config/webpacker.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Note: You must restart bin/webpack-dev-server for changes to take effect
2+
3+
default: &default
4+
source_path: app/javascript
5+
source_entry_path: packs
6+
public_output_path: packs
7+
cache_path: tmp/cache/webpacker
8+
9+
# Additional paths webpack should lookup modules
10+
# ['app/assets', 'engine/foo/app/assets']
11+
resolved_paths: []
12+
13+
# Reload manifest.json on all requests so we reload latest compiled packs
14+
cache_manifest: false
15+
16+
extensions:
17+
- .js
18+
- .sass
19+
- .scss
20+
- .css
21+
- .module.sass
22+
- .module.scss
23+
- .module.css
24+
- .png
25+
- .svg
26+
- .gif
27+
- .jpeg
28+
- .jpg
29+
30+
development:
31+
<<: *default
32+
compile: true
33+
34+
# Reference: https://webpack.js.org/configuration/dev-server/
35+
dev_server:
36+
https: false
37+
host: localhost
38+
port: 3035
39+
public: localhost:3035
40+
hmr: false
41+
# Inline should be set to true if using HMR
42+
inline: true
43+
overlay: true
44+
compress: true
45+
disable_host_check: true
46+
use_local_ip: false
47+
quiet: false
48+
headers:
49+
'Access-Control-Allow-Origin': '*'
50+
watch_options:
51+
ignored: /node_modules/
52+
53+
54+
test:
55+
<<: *default
56+
compile: true
57+
58+
# Compile test packs to a separate directory
59+
public_output_path: packs-test
60+
61+
production:
62+
<<: *default
63+
64+
# Production depends on precompilation of packs prior to booting for performance.
65+
compile: false
66+
67+
# Cache manifest.json for performance
68+
cache_manifest: true

docker-compose.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ services:
55
image: commonfare_dev_rails_app
66
container_name: commonfare_dev_rails_app
77
restart: always
8-
command: rails server -p 3000 -b '0.0.0.0'
8+
command: rails server -p 3000 -b 0.0.0.0 --pid /app/tmp/pids/development.pid
99
volumes:
1010
- .:/app
1111
- ~/tmp:/host_tmp
12+
- bundle_cache:/bundle
1213
ports:
1314
- "3000:3000"
1415
# links app container to postgres container.
@@ -22,6 +23,19 @@ services:
2223
# These two allow debug with pry
2324
tty: true
2425
stdin_open: true
26+
webpack-dev-server:
27+
image: commonfare_dev_rails_app
28+
container_name: commonfare_dev_webpack
29+
restart: always
30+
command: ./bin/webpack-dev-server
31+
ports:
32+
- "3035:3035"
33+
volumes:
34+
- .:/app
35+
- ~/tmp:/host_tmp
36+
- bundle_cache:/bundle
37+
env_file:
38+
- app_variables.env
2539
mailcatcher:
2640
image: tophfr/mailcatcher
2741
container_name: commonfare_mailcatcher
@@ -37,3 +51,6 @@ services:
3751
- "5432"
3852
volumes:
3953
- ./db-data:/var/lib/postgresql/data
54+
volumes:
55+
bundle_cache:
56+
# Mount volume with default driver

docker-entrypoint.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Bash script identifier
3+
4+
set -e
5+
# Exit on fail
6+
7+
rm -f /app/tmp/pids/${RAILS_ENV:-development}.pid
8+
9+
bundle check || bundle install
10+
11+
exec "$@"
12+
# Finally call command issued to the docker service

0 commit comments

Comments
 (0)