-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
95 lines (73 loc) · 2.42 KB
/
Dockerfile.prod
File metadata and controls
95 lines (73 loc) · 2.42 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
# Network Checker - Production Dockerfile
# Clones from git repo at build time
#
# Build with: docker build -f Dockerfile.prod -t network-checker:latest .
# Or use: docker-compose -f docker-compose.prod.yaml build
ARG REPO_URL=https://github.com/fatcat/checker.git
ARG REPO_BRANCH=main
# Build stage
FROM ruby:3.3-slim AS builder
ARG REPO_URL
ARG REPO_BRANCH
# Install build dependencies + git
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libsqlite3-dev \
git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Clone the repository
RUN git clone --depth 1 --branch ${REPO_BRANCH} ${REPO_URL} .
# Install gems
RUN bundle config set --local deployment 'true' && \
bundle config set --local without 'development test' && \
bundle config set --local path 'vendor/bundle' && \
bundle install --jobs 4
# Runtime stage
FROM ruby:3.3-slim
ARG REPO_URL
ARG REPO_BRANCH
# Install runtime dependencies
# - libsqlite3-0: database
# - iputils-ping: ping command for ICMP tests
# - dnsutils: dig/nslookup for DNS tests
# - git: for cloning repo
RUN apt-get update && apt-get install -y --no-install-recommends \
libsqlite3-0 \
iputils-ping \
dnsutils \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN groupadd -g 1000 checker && \
useradd -u 1000 -g checker -s /bin/sh -m checker
WORKDIR /app
# Clone the repository (for application code)
RUN git clone --depth 1 --branch ${REPO_BRANCH} ${REPO_URL} . && \
rm -rf .git
# Copy gems from builder
COPY --from=builder /app/vendor/bundle ./vendor/bundle
# Set ownership
RUN chown -R checker:checker /app
# Create directories for persistent data
RUN mkdir -p /data/db /data/log && \
chown -R checker:checker /data
# Environment variables
ENV RACK_ENV=production \
DATABASE_PATH=/data/db/checker.sqlite3 \
LOG_DIR=/data/log \
PORT=9292
# Switch to non-root user
USER checker
# Configure bundler for deployment (run as checker user)
RUN bundle config set --local deployment 'true' && \
bundle config set --local without 'development test' && \
bundle config set --local path 'vendor/bundle'
# Expose port
EXPOSE 9292
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:9292/health || exit 1
# Start the application
CMD ["bundle", "exec", "puma", "-C", "-", "-b", "tcp://0.0.0.0:9292", "config.ru"]