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,23 @@ 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+ pngcrush optipng advancecomp pngquant jhead jpegoptim gifsicle libjpeg-progs unzip \
21+ && curl -fsSL https://deb.nodesource.com/setup_24 .x | bash - \
1722 && apt-get install -y nodejs \
1823 && npm install -g yarn svgo \
1924 && apt-get clean && rm -rf /var/lib/apt/lists/*
2025
21- RUN a2enmod passenger
2226
2327# 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
28+ ENV OPENSTREETMAP_WEBSITE_GITSHA=acb1e73fa98e6cb7adf67f99e0be5891dcd4f6ea
29+ ENV OSM_WEBSITE_URL=https://github.com/openstreetmap/openstreetmap-website/archive/${OPENSTREETMAP_WEBSITE_GITSHA}.zip
30+ RUN rm -rf $workdir/* && curl -fsSL $OSM_WEBSITE_URL -o /tmp/openstreetmap-website.zip && \
31+ unzip /tmp/openstreetmap-website.zip -d /tmp && \
32+ mv /tmp/openstreetmap-website-$OPENSTREETMAP_WEBSITE_GITSHA/* $workdir && \
33+ rm -rf /tmp/*
34+
3235RUN gem install bundler && \
3336 bundle install && \
3437 yarn install && \
@@ -45,8 +48,8 @@ RUN rm -f config/credentials.yml.enc && \
4548 export RAILS_MASTER_KEY=$(openssl rand -hex 16) && \
4649 export SECRET_KEY_BASE=$(bundle exec rails secret) && \
4750 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 "\
51+ EDITOR="echo" RAILS_MASTER_KEY=$RAILS_MASTER_KEY bundle exec rails credentials:edit && \
52+ RAILS_MASTER_KEY=$RAILS_MASTER_KEY bundle exec rails runner "\
5053 require 'active_support/encrypted_configuration'; \
5154 require 'yaml'; \
5255 creds = ActiveSupport::EncryptedConfiguration.new(\
@@ -59,40 +62,108 @@ RUN rm -f config/credentials.yml.enc && \
5962 creds.write(credentials.to_yaml); \
6063 puts 'Credentials configured correctly.'"
6164
62- # Precompile assets
63- RUN bundle exec rake i18n:js:export && \
64- bundle exec rake assets:precompile
65+ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
66+ RUN SECRET_KEY_BASE_DUMMY=1 \
67+ bundle exec i18n export && \
68+ bundle exec rails assets:precompile
69+
6570
6671FROM ruby:3.3-slim
6772
6873ENV 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 \
74+ workdir=/var/www \
75+ BUNDLE_PATH=/usr/local/bundle \
76+ GEM_HOME=/usr/local/bundle \
77+ GEM_PATH=/usr/local/bundle \
78+ PATH="/usr/local/bundle/bin:$PATH" \
79+ RAILS_ENV=production \
80+ PATH="$PATH:$GEM_HOME/bin"
81+
82+ # Install base dependencies for Passenger gem compilation and runtime
83+ RUN BUILD_DEPS=" \
84+ build-essential \
85+ apache2-dev \
86+ libcurl4-openssl-dev \
87+ zlib1g-dev \
88+ libssl-dev \
89+ npm \
90+ " \
91+ && apt-get update && apt-get install -y --no-install-recommends \
92+ $BUILD_DEPS \
93+ libgd-dev \
94+ apache2 \
95+ libapache2-mod-fcgid \
96+ libpq5 \
97+ libxml2 \
98+ libyaml-0-2 \
99+ libarchive13 \
100+ file \
101+ pngcrush \
102+ optipng \
103+ advancecomp \
104+ pngquant \
105+ jhead \
106+ jpegoptim \
107+ gifsicle \
108+ postgresql-client \
109+ curl \
110+ libvips \
111+ nodejs \
112+ \
113+ && npm install -g svgo \
114+ \
115+ # Install Passenger as a gem and compile the Apache module
116+ \
117+ && gem install passenger --no-document \
118+ && yes | passenger-install-apache2-module --auto --languages ruby \
119+ && passenger-config validate-install --auto \
120+ \
121+ # Delete the build dependencies to reduce image size
122+ \
123+ && apt-get purge -y --auto-remove $BUILD_DEPS \
124+ \
125+ # libgd-dev is requiered by the app on run time to process gps files
126+ \
127+ && apt-get update && apt-get install -y --no-install-recommends libgd3 libgd-dev \
128+ \
129+ # Final cleanup
130+ \
78131 && apt-get clean && rm -rf /var/lib/apt/lists/*
79132
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
85133
86134# Apache configuration
87135COPY config/production.conf /etc/apache2/sites-available/production.conf
136+
137+ RUN passenger-install-apache2-module --snippet > /etc/apache2/mods-available/passenger.load && \
138+ passenger-config build-native-support
139+
88140RUN a2enmod headers setenvif proxy proxy_http proxy_fcgi fcgid rewrite lbmethod_byrequests passenger && \
89141 a2dissite 000-default && \
90142 a2ensite production && \
91143 echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
92144 apache2ctl configtest
93145
146+ RUN echo '#!/bin/bash\n exec /usr/local/bin/ruby --yjit --yjit-exec-mem-size=64 "$@"' > /usr/local/bin/ruby_yjit && \
147+ chmod +x /usr/local/bin/ruby_yjit
148+
149+ WORKDIR $workdir
150+
151+ COPY --chown=www-data:www-data --from=builder /var/www /$workdir
152+ COPY --from=builder /usr/local/bundle /usr/local/bundle
153+
94154COPY config/settings.yml $workdir/config/
95155COPY start.sh liveness.sh $workdir/
96- RUN chmod +x $workdir/*.sh
97- RUN chown -R www-data:www-data /var/www
156+
157+ RUN ln -s /tmp /var/www/tmp
158+
159+ RUN mkdir -p /var/www/log && \
160+ touch /var/www/log/production.log && \
161+ chown -R www-data:www-data /var/www/log /var/www/public && \
162+ chown -R www-data:www-data /var/www
163+
98164CMD ["./start.sh" ]
165+
166+
167+
168+
169+
0 commit comments