Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
112 lines (88 loc) · 3.11 KB
/
Copy pathDockerfile
File metadata and controls
112 lines (88 loc) · 3.11 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
FROM ruby:4.0.1-slim AS builder
WORKDIR /rails
LABEL org.opencontainers.image.description="IDP for Patchwork Labs"
LABEL org.opencontainers.image.source="https://github.com/patchworklabsorg/idp"
# Install essential build dependencies
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
build-essential \
curl \
pkg-config \
libpq-dev \
unzip \
libffi-dev \
libyaml-dev \
git \
libvips-dev \
libmagickwand-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Bun
RUN curl -fsSL https://bun.sh/install | bash && \
ln -s /root/.bun/bin/bun /usr/local/bin/bun
# Install specific bundler version
RUN gem install bundler -v 2.5.17
# Copy dependency definitions first for better caching
COPY Gemfile Gemfile.lock .ruby-version ./
COPY package.json bun.lock ./
# Set bundle config - IMPORTANT: Removed BUNDLE_PATH to use system location
ENV BUNDLE_GEMFILE=Gemfile \
BUNDLE_JOBS=4 \
BUNDLE_WITHOUT="development:test"
# Install Ruby and JS dependencies
# Added --no-cache to ensure gems are properly installed
RUN bundle config set --local without 'development test' && \
bundle install --no-cache && \
bun install --frozen-lockfile
# Add source code
COPY . .
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# Precompile assets without requiring RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 RAILS_ENV=production ./bin/rails assets:precompile
# Set permissions on executables
RUN chmod +x bin/rails bin/*
# Create a clean runtime image
FROM ruby:4.0.1-slim
# Install runtime dependencies only
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
postgresql-client \
nano \
poppler-utils \
libpq5 \
libvips42 \
libffi8 \
libyaml-0-2 \
curl \
unzip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Bun for runtime
RUN curl -fsSL https://bun.sh/install | bash && \
ln -s /root/.bun/bin/bun /usr/local/bin/bun
# Set editor for credentials
ENV EDITOR=nano
WORKDIR /rails
# Copy gems from builder stage - IMPORTANT: Copy the entire gem installation
COPY --from=builder /usr/local/lib/ruby/gems/ /usr/local/lib/ruby/gems/
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
# Copy node_modules from builder
COPY --from=builder /rails/node_modules /rails/node_modules
# Copy application from builder
COPY --from=builder /rails /rails
# Handle Rubocop config symlinks
RUN ln -sf /rails/.rubocop.yml ~/.rubocop.yml && \
ln -sf /rails/.rubocop_todo.yml ~/.rubocop_todo.yml
# Set application environment
ENV BUNDLE_GEMFILE=Gemfile \
RAILS_ENV=production \
RAILS_SERVE_STATIC_FILES=true \
RAILS_LOG_TO_STDOUT=true
# Create an entrypoint script to verify gem installation
RUN echo '#!/bin/bash\necho "Verifying gem installation..."\nbundle check || bundle install\nexec "$@"' > /rails/bin/docker-entrypoint && \
chmod +x /rails/bin/docker-entrypoint
# Set entry point and default command
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
EXPOSE 3000
CMD ["./bin/thrust", "./bin/rails", "server", "-b", "0.0.0.0", "-p", "3000"]