11FROM ruby:3.3-slim AS builder
22
33ENV DEBIAN_FRONTEND=noninteractive \
4- workdir=/var/www
4+ workdir=/var/www \
5+ BUNDLE_PATH=/usr/local/bundle \
6+ GEM_HOME=/usr/local/bundle \
7+ GEM_PATH=/usr/local/bundle \
8+ PATH="/usr/local/bundle/bin:$PATH" \
9+ RAILS_ENV=production
510
611WORKDIR $workdir
712
@@ -10,25 +15,24 @@ RUN apt-get update && \
1015 apt-get install -y --no-install-recommends \
1116 git curl gnupg build-essential \
1217 libarchive-dev zlib1g-dev libcurl4-openssl-dev \
13- apache2 apache2-dev libapache2-mod-passenger libapache2-mod- fcgid libapr1-dev libaprutil1-dev \
18+ apache2 apache2-dev libapache2-mod-fcgid libapr1-dev libaprutil1-dev \
1419 postgresql-client libpq-dev libxml2-dev libyaml-dev \
15- pngcrush optipng advancecomp pngquant jhead jpegoptim gifsicle libjpeg-progs \
16- && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
20+ libgd-dev \
21+ pngcrush optipng advancecomp pngquant jhead jpegoptim gifsicle libjpeg-progs unzip\
22+ && curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
1723 && apt-get install -y nodejs \
1824 && npm install -g yarn svgo \
1925 && apt-get clean && rm -rf /var/lib/apt/lists/*
2026
21- RUN a2enmod passenger
2227
2328# Clone OSM Website
24- ENV OPENSTREETMAP_WEBSITE_GITSHA=ea3760f94d9d74d3aaa8492182b9e1a15ec1effa
25- RUN rm -rf $workdir/* && \
26- git clone https://github.com/openstreetmap/openstreetmap-website.git $workdir && \
27- cd $workdir && \
28- git checkout $OPENSTREETMAP_WEBSITE_GITSHA && \
29- git fetch && rm -rf .git
30-
31- # Install Ruby/Node dependencies
29+ ENV OPENSTREETMAP_WEBSITE_GITSHA=a244e419719ded592fb87e7ffd360f6e462a0d67
30+ ENV OSM_WEBSITE_URL=https://github.com/openstreetmap/openstreetmap-website/archive/${OPENSTREETMAP_WEBSITE_GITSHA}.zip
31+ RUN rm -rf $workdir/* && curl -fsSL $OSM_WEBSITE_URL -o /tmp/openstreetmap-website.zip && \
32+ unzip /tmp/openstreetmap-website.zip -d /tmp && \
33+ mv /tmp/openstreetmap-website-$OPENSTREETMAP_WEBSITE_GITSHA/* $workdir && \
34+ rm -rf /tmp/*
35+
3236RUN gem install bundler && \
3337 bundle install && \
3438 yarn install && \
@@ -45,8 +49,8 @@ RUN rm -f config/credentials.yml.enc && \
4549 export RAILS_MASTER_KEY=$(openssl rand -hex 16) && \
4650 export SECRET_KEY_BASE=$(bundle exec rails secret) && \
4751 echo $RAILS_MASTER_KEY > config/master.key && \
48- EDITOR="echo" RAILS_MASTER_KEY=$RAILS_MASTER_KEY rails credentials:edit && \
49- RAILS_MASTER_KEY=$RAILS_MASTER_KEY rails runner "\
52+ EDITOR="echo" RAILS_MASTER_KEY=$RAILS_MASTER_KEY bundle exec rails credentials:edit && \
53+ RAILS_MASTER_KEY=$RAILS_MASTER_KEY bundle exec rails runner "\
5054 require 'active_support/encrypted_configuration'; \
5155 require 'yaml'; \
5256 creds = ActiveSupport::EncryptedConfiguration.new(\
@@ -59,40 +63,103 @@ RUN rm -f config/credentials.yml.enc && \
5963 creds.write(credentials.to_yaml); \
6064 puts 'Credentials configured correctly.'"
6165
62- # Precompile assets
63- RUN bundle exec rake i18n:js:export && \
64- bundle exec rake assets:precompile
66+ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
67+ RUN SECRET_KEY_BASE_DUMMY=1 \
68+ bundle exec i18n export && \
69+ bundle exec rails assets:precompile
70+
6571
6672FROM ruby:3.3-slim
6773
6874ENV DEBIAN_FRONTEND=noninteractive \
69- workdir=/var/www
70-
71- WORKDIR $workdir
72-
73- # Install only runtime dependencies
74- RUN apt-get update && apt-get install -y --no-install-recommends \
75- apache2 libapache2-mod-passenger libapache2-mod-fcgid \
76- libpq5 libxml2 libyaml-0-2 libarchive13 file libgd-dev \
77- postgresql-client curl \
75+ workdir=/var/www \
76+ BUNDLE_PATH=/usr/local/bundle \
77+ GEM_HOME=/usr/local/bundle \
78+ GEM_PATH=/usr/local/bundle \
79+ PATH="/usr/local/bundle/bin:$PATH" \
80+ RAILS_ENV=production \
81+ PATH="$PATH:$GEM_HOME/bin"
82+
83+ # Install base dependencies for Passenger gem compilation and runtime
84+ RUN BUILD_DEPS=" \
85+ build-essential \
86+ apache2-dev \
87+ libcurl4-openssl-dev \
88+ zlib1g-dev \
89+ libssl-dev \
90+ npm \
91+ " \
92+ && apt-get update && apt-get install -y --no-install-recommends \
93+ $BUILD_DEPS \
94+ libgd-dev \
95+ apache2 \
96+ libapache2-mod-fcgid \
97+ libpq5 \
98+ libxml2 \
99+ libyaml-0-2 \
100+ libarchive13 \
101+ file \
102+ pngcrush \
103+ optipng \
104+ advancecomp \
105+ pngquant \
106+ jhead \
107+ jpegoptim \
108+ gifsicle \
109+ postgresql-client \
110+ curl \
111+ libvips \
112+ nodejs \
113+ \
114+ && npm install -g svgo \
115+ \
116+ # Install Passenger as a gem and compile the Apache module
117+ \
118+ && gem install passenger --no-document \
119+ && yes | passenger-install-apache2-module --auto --languages ruby \
120+ && passenger-config validate-install --auto \
121+ \
122+ # Delete the build dependencies to reduce image size
123+ \
124+ && apt-get purge -y --auto-remove $BUILD_DEPS \
125+ \
126+ # libgd-dev is requiered by the app on run time to process gps files
127+ \
128+ && apt-get update && apt-get install -y --no-install-recommends libgd3 libgd-dev \
129+ \
130+ # Final cleanup
131+ \
78132 && apt-get clean && rm -rf /var/lib/apt/lists/*
79133
80- COPY --from=builder /var/www /var/www
81- COPY --from=builder /usr/local/bundle /usr/local/bundle
82-
83- # Symlink tmp for Passenger
84- RUN ln -s /tmp /var/www/tmp
85134
86135# Apache configuration
87136COPY config/production.conf /etc/apache2/sites-available/production.conf
137+
138+ RUN passenger-install-apache2-module --snippet > /etc/apache2/mods-available/passenger.load && \
139+ passenger-config build-native-support
140+
88141RUN a2enmod headers setenvif proxy proxy_http proxy_fcgi fcgid rewrite lbmethod_byrequests passenger && \
89142 a2dissite 000-default && \
90143 a2ensite production && \
91144 echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
92145 apache2ctl configtest
93146
147+ RUN echo '#!/bin/bash\n exec /usr/local/bin/ruby --yjit --yjit-exec-mem-size=64 "$@"' > /usr/local/bin/ruby_yjit && \
148+ chmod +x /usr/local/bin/ruby_yjit
149+
150+ WORKDIR $workdir
151+
152+ COPY --chown=www-data:www-data --from=builder /var/www /$workdir
153+ COPY --from=builder /usr/local/bundle /usr/local/bundle
154+
94155COPY config/settings.yml $workdir/config/
95156COPY start.sh liveness.sh $workdir/
96- RUN chmod +x $workdir/*.sh
97- RUN chown -R www-data:www-data /var/www
157+
158+ RUN ln -s /tmp /var/www/tmp
159+
160+ RUN mkdir -p /var/www/log && \
161+ touch /var/www/log/production.log && \
162+ chown -R www-data:www-data /var/www/log /var/www/public && \
163+ chown -R www-data:www-data /var/www
164+
98165CMD ["./start.sh" ]
0 commit comments