Skip to content

Commit 74c7c51

Browse files
committed
perf(container): optimize LSP images size and structure
1 parent f514c90 commit 74c7c51

File tree

5 files changed

+52
-35
lines changed

5 files changed

+52
-35
lines changed

container/pyrefly/ContainerFile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
# Multi-stage build for Pyrefly
21
ARG VERSION=0.46.0
3-
FROM python:3.12-slim AS builder
4-
ARG VERSION
5-
RUN pip install --no-cache-dir pyrefly==${VERSION}
62

7-
FROM python:3.12-slim
3+
FROM ghcr.io/astral-sh/uv:python3.11-trixie-slim AS builder
84
ARG VERSION
9-
LABEL org.opencontainers.image.version="${VERSION}"
10-
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
5+
RUN uv tool install pyrefly==${VERSION}
6+
7+
FROM gcr.io/distroless/cc-debian12
118
COPY --from=builder /usr/local/bin/pyrefly /usr/local/bin/pyrefly
129

1310
WORKDIR /workspace
14-
ENTRYPOINT ["pyrefly", "lsp"]
11+
ENTRYPOINT ["/usr/local/bin/pyrefly", "lsp"]

container/pyright/ContainerFile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
# Multi-stage build for Pyright
21
ARG VERSION=1.1.407
3-
FROM node:22-slim AS builder
2+
FROM node:22-alpine AS builder
43
ARG VERSION
5-
RUN npm install -g pyright@${VERSION}
4+
WORKDIR /app
5+
RUN apk add --no-cache curl && \
6+
curl -sf https://gobinaries.com/tj/node-prune | sh && \
7+
npm install pyright@${VERSION} && \
8+
npm prune --production && \
9+
/usr/local/bin/node-prune
610

7-
FROM node:22-slim
11+
FROM node:22-alpine
812
ARG VERSION
913
LABEL org.opencontainers.image.version="${VERSION}"
10-
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
11-
COPY --from=builder /usr/local/bin/pyright /usr/local/bin/pyright
12-
COPY --from=builder /usr/local/bin/pyright-langserver /usr/local/bin/pyright-langserver
14+
WORKDIR /app
15+
COPY --from=builder /app/node_modules ./node_modules
16+
ENV PATH="/app/node_modules/.bin:${PATH}"
1317

14-
# Pyright needs node to run
1518
WORKDIR /workspace
1619
ENTRYPOINT ["pyright-langserver", "--stdio"]
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
# Multi-stage build for Rust-analyzer
1+
# Multi-stage build for rust-analyzer
22
ARG VERSION=2025-12-15
3-
FROM debian:bookworm-slim AS builder
3+
FROM rust:slim-bookworm AS builder
44
ARG VERSION
5-
RUN apt-get update && apt-get install -y curl && \
6-
curl -L https://github.com/rust-lang/rust-analyzer/releases/download/${VERSION}/rust-analyzer-x86_64-unknown-linux-gnu.gz | gunzip -c - > /usr/local/bin/rust-analyzer && \
5+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
6+
7+
# Determine architecture and download appropriate binary
8+
# rust-analyzer releases use x86_64-unknown-linux-gnu or aarch64-unknown-linux-gnu
9+
RUN set -eux; \
10+
arch=$(uname -m); \
11+
case "$arch" in \
12+
x86_64) bin="rust-analyzer-x86_64-unknown-linux-gnu.gz" ;; \
13+
aarch64) bin="rust-analyzer-aarch64-unknown-linux-gnu.gz" ;; \
14+
*) echo "Unsupported architecture: $arch"; exit 1 ;; \
15+
esac; \
16+
curl -L "https://github.com/rust-lang/rust-analyzer/releases/download/${VERSION}/${bin}" | gunzip -c - > /usr/local/bin/rust-analyzer; \
717
chmod +x /usr/local/bin/rust-analyzer
818

9-
FROM debian:bookworm-slim
19+
FROM gcr.io/distroless/cc-debian12
1020
ARG VERSION
1121
LABEL org.opencontainers.image.version="${VERSION}"
12-
RUN apt-get update && apt-get install -y libgcc-s1 && rm -rf /var/lib/apt/lists/*
22+
1323
COPY --from=builder /usr/local/bin/rust-analyzer /usr/local/bin/rust-analyzer
1424

1525
WORKDIR /workspace
16-
ENTRYPOINT ["rust-analyzer"]
26+
ENTRYPOINT ["/usr/local/bin/rust-analyzer"]
27+

container/ty/ContainerFile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# ty has built-in LSP
2-
ARG VERSION=0.0.5
3-
FROM ghcr.io/astral-sh/ty:${VERSION}
2+
ARG VERSION=latest
3+
FROM ghcr.io/astral-sh/uv:python3.11-trixie-slim AS builder
44
ARG VERSION
5-
LABEL org.opencontainers.image.version="${VERSION}"
5+
RUN uv tool install ty@${VERSION}
6+
7+
FROM gcr.io/distroless/cc-debian12
8+
COPY --from=builder /usr/local/bin/ty /usr/local/bin/ty
69

710
WORKDIR /workspace
8-
ENTRYPOINT ["ty", "server"]
11+
ENTRYPOINT ["/usr/local/bin/ty", "server"]

container/typescript/ContainerFile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
# Multi-stage build for TypeScript Language Server
21
ARG VERSION=5.1.3
3-
FROM node:22-slim AS builder
2+
FROM node:22-alpine AS builder
43
ARG VERSION
5-
RUN npm install -g typescript-language-server@${VERSION} typescript
4+
WORKDIR /app
5+
RUN apk add --no-cache curl && \
6+
curl -sf https://gobinaries.com/tj/node-prune | sh && \
7+
npm install typescript-language-server@${VERSION} typescript && \
8+
npm prune --production && \
9+
/usr/local/bin/node-prune
610

7-
FROM node:22-slim
11+
FROM node:22-alpine
812
ARG VERSION
913
LABEL org.opencontainers.image.version="${VERSION}"
10-
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
11-
COPY --from=builder /usr/local/bin/typescript-language-server /usr/local/bin/typescript-language-server
12-
COPY --from=builder /usr/local/bin/tsserver /usr/local/bin/tsserver
13-
COPY --from=builder /usr/local/bin/tsc /usr/local/bin/tsc
14+
WORKDIR /app
15+
COPY --from=builder /app/node_modules ./node_modules
16+
ENV PATH="/app/node_modules/.bin:${PATH}"
1417

1518
WORKDIR /workspace
1619
ENTRYPOINT ["typescript-language-server", "--stdio"]

0 commit comments

Comments
 (0)