Skip to content

Commit

Permalink
chore(Dockerfile): fix build and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Jan 21, 2025
1 parent 4127e56 commit 4e6ae75
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 244 deletions.
27 changes: 12 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ARG RUBY_VER="3.3"
FROM ruby:$RUBY_VER-alpine AS build-env

ARG PACKAGES="git libxml2 libxslt build-base curl-dev libxml2-dev libxslt-dev zlib-dev tzdata libpq-dev"
ARG PACKAGES="git libxml2 libxslt build-base curl-dev libxml2-dev libxslt-dev zlib-dev tzdata libpq-dev yaml-dev"

RUN apk update && \
apk upgrade && \
apk add --update --no-cache $PACKAGES && \
cp /usr/share/zoneinfo/Australia/Sydney /etc/localtime && \
echo "Australia/Sydney" > /etc/timezone

ENV APP_DIR /app
ENV APP_DIR="/app"
RUN mkdir $APP_DIR
WORKDIR $APP_DIR

Expand All @@ -19,9 +19,10 @@ COPY Gemfile* $APP_DIR/
RUN gem install bundler
RUN bundle config set without 'test:assets'
RUN bundle config set --local path 'vendor/bundle'
RUN bundle config set --local without 'test development'
RUN bundle config --global frozen 1 \
&& bundle install -j4 --retry 3 \
&& bundle binstubs puma --force \
&& bundle binstubs bundler puma --force \
# Remove unneeded files (cached *.gem, *.o, *.c)
&& rm -rf vendor/bundle/ruby/3.3.0/cache/*.gem \
&& find vendor/bundle/ruby/3.3.0/gems/ -name "*.c" -delete \
Expand All @@ -35,36 +36,32 @@ RUN rm -rf /app/tmp/pids/ && rm -rf /app/spec

FROM ruby:$RUBY_VER-alpine

# Copy just the application to this new image
ENV APP_DIR /app
# Copy the application and bundled gems
ENV APP_DIR="/app"
COPY --from=build-env $APP_DIR $APP_DIR
WORKDIR $APP_DIR

ENV BUNDLE_APP_CONFIG="$APP_DIR/.bundle"

# install packages
ARG PACKAGES="tzdata libxml2 libxslt libc6-compat libpq-dev"
# Install runtime packages
ARG PACKAGES="tzdata libxml2 libxslt libc6-compat libpq-dev yaml-dev"
RUN apk update \
&& apk upgrade \
&& apk add --update --no-cache $PACKAGES

# Create a non-privileged user
# defaults are appuser:10001
ARG IMAGE_UID="10001"
ENV UID=$IMAGE_UID
ENV USER=appuser

# See https://stackoverflow.com/a/55757473/12429735RUN
RUN adduser -D -g "" -h "/nonexistent" -s "/sbin/nologin" -H -u "${UID}" "${USER}"
RUN chown appuser:appuser -R /app/tmp

# NOTE:: this should not be used, instead use `RAILS_MASTER_KEY` env var
RUN chown appuser:appuser -R /app/config/
RUN bundle binstubs bundler --force
RUN chown appuser:appuser -R /app/vendor/bundle # Ensure appuser owns the gems

# Use an unprivileged user.
# Use the unprivileged user
USER appuser:appuser

EXPOSE 8080
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
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"]
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ gem "opentelemetry-sdk"
gem "opentelemetry-exporter-otlp"
gem "opentelemetry-instrumentation-all"

# Runtime debugging
gem "rbtrace"

# Fast JSON parsing
gem "yajl-ruby"
gem "multi_json"
Expand Down
Loading

0 comments on commit 4e6ae75

Please sign in to comment.