-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
71 lines (52 loc) · 2.17 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
59
60
61
62
63
64
65
66
67
68
69
70
71
ARG RUBY_VERSION
ARG NODE_VERSION
### dev
FROM ruby:${RUBY_VERSION}-slim as dev
ARG NODE_VERSION
USER root
RUN useradd www
WORKDIR /usr/src/larp_library
RUN apt-get update && apt-get install -y git build-essential shared-mime-info libpq-dev && rm -rf /var/lib/apt/lists/*
COPY --chown=www:www Gemfile Gemfile.lock .ruby-version /usr/src/larp_library/
RUN bundle config set without 'development test' \
&& bundle install -j4 \
&& echo 'Running bundle clean --force' \
&& bundle clean --force \
&& echo 'Copying /usr/local/bundle to /usr/local/bundle-tmp' \
&& cp -R /usr/local/bundle /usr/local/bundle-tmp \
&& echo 'Cleaning cached gems and intermediate build files from /usr/local/bundle-tmp' \
&& rm -rf /usr/local/bundle-tmp/cache/*.gem \
&& find /usr/local/bundle-tmp/gems -name '*.c' -delete \
&& find /usr/local/bundle-tmp/gems -name '*.o' -delete \
&& echo 'Switching the bundle directory for the cleaned one, Raiders of the Lost Ark-style' \
&& rm -rf /usr/local/bundle \
&& mv /usr/local/bundle-tmp /usr/local/bundle
COPY --chown=www:www . /usr/src/larp_library
### build
FROM dev AS build
ENV RAILS_ENV production
ENV NODE_ENV production
ENV AWS_ACCESS_KEY_ID dummy
ENV AWS_SECRET_ACCESS_KEY dummy
RUN DATABASE_URL=postgresql://fakehost/not_a_real_database AWS_S3_BUCKET=fakebucket ASSETS_HOST=fakehost SECRET_KEY_BASE=fakekey bundle exec rails assets:precompile
### ld_preload trickery
FROM ruby:${RUBY_VERSION}-slim as amd64_jemalloc
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
FROM ruby:${RUBY_VERSION}-slim as arm64_jemalloc
ENV LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libjemalloc.so.2
### production
FROM ${TARGETARCH}_jemalloc as production
ARG NODE_VERSION
ARG TARGETARCH
ARG REVISION
ENV RAILS_ENV production
ENV NODE_ENV production
ENV REVISION ${REVISION}
USER root
RUN useradd -ms /bin/bash www
RUN apt-get update && apt-get install -y --no-install-recommends libjemalloc2 shared-mime-info libpq5 && rm -rf /var/lib/apt/lists/*
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=www /usr/src/larp_library /usr/src/larp_library
WORKDIR /usr/src/larp_library
USER www
CMD bundle exec bin/rails server -p $PORT -b 0.0.0.0