From 0a243a269e2987b9c5bb278f8483d655d750b6e4 Mon Sep 17 00:00:00 2001 From: Rodrigo Borba Date: Wed, 25 Feb 2026 16:43:25 -0300 Subject: [PATCH] fix: add missing system dependencies for bundle install --- docker/Dockerfile | 120 ++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 79 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 8f990c820..739c7e1cd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,89 +14,51 @@ RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs \ && ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \ && ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx -RUN apk add --no-cache \ +# Install system dependencies +RUN apk update && apk add --no-cache \ build-base \ git \ - nodejs \ - npm \ tzdata \ - shared-mime-info \ - vips-dev + postgresql-dev \ + postgresql-client \ + curl \ + xz \ + vips-dev \ + imagemagick \ + libffi-dev \ + shared-mime-info WORKDIR /app -COPY package.json pnpm-lock.yaml ./ - +# Install pnpm RUN npm install -g pnpm@${PNPM_VERSION} -ENV PATH="$PNPM_HOME:$PATH" - -WORKDIR /app +# Copy dependency files first for caching COPY Gemfile Gemfile.lock ./ - -# natively compile grpc and protobuf to support alpine musl (dialogflow-docker workflow) -# https://github.com/googleapis/google-cloud-ruby/issues/13306 -# adding xz as nokogiri was failing to build libxml -# https://github.com/chatwoot/chatwoot/issues/4045 -RUN apk update && apk add --no-cache build-base musl ruby-full ruby-dev gcc make musl-dev openssl openssl-dev g++ linux-headers xz vips -RUN bundle config set --local force_ruby_platform true - -# Do not install development or test gems in production -RUN if [ "$RAILS_ENV" = "production" ]; then \ - bundle config set without 'development test'; bundle install -j 4 -r 3; \ - else bundle install -j 4 -r 3; \ - fi +RUN bundle config set --local force_ruby_platform true \ + && bundle config set --local without 'development test' \ + && bundle install -j "$(getconf _NPROCESSORS_ONLN)" -r 3 COPY package.json pnpm-lock.yaml ./ -RUN pnpm config set store-dir /pnpm/store -RUN --mount=type=cache,target=/pnpm/store pnpm i --frozen-lockfile +RUN pnpm config set store-dir /pnpm/store \ + && pnpm i --frozen-lockfile -COPY . /app +# Copy application code +COPY . . -# creating a log directory so that image wont fail when RAILS_LOG_TO_STDOUT is false -# https://github.com/chatwoot/chatwoot/issues/701 -RUN mkdir -p /app/log +# Generate production assets +RUN SECRET_KEY_BASE=precompile_placeholder RAILS_LOG_TO_STDOUT=enabled bundle exec rake assets:precompile \ + && rm -rf spec node_modules tmp/cache -# generate production assets if production environment -RUN if [ "$RAILS_ENV" = "production" ]; then \ - SECRET_KEY_BASE=precompile_placeholder RAILS_LOG_TO_STDOUT=enabled bundle exec rake assets:precompile \ - && rm -rf spec node_modules tmp/cache; \ - fi - -# Generate .git_sha file with current commit hash +# Generate .git_sha file RUN git rev-parse HEAD > /app/.git_sha -# Remove unnecessary files -RUN rm -rf /gems/ruby/3.4.0/cache/*.gem \ - && find /gems/ruby/3.4.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete \ - && rm -rf .git \ - && rm .gitignore - # final build stage FROM ruby:3.4.4-alpine3.21 -ARG NODE_VERSION="24.13.0" ARG PNPM_VERSION="10.2.0" -ENV NODE_VERSION=${NODE_VERSION} ENV PNPM_VERSION=${PNPM_VERSION} -ARG BUNDLE_WITHOUT="development:test" -ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT} -ENV BUNDLER_VERSION=2.5.16 - -ARG EXECJS_RUNTIME="Disabled" -ENV EXECJS_RUNTIME ${EXECJS_RUNTIME} - -ARG RAILS_SERVE_STATIC_FILES=true -ENV RAILS_SERVE_STATIC_FILES ${RAILS_SERVE_STATIC_FILES} - -ARG BUNDLE_FORCE_RUBY_PLATFORM=1 -ENV BUNDLE_FORCE_RUBY_PLATFORM ${BUNDLE_FORCE_RUBY_PLATFORM} - -ARG RAILS_ENV=production -ENV RAILS_ENV ${RAILS_ENV} -ENV BUNDLE_PATH="/gems" - RUN apk update && apk add --no-cache \ build-base \ openssl \ @@ -106,25 +68,25 @@ RUN apk update && apk add --no-cache \ git \ vips \ ffmpeg \ - && gem install bundler -v "$BUNDLER_VERSION" - -COPY --from=node /usr/local/bin/node /usr/local/bin/ -COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules - -RUN if [ "$RAILS_ENV" != "production" ]; then \ - apk add --no-cache curl \ - && ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \ - && ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \ - && npm install -g pnpm@${PNPM_VERSION} \ - && pnpm --version; \ - fi - -COPY --from=pre-builder /gems/ /gems/ -COPY --from=pre-builder /app /app - -# Copy .git_sha file from pre-builder stage -COPY --from=pre-builder /app/.git_sha /app/.git_sha + shared-mime-info WORKDIR /app +COPY --from=node /usr/local/bin/node /usr/local/bin/node +COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules +RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + && ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \ + && ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \ + && npm install -g pnpm@${PNPM_VERSION} + +COPY --from=pre-builder /usr/local/bundle /usr/local/bundle +COPY --from=pre-builder /app /app + +ENV RAILS_ENV=production +ENV NODE_ENV=production +ENV RAILS_SERVE_STATIC_FILES=true +ENV RAILS_LOG_TO_STDOUT=true + EXPOSE 3000 + +CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]