I’m working on a project where I’m combining several software packages into a single monolith. I’ve chosen the base image node:18-alpine3.18
due to other dependencies. However, I’ve encountered several issues:
- MiniRacer in Gemfile: Initially, I faced problems with
mini_racer
. I tried removing it andrtlcss
(which requires it), but received multiple errors. I then tried switching to a multistage build and attempting to precompile assets which led to issues with the database connection. I tried stubbing the database with a mock implementation and using thefakeredis
gem, which had a Redis version mismatch. Running Redis in the container then brought up issues with Postgres. - Installing MiniRacer from Source: Frustrated with database stubbing, I decided to install
mini_racer
from source. I found that it didn’t recognizelibv8-node
, so I installed that from source as well. However, it requirednode:16
to buildlibv8
. Out of desperation, I changed the base image tonode:16-alpine3.18
, but still encountered a dependency conflict formini_racer
when bundling.
I’m struggling with this quite a bit, and I’d really appreciate advice on how to proceed. Below is the current build stage for reference:
# Discourse stage
FROM node:16-alpine3.18 AS discourse
ARG DISCOURSE_VERSION=3.1.0
ENV RAILS_ENV=production
ENV RUBY_GLOBAL_METHOD_CACHE_SIZE=131072
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
# Install system dependencies
RUN apk add --no-cache \
ruby \
ruby-dev \
ruby-bundler \
git \
build-base \
linux-headers \
postgresql-dev \
libxml2-dev \
libxslt-dev \
imagemagick \
sudo \
tzdata \
wget \
python3 \
curl \
gcc \
g++ \
make \
&& gem install bundler
# Create discourse user
RUN adduser -D -h /home/discourse discourse && \
echo "discourse ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/discourse
# Clone repository and checkout version
RUN git clone --depth 1 --branch v${DISCOURSE_VERSION} --single-branch https://github.com/discourse/discourse.git /home/discourse/discourse && \
chown -R discourse:discourse /home/discourse/discourse
# Set Git safe directory
RUN git config --system --add safe.directory /home/discourse/discourse
WORKDIR /home/discourse/discourse
# Update mini_racer version in Gemfile
RUN sed -i 's/gem "mini_racer".*$/gem "mini_racer", "0.6.2"/' Gemfile
# Install libv8-node and mini_racer
RUN gem install libv8-node -v 16.10.0.0 -- --with-system-v8=false && \
gem contents libv8-node | grep -E 'vendor/v8/.*\.a
Any suggestions or guidance would be greatly appreciated! &&
ls -l $(gem contents libv8-node | grep -E 'vendor/v8/.*.a
Any suggestions or guidance would be greatly appreciated! | sed 's/libv8_monolith\.a$//') && \
gem install mini_racer -v 0.6.2 -- \
--with-v8-dir=$(gem contents libv8-node | grep -E 'vendor/v8/.*\.a
Any suggestions or guidance would be greatly appreciated! | sed ‘s/libv8_monolith.a$//’)
Update Gemfile.lock
RUN bundle lock --update
Configure bundler
RUN bundle config set --local deployment ‘true’ &&
bundle config set --local without ‘development:test’ &&
bundle config build.nokogiri --use-system-libraries
Install dependencies
RUN bundle install --jobs 4 --retry 3 &&
yarn install
Copy configuration files
COPY discourse-config.yml /home/discourse/discourse/config/discourse.yml
Create a minimal database.yml for asset precompilation
RUN echo “production:\n adapter: postgresql\n database: discourse\n host: localhost\n pool: 5” > /home/discourse/discourse/config/database.yml
Create a mock Redis implementation
RUN echo “class Redis\n def method_missing(*args)\n nil\n end\n def self.new(*args)\n self\n end\nend” > /home/discourse/discourse/config/initializers/mock_redis.rb
Precompile assets without connecting to database or Redis
RUN RAILS_ENV=production
SKIP_REDIS=1
SKIP_DB=1
SKIP_TAGS=1
SECRET_TOKEN=dummytoken
DISABLE_CUSTOM_PLUGINS=1
LOAD_PLUGINS=0
bundle exec rake assets:precompile
Remove the temporary configuration files
RUN rm /home/discourse/discourse/config/database.yml /home/discourse/discourse/config/initializers/mock_redis.rb
Set correct ownership
RUN chown -R discourse:discourse /home/discourse/discourse
Any suggestions or guidance would be greatly appreciated!