Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ RUN mkdir -p /opt/app/tmp \
&& ln -s /opt/app/artifacts/screenshots /opt/app/tmp/screenshots

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

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

RUN mkdir -p /usr/local/yarn \
&& chown -R $APP_USER:$APP_USER /usr/local/yarn
COPY ./webpack.config.js ./package.json /usr/local/yarn

# ------------------------------------------------------------
# Install Ruby gems
# Install Ruby gems and Yarn packages

# Drop back to $APP_USER.
USER $APP_USER
Expand All @@ -127,6 +131,8 @@ RUN bundle install
# re-install.
COPY --chown=$APP_USER:$APP_USER . .

RUN yarn install --cwd /usr/local/yarn

# =============================================================================
# Target: production
#
Expand All @@ -149,6 +155,7 @@ ENV RAILS_SERVE_STATIC_FILES=true
# Copy the built codebase from the dev stage
COPY --from=development --chown=$APP_USER /opt/app /opt/app
COPY --from=development --chown=$APP_USER /usr/local/bundle /usr/local/bundle
COPY --from=development --chown=$APP_USER /usr/local/yarn /usr/local/yarn

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

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

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

# Remove cached YARN packages
# TODO: change this to .yarn/cache once we're on Yarn 3.x
RUN rm -r .cache/yarn

# ------------------------------------------------------------
# Preserve build arguments

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
aliases:
- app.test
volumes:
- ./:/opt/app
- .:/opt/app
- ./app/assets/builds:/opt/app/app/assets/builds
ports:
- 3000:3000
Expand Down