Skip to content

Commit

Permalink
chore(Dockerfile): attempt to resovle build failure
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Feb 1, 2025
1 parent 056bbcf commit a5c59b4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ARG RUBY_VER="3.3"
FROM ruby:$RUBY_VER-alpine AS build-env

# 1a) Packages required to build native extensions + runtime libs
ARG BUILD_PACKAGES="build-base curl-dev libxml2-dev libxslt-dev zlib-dev libpq-dev yaml-dev git"
# Note: Added openssl-dev to BUILD_PACKAGES
ARG BUILD_PACKAGES="build-base curl-dev libxml2-dev libxslt-dev zlib-dev libpq-dev yaml-dev git openssl-dev"
ARG RUNTIME_PACKAGES="tzdata libxml2 libxslt curl zlib libpq yaml"

ENV RAILS_ENV=production \
Expand All @@ -16,6 +17,7 @@ ENV RAILS_ENV=production \

RUN apk add --no-cache $BUILD_PACKAGES $RUNTIME_PACKAGES

# Set timezone if needed
RUN cp /usr/share/zoneinfo/Australia/Sydney /etc/localtime && \
echo "Australia/Sydney" > /etc/timezone

Expand All @@ -24,7 +26,7 @@ WORKDIR /app
# Copy Gemfiles first for layer caching
COPY Gemfile* ./

# Configure bundler for Nokogiri to use system libraries
# (If using Nokogiri, configure it to use system libraries)
RUN bundle config build.nokogiri --use-system-libraries

# Install bundler (no docs)
Expand All @@ -36,9 +38,13 @@ RUN bundle install -j2 --retry 3
# Copy the rest of your Rails code
COPY . .

# Remove any stale binstubs referencing dev/test gems
RUN rm -rf bin/*

# Generate binstubs for Puma
RUN bundle binstubs puma --force

# Clean up gem caches, .o/.c files, leftover test dirs
RUN rm -rf vendor/bundle/ruby/3.3.0/cache/*.gem && \
find vendor/bundle/ruby/3.3.0/gems/ -name "*.c" -delete && \
find vendor/bundle/ruby/3.3.0/gems/ -name "*.o" -delete && \
Expand All @@ -64,15 +70,18 @@ ENV RAILS_ENV=production \
BUNDLE_FROZEN=1 \
BUNDLE_PATH=$APP_DIR/vendor/bundle

# Copy only the fully built app (with installed gems) from builder
COPY --from=build-env /app /app

# Create non-privileged user
ARG IMAGE_UID="10001"
RUN adduser -D -g "" -h "/nonexistent" -s "/sbin/nologin" -H -u "${IMAGE_UID}" appuser && \
chown -R appuser:appuser $APP_DIR

USER appuser
EXPOSE 8080

HEALTHCHECK CMD ["wget","--no-verbose","-q","--spider","http://0.0.0.0:8080/auth/authority?health=true"]
# Healthcheck, optional
HEALTHCHECK CMD ["wget", "--no-verbose", "-q", "--spider", "http://0.0.0.0:8080/auth/authority?health=true"]

ENTRYPOINT ["./bin/puma", "-b", "tcp://0.0.0.0:8080"]

0 comments on commit a5c59b4

Please sign in to comment.