-
Notifications
You must be signed in to change notification settings - Fork 13
/
Dockerfile.local
84 lines (65 loc) · 2.42 KB
/
Dockerfile.local
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Base image for builder stage
FROM ruby:3.0.6-slim as base
# Set environment variables
ENV RAILS_ENV=production \
SECRET_KEY_BASE=dummy
# Install common dependencies
RUN apt-get update -q && \
apt-get install -yq --no-install-recommends \
libpq-dev curl git libicu-dev build-essential openssl p7zip-full && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Builder Stage
FROM base as builder
# Set work directory
WORKDIR /app
# Install Node.js and Yarn
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
npm install --global yarn && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Bundler
RUN gem install bundler:2.4.9
# Copy Gemfile and install gems
COPY Gemfile Gemfile.lock ./
RUN bundle config set --local without 'development test' && \
bundle install -j"$(nproc)"
# Copy package.json and install node modules
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Copy the rest of the application code
COPY . .
# Precompile assets and perform other build tasks
RUN bundle exec bootsnap precompile --gemfile app/ lib/ config/ bin/ db/ && \
bundle exec rails assets:precompile && \
bundle exec rails deface:precompile
# Generate self-signed certificate
RUN mkdir certificate-https-local && \
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
-subj "/C=FR/ST=France/L=Paris/O=decidim/CN=decidim.eu" \
-keyout ./certificate-https-local/key.pem \
-out ./certificate-https-local/cert.pem
# Runner Stage
FROM base as runner
# Set environment variables
ENV RAILS_LOG_TO_STDOUT=true \
LD_PRELOAD="libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:5000,muzzy_decay_ms:5000,narenas:2"
# Set work directory
WORKDIR /app
# Install runtime dependencies
RUN apt-get update -q && \
apt-get install -yq --no-install-recommends \
postgresql-client imagemagick libproj-dev proj-bin libjemalloc2 p7zip-full && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Bundler
RUN gem install bundler:2.4.9
# Copy the built application and gems from the builder stage
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY --from=builder /app /app
# Expose port
EXPOSE 3000
# Start the Rails server
CMD ["bundle", "exec", "rails", "server", "-b", "ssl://0.0.0.0:3000?key=/app/certificate-https-local/key.pem&cert=/app/certificate-https-local/cert.pem"]