-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (61 loc) · 2.08 KB
/
Dockerfile
File metadata and controls
79 lines (61 loc) · 2.08 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
# ── Stage 1: Build Go binary (FAST + CACHED) ────────────────────────────────
FROM golang:1.26-alpine AS builder
WORKDIR /build
# Better proxy + deterministic builds
ENV GOPROXY=https://proxy.golang.org,direct \
CGO_ENABLED=0
# Copy deps first (cache friendly)
COPY go.mod go.sum ./
# 🔥 Use BuildKit cache (BIG WIN)
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod download
# Copy source
COPY . .
# Build binary (also cached)
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=linux GOARCH=amd64 \
go build -ldflags="-s -w" -o atstex-lab ./cmd/server/main.go
# ── Stage 2: Runtime with Tectonic (LEAN + STABLE) ──────────────────────────
FROM alpine:3.21
# Install only required runtime deps
RUN apk add --no-cache \
tectonic \
libstdc++ \
fontconfig \
freetype \
ca-certificates
# Cache directory (persist across container runs if mounted)
ENV XDG_CACHE_HOME=/var/cache/tectonic
RUN mkdir -p ${XDG_CACHE_HOME} && chmod 777 ${XDG_CACHE_HOME}
# 🔥 Prewarm Tectonic cache (but optimized layer)
RUN <<EOF
set -e
cat <<LATEX > /tmp/dummy.tex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{geometry,setspace,fancyhdr,array,tabularx,booktabs,longtable}
\usepackage{enumitem,xcolor,graphicx,hyperref,microtype,titlesec}
\usepackage{multicol,etoolbox,latexsym,marvosym,verbatim,tikz}
\usepackage{helvet,mathptmx,palatino,courier,lmodern}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\begin{document}
Hello World
\end{document}
LATEX
tectonic /tmp/dummy.tex
rm -rf /tmp/*
EOF
# Non-root user
RUN adduser -D -u 1001 appuser && \
chown -R appuser:appuser ${XDG_CACHE_HOME}
WORKDIR /home/appuser
# Copy binary only (NO extra files)
COPY --from=builder /build/atstex-lab /usr/local/bin/atstex-lab
USER appuser
EXPOSE 8080
ENV ADDR=:8080
ENTRYPOINT ["/usr/local/bin/atstex-lab"]