-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (55 loc) · 2.25 KB
/
Copy pathDockerfile
File metadata and controls
71 lines (55 loc) · 2.25 KB
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
FROM ruby:3.3.7-slim-bullseye AS build
ENV RUBYOPT='-W:no-deprecated -W:no-experimental'
ENV RAILS_ENV=production
RUN apt update
RUN apt install -y build-essential libsqlite3-dev libyaml-dev
WORKDIR /app
COPY Gemfile Gemfile.lock /app/
RUN gem install bundler
# don't install development, test gems
RUN bundle config set without 'development test'
RUN bundle install --jobs 4 --no-cache --retry 5
COPY . .
# generate master.key and encrypted credentials
RUN EDITOR="mate --wait" bin/rails credentials:edit
RUN bundle exec rails assets:precompile
RUN rails db:setup --trace
# cleanup
RUN apt remove -y build-essential
RUN apt autoremove -y
# more cleanup
RUN rm -rf tmp/cache vendor/assets lib/assets /usr/local/share/.cache /root/.bundle/cache
RUN find / -type f -name "*.c" -exec rm -rf {} +
RUN find / -type f -name "*.h" -exec rm -rf {} +
RUN find / -type f -name "*.hpp" -exec rm -rf {} +
RUN find / -type f -name "*.java" -exec rm -rf {} +
RUN find / -type f -name "*.log" -exec rm -rf {} +
RUN find / -type f -name "*.md" -exec rm -rf {} +
RUN find / -type f -name "*.mk" -exec rm -rf {} +
RUN find / -type f -name "*.o" -exec rm -rf {} +
RUN find / -type f -name "*.txt" -exec rm -rf {} +
RUN find / -type f -name "Makefile" -exec rm -rf {} +
RUN find / -type f -name "*.gem" -exec rm -rf {} +
RUN find / -type f -name "CHANGELOG" -exec rm -rf {} +
RUN find / -type f -name "LICENSE" -exec rm -rf {} +
RUN find / -type f -name "README" -exec rm -rf {} +
RUN find / -type f -name "CHANGES" -exec rm -rf {} +
RUN find / -type f -name "TODO" -exec rm -rf {} +
RUN find / -type f -name "MIT-LICENSE" -exec rm -rf {} +
RUN find / -type f -name "Dockerfile" -exec rm -rf {} +
RUN find / -type f -name ".rspec" -exec rm -rf {} +
RUN find / -type f -name ".rubocop.yml" -exec rm -rf {} +
RUN find / -type f -name "gem_make.out" -exec rm -rf {} +
RUN find / -name "Rakefile" -exec rm -rf {} +
RUN find / -name "spec" -exec rm -rf {} +
# remove the package manager
RUN apt remove -y --allow-remove-essential apt
# Runtime image without unnecessary files/directories
FROM ruby:3.3.7-slim-bullseye AS runtime
COPY --from=build . .
ENV RAILS_ENV=production
ENV RAILS_SERVE_STATIC_FILES=true
ENV RAILS_LOG_TO_STDOUT=true
WORKDIR /app
EXPOSE 3000
CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]