-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (34 loc) 路 1.76 KB
/
Copy pathDockerfile
File metadata and controls
36 lines (34 loc) 路 1.76 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
FROM node:lts-alpine AS build
RUN apk add --no-cache zstd tar && corepack enable pnpm
WORKDIR /src
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY patches/ patches/
COPY shims/ shims/
COPY lib/package.json lib/
COPY scripts/ scripts/
RUN pnpm install --frozen-lockfile
COPY lib/ lib/
COPY tsconfig.json ./
RUN pnpm build && cd lib && npm pack --pack-destination /tmp
FROM node:lts-alpine AS runtime
RUN apk add --no-cache zstd \
&& corepack enable \
&& rm -rf /opt/yarn* /usr/local/lib/node_modules/yarn
COPY --from=build /tmp/coderaft-*.tgz /tmp/coderaft.tgz
RUN mkdir -p /usr/local/lib/node_modules/coderaft \
&& tar -xzf /tmp/coderaft.tgz -C /usr/local/lib/node_modules/coderaft --strip-components=1 \
&& ln -s ../lib/node_modules/coderaft/dist/cli.mjs /usr/local/bin/coderaft \
&& rm /tmp/coderaft.tgz \
&& zstd -19 --rm /usr/local/bin/node -o /usr/local/bin/node.zst \
&& printf '#!/bin/sh\nset -e\nzstd -qd /usr/local/bin/node.zst -o /tmp/.node\nmv /tmp/.node /usr/local/bin/node\nchmod +x /usr/local/bin/node\nrm -f /usr/local/bin/node.zst\nexec /usr/local/bin/node "$@"\n' > /usr/local/bin/node \
&& chmod +x /usr/local/bin/node
FROM alpine:3.23
RUN apk add --no-cache bash zstd libstdc++ \
&& mkdir -p /data/workspace /data/home \
&& ln -s /data/home /root \
&& echo '{"type":"module"}' > /data/workspace/package.json \
&& printf 'import { createServer } from "node:http";\n\nconst server = createServer((req, res) => {\n res.writeHead(200, { "Content-Type": "text/plain" });\n res.end("Hello from CodeRaft!\\n");\n});\n\nserver.listen(3000, () => {\n console.log("Server running at http://localhost:3000");\n});\n' > /data/workspace/index.ts
COPY --from=runtime /usr/local/ /usr/local/
VOLUME /data
EXPOSE 6063
CMD ["coderaft", "/data/workspace"]