fix: add missing system dependencies for bundle install

This commit is contained in:
Rodrigo Borba 2026-02-25 16:43:25 -03:00
parent a55d831403
commit 0a243a269e

View File

@ -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/npm-cli.js /usr/local/bin/npm \
&& ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx && 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 \ build-base \
git \ git \
nodejs \
npm \
tzdata \ tzdata \
shared-mime-info \ postgresql-dev \
vips-dev postgresql-client \
curl \
xz \
vips-dev \
imagemagick \
libffi-dev \
shared-mime-info
WORKDIR /app WORKDIR /app
COPY package.json pnpm-lock.yaml ./ # Install pnpm
RUN npm install -g pnpm@${PNPM_VERSION} RUN npm install -g pnpm@${PNPM_VERSION}
ENV PATH="$PNPM_HOME:$PATH"
WORKDIR /app
# Copy dependency files first for caching
COPY Gemfile Gemfile.lock ./ COPY Gemfile Gemfile.lock ./
RUN bundle config set --local force_ruby_platform true \
# natively compile grpc and protobuf to support alpine musl (dialogflow-docker workflow) && bundle config set --local without 'development test' \
# https://github.com/googleapis/google-cloud-ruby/issues/13306 && bundle install -j "$(getconf _NPROCESSORS_ONLN)" -r 3
# 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
COPY package.json pnpm-lock.yaml ./ COPY package.json pnpm-lock.yaml ./
RUN pnpm config set store-dir /pnpm/store RUN pnpm config set store-dir /pnpm/store \
RUN --mount=type=cache,target=/pnpm/store pnpm i --frozen-lockfile && 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 # Generate production assets
# https://github.com/chatwoot/chatwoot/issues/701 RUN SECRET_KEY_BASE=precompile_placeholder RAILS_LOG_TO_STDOUT=enabled bundle exec rake assets:precompile \
RUN mkdir -p /app/log && rm -rf spec node_modules tmp/cache
# generate production assets if production environment # Generate .git_sha file
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
RUN git rev-parse HEAD > /app/.git_sha 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 # final build stage
FROM ruby:3.4.4-alpine3.21 FROM ruby:3.4.4-alpine3.21
ARG NODE_VERSION="24.13.0"
ARG PNPM_VERSION="10.2.0" ARG PNPM_VERSION="10.2.0"
ENV NODE_VERSION=${NODE_VERSION}
ENV PNPM_VERSION=${PNPM_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 \ RUN apk update && apk add --no-cache \
build-base \ build-base \
openssl \ openssl \
@ -106,25 +68,25 @@ RUN apk update && apk add --no-cache \
git \ git \
vips \ vips \
ffmpeg \ ffmpeg \
&& gem install bundler -v "$BUNDLER_VERSION" shared-mime-info
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
WORKDIR /app 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 EXPOSE 3000
CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]