-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDockerfile
More file actions
93 lines (72 loc) · 2.89 KB
/
Copy pathDockerfile
File metadata and controls
93 lines (72 loc) · 2.89 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
# Multi-stage Dockerfile for filters-compiler
# Dependencies are cached until package.json/pnpm-lock.yaml change
# Each stage can be built independently via --target
FROM adguard/node-ssh:22.22--0 AS base
SHELL ["/bin/bash", "-lc"]
# Install specific pnpm version for deterministic builds
RUN npm install -g pnpm@10.7.1
WORKDIR /compiler
# pnpm store directory — set once here, no need for pnpm config set in every RUN
ENV npm_config_store_dir=/pnpm-store
# ============================================================================
# Stage: deps
# Cached until package.json/pnpm-lock.yaml changes
# ============================================================================
FROM base AS deps
COPY package.json pnpm-lock.yaml ./
# --ignore-scripts: skips husky install (prepare script) which requires a git repo
RUN --mount=type=cache,target=/pnpm-store,id=compiler-pnpm \
pnpm install \
--frozen-lockfile \
--ignore-scripts \
--prefer-offline
# ============================================================================
# Stage: source
# Cached until source code changes
# Has source + node_modules
# ============================================================================
FROM deps AS source
COPY . /compiler
# ============================================================================
# Stage: lint
# Runs all linting (eslint + tsc)
# ============================================================================
FROM source AS lint
ARG BUILD_RUN_ID=""
RUN --mount=type=cache,target=/pnpm-store,id=compiler-pnpm \
echo "${BUILD_RUN_ID}" > /tmp/.build-run-id && \
pnpm lint && \
mkdir -p /out && \
touch /out/lint.txt
FROM scratch AS lint-output
COPY --from=lint /out/ /
# ============================================================================
# Stage: test
# Builds the package and runs vitest unit tests
# ============================================================================
FROM source AS test
ARG BUILD_RUN_ID=""
RUN --mount=type=cache,target=/pnpm-store,id=compiler-pnpm \
echo "${BUILD_RUN_ID}" > /tmp/.build-run-id && \
pnpm build && \
pnpm test && \
mkdir -p /out && \
touch /out/test.txt
FROM scratch AS test-output
COPY --from=test /out/ /
# ============================================================================
# Stage: full-build
# Builds the library, generates build.txt, and creates the npm package tarball
# ============================================================================
FROM source AS full-build
ARG BUILD_RUN_ID=""
RUN --mount=type=cache,target=/pnpm-store,id=compiler-pnpm \
echo "${BUILD_RUN_ID}" > /tmp/.build-run-id && \
pnpm build && \
pnpm build-txt && \
pnpm pack --out filters-compiler.tgz && \
mkdir -p /out/artifacts && \
mv filters-compiler.tgz /out/artifacts/ && \
cp dist/build.txt /out/artifacts/
FROM scratch AS full-build-output
COPY --from=full-build /out/ /