This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
66 lines (52 loc) · 2.05 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
ARG RUBY_VERSION=3.2.2
# Use the official Ruby image as the parent image
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
# Set the working directory to /app
WORKDIR /app
# Set production environment this values will be overwritten at with docker-compose.yml
ARG BUNDLE_WITHOUT
ENV BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
BUNDLE_WITHOUT="${BUNDLE_WITHOUT}"
# Throw-away build stage to reduce size of final image
FROM base as build
# Install libvips for Active Storage preview support
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
build-essential \
git \
pkg-config \
libpq-dev \
postgresql-client \
nodejs
# Copy the Gemfile and Gemfile.lock into the image
COPY Gemfile Gemfile.lock ./
# Install dependencies
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
# Copy the rest of the application code into the image
COPY . .
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# To ignore precompile step we can send ENV['RUNNING_CI']=true to dockerfile
# RSpotify.authenticate in /config/application.rb brakes the build if spotify ENV vars not set right
ARG RUNNING_CI="false"
# Precompiling assets for container without requiring secret RAILS_MASTER_KEY
RUN if [ "$RUNNING_CI" = "false" ]; then \
SECRET_KEY_BASE_DUMMY=1 bin/rails assets:precompile && bundle exec rake tailwindcss:build; \
fi
FROM base
# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y postgresql-client nodejs && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /app /app
# Expose port 3000 for the Rails server
EXPOSE 3000
# Start the Rails server
CMD ["rails", "server", "-b", "0.0.0.0"]