-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.bullseye-slim
130 lines (92 loc) · 2.96 KB
/
Dockerfile.bullseye-slim
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
##
## Base
##
FROM ruby:3.1.2-slim-bullseye as base
# labels from https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL [email protected]
LABEL org.opencontainers.image.created=$CREATED_DATE
LABEL org.opencontainers.image.revision=$SOURCE_COMMIT
LABEL org.opencontainers.image.title="Zero To GraphQL Using Ruby"
LABEL org.opencontainers.image.url=https://hub.docker.com/u/conradwt/zero-to-graphql-using-ruby
LABEL org.opencontainers.image.source=https://github.com/conradwt/zero-to-graphql-using-ruby
LABEL org.opencontainers.image.licenses=MIT
LABEL com.conradtaylor.ruby_version=$RUBY_VERSION
# set this with shell variables at build-time.
# If they aren't set, then not-set will be default.
ARG CREATED_DATE=not-set
ARG SOURCE_COMMIT=not-set
# environment variables
ENV APP_PATH /home/darnoc/app
ENV BUNDLE_PATH /usr/local/bundle/gems
ENV TMP_PATH /tmp/
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_PORT 3000
ENV USER=darnoc
ENV UID=1000
ENV GID=1000
# creates an unprivileged user to be used exclusively to run the Rails app
RUN groupadd --gid 1000 darnoc \
&& useradd --uid 1000 --gid darnoc --shell /bin/bash --create-home darnoc
# copy entrypoint scripts and grant execution permissions
# COPY ./dev-docker-entrypoint.sh /usr/local/bin/dev-entrypoint.sh
# COPY ./test-docker-entrypoint.sh /usr/local/bin/test-entrypoint.sh
# RUN chmod +x /usr/local/bin/dev-entrypoint.sh && chmod +x /usr/local/bin/test-entrypoint.sh
#
# https://www.debian.org/distrib/packages#view
#
# install build and runtime dependencies
RUN apt-get update -qq -y && \
apt-get install -qq --no-install-recommends -y \
build-essential=12.9 \
bzip2=1.0.8-4 \
ca-certificates=20210119 \
curl=7.74.0-1.3+deb11u1 \
libfontconfig1=2.13.1-4.2 \
libpq-dev && \
rm -rf /var/lib/apt/lists/*
ENV RAILS_ENV=production
EXPOSE ${RAILS_PORT}
ENV PORT ${RAILS_PORT}
WORKDIR ${APP_PATH}
COPY Gemfile* ./
RUN gem install bundler && \
rm -rf ${GEM_HOME}/cache/*
RUN bundle config set without 'development test'
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install --jobs 20 --retry 5
COPY . .
RUN chmod +x ./entrypoint.sh
RUN chown -R ${USER}:${USER} ${APP_PATH}
ENTRYPOINT ["/sbin/tini", "--", "./entrypoint.sh"]
##
## Development
##
FROM base as dev
ENV RAILS_ENV=development
# RUN bundle config list
RUN bundle config --delete without
RUN bundle config --delete with
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install --jobs 20 --retry 5
USER ${USER}:${USER}
CMD ["bin/rails", "server", "-b", "0.0.0.0"]
##
## Test
##
FROM dev as test
USER ${USER}:${USER}
CMD ["bundle", "exec", "rspec"]
##
## Pre-Production
##
FROM test as pre-prod
USER root
RUN rm -rf ./spec
##
## Production
##
FROM base as prod
COPY --from=pre-prod ${APP_PATH} ${APP_PATH}
HEALTHCHECK CMD curl http://127.0.0.1/ || exit 1
USER ${USER}:${USER}
CMD ["bin/rails", "server", "-b", "0.0.0.0", "-e", "production"]