-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
224 lines (177 loc) · 6.04 KB
/
Dockerfile
File metadata and controls
224 lines (177 loc) · 6.04 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# TypeCraft - Multi-stage Dockerfile
# Conformidade: Constituição Vértice v3.0
# P1 (Completude): All system dependencies included
# P4 (Rastreabilidade): All versions documented
# ==============================================================================
# Stage 1: Builder - Compile Go binaries
# ==============================================================================
FROM golang:1.24-alpine AS builder
LABEL maintainer="JuanCS-Dev (juan@vertice-maximus.com)"
LABEL description="TypeCraft AI-Powered Book Production Engine - Builder Stage"
# Install build dependencies
RUN apk add --no-cache \
git \
make \
gcc \
musl-dev
WORKDIR /app
# Copy dependency files first (layer caching optimization)
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build binaries
# P6 (Eficiência): Static linking for smaller binaries
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o bin/api ./cmd/api
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o bin/worker ./cmd/worker
# Verify binaries were created (P2 - Validação Preventiva)
RUN test -f bin/api || (echo "ERROR: API binary not found" && exit 1)
RUN test -f bin/worker || (echo "ERROR: Worker binary not found" && exit 1)
# ==============================================================================
# Stage 2: API Runtime - Production API server
# ==============================================================================
FROM alpine:3.19 AS api
LABEL maintainer="JuanCS-Dev (juan@vertice-maximus.com)"
LABEL description="TypeCraft API Server - Production Runtime"
LABEL version="0.1.0"
# Install runtime dependencies
# P1 (Completude): ALL tools required for book production
RUN apk add --no-cache \
ca-certificates \
tzdata \
curl \
pandoc \
texlive \
texlive-luatex \
texlive-xetex \
nodejs \
npm \
chromium \
nss \
freetype \
harfbuzz \
ttf-freefont \
&& rm -rf /var/cache/apk/*
# Puppeteer/PagedJS configuration (solução oficial)
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# Create app user (security best practice)
RUN addgroup -g 1000 typecraft && \
adduser -D -u 1000 -G typecraft typecraft
# Install Node.js dependencies globally
# pagedjs-cli: HTML to PDF rendering
RUN npm install -g pagedjs-cli@0.4.3 \
&& npm cache clean --force
# Create directories
RUN mkdir -p /app/output /app/templates /tmp/typecraft && \
chown -R typecraft:typecraft /app /tmp/typecraft
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/bin/api /usr/local/bin/typecraft-api
# Copy templates (LaTeX, HTML, etc.)
COPY --chown=typecraft:typecraft templates/ /app/templates/
# Set timezone to UTC
ENV TZ=UTC
# Switch to non-root user
USER typecraft
# Expose API port
EXPOSE 8080
# Health check (P2 - Validação Preventiva)
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Entrypoint
ENTRYPOINT ["/usr/local/bin/typecraft-api"]
# ==============================================================================
# Stage 3: Worker Runtime - Async job processor
# ==============================================================================
FROM alpine:3.19 AS worker
LABEL maintainer="JuanCS-Dev (juan@vertice-maximus.com)"
LABEL description="TypeCraft Worker - Async Job Processor"
LABEL version="0.1.0"
# Install runtime dependencies (same as API)
# P1 (Completude): Worker needs ALL conversion tools
RUN apk add --no-cache \
ca-certificates \
tzdata \
pandoc \
texlive \
texlive-luatex \
texlive-xetex \
nodejs \
npm \
&& rm -rf /var/cache/apk/*
# Install Node.js dependencies
RUN npm install -g pagedjs-cli@0.4.3 \
&& npm cache clean --force
# Create app user
RUN addgroup -g 1000 typecraft && \
adduser -D -u 1000 -G typecraft typecraft
# Create directories
RUN mkdir -p /app/output /app/templates /tmp/typecraft && \
chown -R typecraft:typecraft /app /tmp/typecraft
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/bin/worker /usr/local/bin/typecraft-worker
# Copy templates
COPY --chown=typecraft:typecraft templates/ /app/templates/
# Set timezone
ENV TZ=UTC
# Switch to non-root user
USER typecraft
# No exposed ports (worker connects to Redis)
# Entrypoint
ENTRYPOINT ["/usr/local/bin/typecraft-worker"]
# ==============================================================================
# Stage 4: Development - Hot reload for local development
# ==============================================================================
FROM golang:1.24-alpine AS development
LABEL maintainer="JuanCS-Dev (juan@vertice-maximus.com)"
LABEL description="TypeCraft Development Environment"
# Install all dependencies (build + runtime)
RUN apk add --no-cache \
git \
make \
gcc \
musl-dev \
pandoc \
texlive \
texlive-luatex \
texlive-xetex \
nodejs \
npm \
&& rm -rf /var/cache/apk/*
# Install Node.js dependencies
RUN npm install -g pagedjs-cli@0.4.3
# Install air for hot reload
RUN go install github.com/cosmtrek/air@latest
WORKDIR /app
# Copy everything
COPY . .
# Download Go dependencies
RUN go mod download
# Expose ports
EXPOSE 8080
# Use air for hot reload
CMD ["air", "-c", ".air.toml"]
# ==============================================================================
# Build Instructions:
#
# Build API:
# docker build --target api -t typecraft-api:latest .
#
# Build Worker:
# docker build --target worker -t typecraft-worker:latest .
#
# Build Development:
# docker build --target development -t typecraft-dev:latest .
#
# Run with docker-compose:
# docker compose up -d
#
# ==============================================================================
# System Requirements Validation:
# - Pandoc: pandoc --version (should be 2.x+)
# - LaTeX: lualatex --version (should be LuaTeX 1.x+)
# - Node: node --version (should be v18+)
# - Paged.js: pagedjs-cli --version (should be 0.4.x)
# ==============================================================================