-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
58 lines (45 loc) · 1.44 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
ARG RUBY_VERSION
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
# The app lives here
WORKDIR /app
# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
curl \
postgresql-client
# Set production environment
ENV BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_CACHE_PATH="/usr/local/bundle/cache" \
BUNDLE_WITHOUT="development"
# Throw-away build stage to reduce size of final image
FROM base as build
# Install build packages
RUN apt-get install --no-install-recommends -y \
build-essential \
git \
libpq-dev \
pkg-config
# Install application gems
COPY Gemfile Gemfile.lock .ruby-version ./
COPY vendor/cache "${BUNDLE_CACHE_PATH}"
RUN bundle install --local
# Copy application code
COPY . .
# Final stage for app image
FROM base
ARG APPUSER=app
ARG APPDIR=/app
# Clean up installation packages to reduce image size
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build $APPDIR $APPDIR
# Run and own only the runtime files as a non-root user for security
RUN mkdir -p log tmp
RUN groupadd --system --gid 1000 $APPUSER
RUN useradd $APPUSER --uid 1000 --gid 1000 --create-home --shell /bin/bash
RUN chown -R $APPUSER:$APPUSER log tmp
USER 1000:1000
# Start the server by default, this can be overwritten at runtime
CMD bin/start