Skip to content

Commit ee2c1de

Browse files
Dockerfile: Install Yarn for dev as well (#12)
docker-compose: Don't bind /opt/app This will prevent 'hot reload' from working inside Docker (the image will need to be rebuilt for every change), but it does ensure webpack works correctly. Otherwise, the binstub is overridden by our own bin/ (and can't be put back because node_modules/ isn't available either). changing where yarn is built changes for yarn path Fixing yarn issue in development deals with gpg expired key running yarn build from /usr/local/yarn copying over yarn files for prod from dev added destination directory for copy of yarn dir from dev to prod moving back to /opt/app in prod to precompile assets removed custom gpg key from Dockerfile putting gpg key set back in to Dockerfile gpg key was renewed so using the original access method removed old call to fetch yarn update env for yarn path, using --cwd for yarn install instead of switching WORKDIR Co-authored-by: A. Wilcox <AWilcox@Wilcox-Tech.com>
1 parent 1473857 commit ee2c1de

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ RUN mkdir -p /opt/app/tmp \
7474
&& ln -s /opt/app/artifacts/screenshots /opt/app/tmp/screenshots
7575

7676
# Add binstubs to the path.
77-
ENV PATH="/usr/bin:/opt/app/bin:$PATH"
77+
ENV PATH="/usr/bin:/opt/app/bin:/usr/local/yarn/node_modules/bin:$PATH"
7878

7979
# If run with no other arguments, the image will start the rails server by
8080
# default. Note that we must bind to all interfaces (0.0.0.0) because when
@@ -108,8 +108,12 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
108108
gcc \
109109
&& rm -rf /var/lib/apt/lists/*
110110

111+
RUN mkdir -p /usr/local/yarn \
112+
&& chown -R $APP_USER:$APP_USER /usr/local/yarn
113+
COPY ./webpack.config.js ./package.json /usr/local/yarn
114+
111115
# ------------------------------------------------------------
112-
# Install Ruby gems
116+
# Install Ruby gems and Yarn packages
113117

114118
# Drop back to $APP_USER.
115119
USER $APP_USER
@@ -127,6 +131,8 @@ RUN bundle install
127131
# re-install.
128132
COPY --chown=$APP_USER:$APP_USER . .
129133

134+
RUN yarn install --cwd /usr/local/yarn
135+
130136
# =============================================================================
131137
# Target: production
132138
#
@@ -149,6 +155,7 @@ ENV RAILS_SERVE_STATIC_FILES=true
149155
# Copy the built codebase from the dev stage
150156
COPY --from=development --chown=$APP_USER /opt/app /opt/app
151157
COPY --from=development --chown=$APP_USER /usr/local/bundle /usr/local/bundle
158+
COPY --from=development --chown=$APP_USER /usr/local/yarn /usr/local/yarn
152159

153160
# Ensure the bundle is installed and the Gemfile.lock is synced.
154161
RUN bundle config set frozen 'true'
@@ -159,17 +166,13 @@ RUN bundle install --local
159166

160167
# TODO: Figure out why jsbundling-rails doesn't invoke `yarn build`
161168
# *before* Sprockets reads app/assets/config/manifest.js
162-
RUN yarn install && yarn build
169+
RUN yarn install --cwd /usr/local/yarn
163170

164171
# Pre-compile assets so we don't have to do it after deployment.
165172
# NOTE: dummy SECRET_KEY_BASE to prevent spurious initializer issues
166173
# -- see https://github.com/rails/rails/issues/32947
167174
RUN SECRET_KEY_BASE=1 rails assets:precompile --trace
168175

169-
# Remove cached YARN packages
170-
# TODO: change this to .yarn/cache once we're on Yarn 3.x
171-
RUN rm -r .cache/yarn
172-
173176
# ------------------------------------------------------------
174177
# Preserve build arguments
175178

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
aliases:
2121
- app.test
2222
volumes:
23-
- ./:/opt/app
23+
- .:/opt/app
2424
- ./app/assets/builds:/opt/app/app/assets/builds
2525
ports:
2626
- 3000:3000

0 commit comments

Comments
 (0)