Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# syntax=docker/dockerfile:1

# Base image
# ==========
# Base stage
# ==========
FROM ruby:3.4.7-alpine AS base

ENV BUNDLE_WITHOUT="development:test" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_DEPLOYMENT="1" \
RAILS_ENV="production"

# ==========
# Build stage
# ==========
FROM base AS build

WORKDIR /app

# Copy dependency manifests first to leverage caching
COPY ./Gemfile /app/Gemfile
COPY ./Gemfile.lock /app/Gemfile.lock

# Install build dependencies and Ruby extensions
RUN apk add --no-cache \
git \
bash \
Expand All @@ -26,12 +33,14 @@ RUN apk add --no-cache \
openssl \
postgresql-dev \
libc6-compat \
libstdc++ && \
bundle config --global without "${BUNDLE_WITHOUT}" && \
libstdc++ \
xz-libs && \
bundle config --global without "${BUNDLE_WITHOUT}" && \
bundle config --global path "${BUNDLE_PATH}" && \
bundle config --global deployment "${BUNDLE_DEPLOYMENT}" && \
bundle config --global retry 5 && \
bundle install && \
# Clean up build artifacts to slim down image
find /usr/local/bundle/ \
\( \
-name "*.c" -o \
Expand All @@ -43,27 +52,38 @@ RUN apk add --no-cache \
\) -delete && \
chmod -R a+r "${BUNDLE_PATH}"

# ==========
# Final stage
# ==========
FROM base
LABEL maintainer="keygen.sh <oss@keygen.sh>"

# Install runtime dependencies (no -dev)
RUN apk add --no-cache \
bash \
postgresql-client \
tzdata \
libc6-compat \
libstdc++ && \
libstdc++ \
xz-libs \
libxml2 \
libxslt && \
adduser -h /app -g keygen -u 1000 -s /bin/bash -D keygen

COPY --from=build --chown=keygen:keygen \
/usr/local/bundle/ /usr/local/bundle

WORKDIR /app
COPY . /app

# Copy Ruby gems from build stage
COPY --from=build --chown=keygen:keygen /usr/local/bundle/ /usr/local/bundle

# Copy application code
COPY --chown=keygen:keygen . .

RUN chmod +x /app/scripts/entrypoint.sh && \
chown -R keygen:keygen /app

# ==========
# Runtime configuration
# ==========
ENV KEYGEN_EDITION="CE" \
KEYGEN_MODE="singleplayer" \
RAILS_LOG_TO_STDOUT="1" \
Expand All @@ -73,4 +93,4 @@ ENV KEYGEN_EDITION="CE" \
USER keygen

ENTRYPOINT ["/app/scripts/entrypoint.sh"]
CMD ["web"]
CMD ["web"]