forked from foodcoops/foodsoft
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
95 lines (78 loc) · 3.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
FROM ruby:2.7.8 as builder
RUN supercronicUrl=https://github.com/aptible/supercronic/releases/download/v0.1.3/supercronic-linux-amd64 && \
supercronicBin=/usr/local/bin/supercronic && \
supercronicSha1sum=96960ba3207756bb01e6892c978264e5362e117e && \
curl -fsSL -o "$supercronicBin" "$supercronicUrl" && \
echo "$supercronicSha1sum $supercronicBin" | sha1sum -c - && \
chmod +x "$supercronicBin"
ENV PORT=3000 \
SMTP_SERVER_PORT=2525 \
RAILS_ENV=production \
RAILS_LOG_TO_STDOUT=true \
RAILS_SERVE_STATIC_FILES=true
WORKDIR /usr/src/app
RUN --mount=type=cache,target=/var/cache/apt/ \
buildDeps='libmagic-dev mariadb-server nodejs' && \
apt-get update && \
apt-get install --no-install-recommends -y $buildDeps
COPY plugins plugins
COPY config config
COPY config.ru Gemfile Gemfile.lock proc-start Procfile Rakefile VERSION ./
COPY app app
COPY bin bin
COPY db db
COPY lib lib
COPY script script
COPY spec spec
COPY vendor vendor
# install dependencies and generate crontab
RUN --mount=type=cache,target=/usr/local/bundle/ \
echo 'gem: --no-document' >> ~/.gemrc && \
gem install bundler -v 2.4.22 && \
bundle config build.nokogiri "--use-system-libraries" && \
bundle config set --local without 'development test' && \
bundle install -j 4 && \
bundle exec whenever >crontab
FROM builder as compiler
# compile assets with temporary mysql server
RUN --mount=type=cache,target=/usr/local/bundle/ \
export DATABASE_URL=mysql2://localhost/temp?encoding=utf8 && \
export SECRET_KEY_BASE=thisisnotimportantnow && \
/etc/init.d/mariadb start && \
mariadb -e "CREATE DATABASE temp" && \
cp config/app_config.yml.SAMPLE config/app_config.yml && \
cp config/cable.yml.SAMPLE config/cable.yml && \
cp config/database.yml.MySQL_SAMPLE config/database.yml && \
cp config/storage.yml.SAMPLE config/storage.yml && \
RAILS_ENV=production bundle exec rake db:setup assets:precompile && \
/etc/init.d/mariadb stop && \
cp -r /usr/local/bundle /bundle
FROM builder as dev
RUN gem install rubocop-rails rubocop-rspec rubocop-capybara rubocop-factory_bot
FROM builder as app
COPY --from=compiler /bundle /usr/local/bundle
COPY --from=compiler /usr/src/app/public /usr/src/app/public
COPY --from=compiler /usr/src/app/config /usr/src/app/config
# Make relevant dirs and files writable for app user
RUN mkdir -p tmp storage && \
chown nobody config/app_config.yml && \
chown nobody tmp && \
chown nobody storage
COPY docker-entrypoint.sh ./
RUN apt-get install -y gosu
# Run app as unprivileged user
# USER nobody
ARG REVISION
ARG BUILDTIME
LABEL org.opencontainers.image.created=$BUILDTIME
LABEL [email protected]
LABEL org.opencontainers.image.url=https://github.com/foodcoops.at/foodsoft
LABEL org.opencontainers.image.source=https://github.com/foodcoops.at/foodsoft
LABEL org.opencontainers.image.revision=$REVISION
LABEL org.opencontainers.image.vendor=IG-FoodCoops
LABEL org.opencontainers.image.licenses=AGPLv3
EXPOSE 3000
VOLUME /usr/src/app/storage
# cleanup, and by default start web process from Procfile
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["./proc-start", "web"]