-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile.production
More file actions
89 lines (67 loc) · 2.38 KB
/
Dockerfile.production
File metadata and controls
89 lines (67 loc) · 2.38 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# syntax=docker/dockerfile:1
############################
# Base
############################
FROM ruby:3.4.8-slim AS base
# Instala dependências essenciais (incluindo curl para healthcheck)
# hadolint ignore=DL3008
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
curl \
wget \
libpq-dev \
libyaml-dev \
postgresql-client \
tzdata && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
ENV RAILS_ENV=production \
BUNDLE_DEPLOYMENT=1 \
BUNDLE_PATH=/usr/local/bundle \
BUNDLE_WITHOUT=development:test \
MAKEFLAGS="-j2"
WORKDIR /app
############################
# Build Stage
############################
FROM base AS build
# hadolint ignore=DL3008
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
build-essential \
git && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
COPY Gemfile Gemfile.lock ./
# Pin bundler to lockfile version to avoid reinstall on each build
RUN gem install bundler -v "$(grep -A1 'BUNDLED WITH' Gemfile.lock | tail -1 | tr -d ' ')" --no-document
RUN --mount=type=cache,id=prostaff-bundle,target=/usr/local/bundle/cache \
bundle install --jobs 4 --retry 3 && \
rm -rf /usr/local/bundle/ruby/*/bundler/gems/*/.git
COPY . .
# Precompila bootsnap
RUN bundle exec bootsnap precompile --gemfile app/ lib/
############################
# Final Stage
############################
FROM base
# Copia gems e aplicação do estágio de build
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /app /app
# Cria usuário rails
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails /app /usr/local/bundle
# Cria diretórios necessários
RUN mkdir -p /app/tmp/pids /app/tmp/cache /app/tmp/sockets /app/log && \
chown -R rails:rails /app/tmp /app/log
USER rails:rails
# Porta padrão do Coolify
EXPOSE 3000
# Healthcheck para Rails 7+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:3000/up || exit 1
# EntryPoint
COPY --chown=rails:rails deploy/scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# Comando final
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]