Skip to content

Commit c7b71ce

Browse files
committed
Initial config for Rails 6 with Webpacker & PostgreSQL on Docker
Initial commit Remove configs from development.rb Update yarn version Add 'n' (node version manager), revert yarn version Suppress bundler installation
1 parent 37d16b1 commit c7b71ce

File tree

4 files changed

+4
-57
lines changed

4 files changed

+4
-57
lines changed

.dockerdev/Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ FROM ruby:$RUBY_VERSION
33

44
ARG PG_MAJOR
55
ARG NODE_MAJOR
6-
ARG BUNDLER_VERSION
76
ARG YARN_VERSION
87

98
# Common dependencies
@@ -39,6 +38,8 @@ RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrad
3938
nodejs \
4039
yarn=$YARN_VERSION-1 \
4140
$(cat /tmp/Aptfile | xargs) && \
41+
npm install -g n && \
42+
n lts && \
4243
apt-get clean && \
4344
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
4445
truncate -s 0 /var/log/*log
@@ -56,8 +57,6 @@ ENV PATH /app/bin:$PATH
5657

5758
# Upgrade RubyGems
5859
RUN gem update --system
59-
# Uncomment this line if you would like to specify other version of bundler
60-
# && gem install bundler:$BUNDLER_VERSION
6160

6261
# Create a directory for the app code
6362
RUN mkdir -p /app

README.md

+2-48
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,14 @@ Assumed that bundler is included within Ruby 2.7 or later. If you want to specif
5151
- `BUNDLER_VERSION` in docker-compose.yml
5252
- `&& gem install bundler:$BUNDLER_VERSION` in .dockerdev/Dockerfile.
5353

54-
### Install
55-
56-
### A. Quick Install
54+
## Quick install
5755

5856
- `dip provision`
5957

6058
> Note: `--skip-listen` option is specified in the command to avoid the issue on macOS:
6159
> ref: [Code is not reloaded in dev with Docker on OS X · Issue \#25186 · rails/rails](https://github.com/rails/rails/issues/25186). Perhaps you can remove the option for Linux environments.
6260

63-
### B. Custom Install
64-
65-
- `dip compose build` to build a container.
66-
- `dip bundle install` to install gems for Rails.
67-
- `dip bundle exec rails new . --webpacker <options as you like>`.
68-
- To macOS user: add `--skip-listen`
69-
- `dip yarn install` to install yarn.
70-
- Perform the following manually to activate local access via Docker:
71-
72-
```sh
73-
dip sh -c "sed -i -e \"3i\ config.hosts << 'localhost'\" config/environments/development.rb"
74-
dip sh -c "sed -i -e \"4i\ config.web_console.whitelisted_ips = '0.0.0.0/0'\" config/environments/development.rb"
75-
```
76-
77-
- Then manually create databases:
78-
79-
```sh
80-
dip sh -c "rails db:prepare 2> /dev/null; exit 0 && rails db:prepare"
81-
dip sh -c "RAILS_ENV=test rails db:prepare"
82-
```
83-
84-
> Known issue: currently, running `db:prepare` twice is needed for establishing the initial database connection.
61+
Known isue: currently, running `db:prepare` twice is needed for establishing the initial database connection.
8562

8663
--------
8764

@@ -92,26 +69,3 @@ That's all. Now you can run `rails s` command via `dip rails s`. You don't need
9269
- You can see the available dip commands via `dip ls`.
9370
- .vscode contains a minimum set of conf and extensions. You can discard.
9471
- If you encounter any issues around caching, try checking bootsnap and spring gem.
95-
96-
## Webpacker + Bootstrap + font-awesome
97-
98-
You can configure Bootstrap 4 and font-awesome on Webpacker by running the following script:
99-
100-
```sh
101-
dip yarn add bootstrap jquery popper.js @fortawesome/fontawesome-free
102-
103-
mkdir app/javascript/src
104-
mkdir app/javascript/images
105-
106-
echo "@import '~bootstrap/scss/bootstrap';" > app/javascript/src/application.sass
107-
echo "@import '~@fortawesome/fontawesome-free/scss/fontawesome';" >> app/javascript/src/application.sass
108-
109-
dip sh -c 'sed -i -e "s/stylesheet_link_tag/stylesheet_pack_tag/g" app/views/layouts/application.html.erb'
110-
111-
dip sh -c "sed -i -e \"10i\import 'bootstrap';\" app/javascript/packs/application.js"
112-
dip sh -c "sed -i -e \"11i\import '../src/application.sass';\" app/javascript/packs/application.js"
113-
dip sh -c "sed -i -e \"12i\import '@fortawesome/fontawesome-free/js/all';\" app/javascript/packs/application.js"
114-
```
115-
116-
Then you can remove app/assets and deactivate Sprockets if unnecessary.
117-

dip.yml

-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,3 @@ provision:
7070
- dip bundle install
7171
- dip rails new . -d postgresql --webpacker --skip-listen --skip-git
7272
- dip yarn install
73-
- dip sh -c "sed -i -e \"3i\ config.hosts << 'localhost'\" config/environments/development.rb"
74-
- dip sh -c "sed -i -e \"4i\ config.web_console.whitelisted_ips = '0.0.0.0/0'\" config/environments/development.rb"
75-
- dip sh -c "rails db:prepare 2> /dev/null; exit 0 && rails db:prepare && RAILS_ENV=test rails db:prepare"

docker-compose.yml

-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ x-var: &NODE_MAJOR
1212
12
1313
x-var: &YARN_VERSION
1414
1.21.1
15-
x-var: &BUNDLER_VERSION
16-
2.1.2
1715

1816
x-app: &app
1917
build:
@@ -24,7 +22,6 @@ x-app: &app
2422
PG_MAJOR: *PG_MAJOR
2523
NODE_MAJOR: *NODE_MAJOR
2624
YARN_VERSION: *YARN_VERSION
27-
# BUNDLER_VERSION: *BUNDLER_VERSION
2825
environment: &env
2926
NODE_ENV: development
3027
RAILS_ENV: ${RAILS_ENV:-development}

0 commit comments

Comments
 (0)