-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDockerfile.selfcontained
98 lines (71 loc) · 2.98 KB
/
Dockerfile.selfcontained
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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/intercode
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash -
RUN apt-get install -y libvips42 git build-essential shared-mime-info nodejs libpq-dev && rm -rf /var/lib/apt/lists/*
RUN npm install -g yarn
COPY --chown=www:www Gemfile Gemfile.lock .ruby-version /usr/src/intercode/
RUN bundle config set without 'development test intercode1_import' \
&& 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 package.json yarn.lock .yarnrc.yml /usr/src/intercode/
COPY --chown=www:www doc-site/package.json /usr/src/intercode/doc-site/
COPY --chown=www:www ./.yarn /usr/src/intercode/.yarn
RUN yarn install
COPY --chown=www:www . /usr/src/intercode
### 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 yarn run build
RUN DATABASE_URL=postgresql://fakehost/not_a_real_database bundle exec rails assets:precompile
### test
FROM build AS test
ENV RAILS_ENV test
ENV NODE_ENV test
USER root
RUN apt-get update && apt-get install -y postgresql-client && rm -rf /var/lib/apt/lists/*
### pre-production
FROM build AS pre-production
RUN yarn cache clean
RUN rm -rf .yarn/.cache doc-site
### 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
ENV RAILS_ENV production
ENV NODE_ENV production
USER root
RUN useradd -ms /bin/bash www
RUN apt-get update && apt-get install -y --no-install-recommends libvips42 poppler-utils curl xz-utils libjemalloc2 shared-mime-info libpq5 && rm -rf /var/lib/apt/lists/*
RUN mkdir /opt/node && \
curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-$(echo ${TARGETARCH} | sed 's/amd64/x64/').tar.xz | tar xJ --strip-components=1
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=www /usr/src/intercode /usr/src/intercode
WORKDIR /usr/src/intercode
USER www
ENV PATH=/opt/node/bin:$PATH
CMD bundle exec bin/rails server -p $PORT -b 0.0.0.0