|
1 | 1 | # build openapi-codegen
|
2 |
| -FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.85 AS chef |
| 2 | +FROM rust:1.85 AS openapi-codegen-builder |
| 3 | +ARG RUST_TARGET="x86_64-unknown-linux-musl" |
3 | 4 | WORKDIR /app
|
4 |
| - |
5 |
| -FROM chef AS planner |
6 |
| - |
| 5 | +RUN rustup target add ${RUST_TARGET} |
7 | 6 | COPY Cargo.toml .
|
8 | 7 | COPY Cargo.lock .
|
9 | 8 | COPY build.rs .
|
10 | 9 | COPY src /app/src
|
11 |
| - |
12 |
| -RUN cargo chef prepare --recipe-path recipe.json |
13 |
| - |
14 |
| -FROM chef AS openapi-codegen-builder |
15 |
| - |
16 |
| -COPY --from=planner /app/recipe.json recipe.json |
17 |
| - |
18 |
| -RUN cargo chef cook --release --recipe-path recipe.json |
19 |
| - |
20 |
| -COPY Cargo.toml . |
21 |
| -COPY Cargo.lock . |
22 |
| -COPY build.rs . |
23 |
| -COPY src /app/src |
24 |
| - |
25 |
| -RUN cargo build --release --bin openapi-codegen |
26 |
| - |
27 |
| -# build goimports |
28 |
| -FROM docker.io/golang:1.24-bookworm AS goimports-builder |
29 |
| -RUN go install golang.org/x/tools/cmd/goimports@latest |
| 10 | +RUN cargo build --target ${RUST_TARGET} --release --bin openapi-codegen |
30 | 11 |
|
31 | 12 | # build rubyfmt
|
32 | 13 | FROM docker.io/rust:1.85 AS rubyfmt-builder
|
33 | 14 | WORKDIR /app
|
34 |
| - |
35 | 15 | RUN apt-get update && \
|
36 | 16 | apt-get install -y --no-install-recommends ruby bison && \
|
37 | 17 | apt-get clean
|
38 |
| - |
39 | 18 | RUN git clone https://github.com/fables-tales/rubyfmt.git \
|
40 | 19 | --recurse-submodules --shallow-submodules /app && \
|
41 | 20 | git checkout 71cbb4adc53d3d8b36a6f1b3dcff87865d0204b8
|
42 |
| - |
43 | 21 | RUN cargo build --release
|
44 | 22 |
|
45 |
| -# main container |
46 |
| -FROM docker.io/ubuntu:noble |
47 |
| - |
48 |
| -ENV DEBIAN_FRONTEND=noninteractive |
49 |
| -ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin/:/root/.dotnet/tools:/usr/local/go/bin" |
50 | 23 |
|
51 |
| -RUN apt-get update && \ |
52 |
| - apt-get install -y --no-install-recommends curl default-jre-headless dotnet8 && \ |
53 |
| - apt-get clean |
| 24 | +# build csharpier |
| 25 | +FROM alpine:3.21 AS csharpier-builder |
| 26 | +ARG DOTNET_PLATFORM="linux-musl-amd64" |
| 27 | +WORKDIR /app |
| 28 | +# csharpier defines .net9 in a file called global.json, so we need it on the system even if we don't use it |
| 29 | +RUN apk add git dotnet9-sdk dotnet8-sdk |
| 30 | +RUN git clone https://github.com/belav/csharpier /app && \ |
| 31 | + git checkout f359fbda3dce613f8c69e4680d65727eefee9d16 |
| 32 | +# we build using .net8 |
| 33 | +RUN dotnet publish --framework net8.0 -o output \ |
| 34 | + -r ${DOTNET_PLATFORM} /p:StripSymbols=true \ |
| 35 | + /p:InvariantGlobalization=true /p:SelfContained=true \ |
| 36 | + /p:PublishSingleFile=true Src/CSharpier.Cli |
54 | 37 |
|
55 | 38 |
|
56 |
| -# C# |
57 |
| -RUN dotnet tool install csharpier --version 0.30.6 -g |
| 39 | +# build goimports |
| 40 | +FROM docker.io/golang:1.24-alpine AS goimports-builder |
| 41 | +RUN go install golang.org/x/tools/cmd/goimports@latest |
| 42 | +# will copy /usr/local/go into release image later, trims about 170mb |
| 43 | +RUN rm -rf /usr/local/go/*.md && \ |
| 44 | + rm -rf /usr/local/go/api && \ |
| 45 | + rm -rf /usr/local/go/doc && \ |
| 46 | + rm -rf /usr/local/go/pkg/tool/**/* && \ |
| 47 | + rm -rf /usr/local/go/src/* && \ |
| 48 | + rm -rf /usr/local/go/test/* |
58 | 49 |
|
59 |
| -# # Rust |
60 |
| -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ |
61 |
| - -y \ |
62 |
| - --profile minimal \ |
63 |
| - --no-modify-path \ |
64 |
| - --no-update-default-toolchain \ |
65 |
| - --default-toolchain nightly-2025-02-27 \ |
66 |
| - --component rustfmt |
67 | 50 |
|
| 51 | +# main image |
| 52 | +FROM alpine:3.21 |
| 53 | +ARG RUST_TARGET="x86_64-unknown-linux-musl" |
| 54 | +ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/root/.cargo/bin" |
| 55 | +RUN apk add --no-cache openjdk17-jre-headless curl gcompat libgcc ruff libstdc++ |
68 | 56 |
|
69 |
| -# Javascript |
70 |
| -COPY --from=ghcr.io/biomejs/biome:1.9.4 /usr/local/bin/biome /usr/bin/biome |
71 | 57 |
|
72 |
| -# Python |
73 |
| -COPY --from=ghcr.io/astral-sh/ruff:0.9.8 /ruff /usr/bin/ruff |
| 58 | +# Kotlin |
| 59 | +RUN echo "5e7eb28a0b2006d1cefbc9213bfc73a8191ec2f85d639ec4fc4ec0cd04212e82 ktfmt-0.54-jar-with-dependencies.jar" > ktfmt-0.54-jar-with-dependencies.jar.sha256 && \ |
| 60 | + curl -fsSL --output ktfmt-0.54-jar-with-dependencies.jar "https://github.com/facebook/ktfmt/releases/download/v0.54/ktfmt-0.54-jar-with-dependencies.jar" && \ |
| 61 | + sha256sum ktfmt-0.54-jar-with-dependencies.jar.sha256 -c && \ |
| 62 | + rm ktfmt-0.54-jar-with-dependencies.jar.sha256 && \ |
| 63 | + mv ktfmt-0.54-jar-with-dependencies.jar /usr/bin/ && \ |
| 64 | + echo "#!/bin/sh" >> /usr/bin/ktfmt && \ |
| 65 | + echo '/usr/bin/java -jar /usr/bin/ktfmt-0.54-jar-with-dependencies.jar $@' >> /usr/bin/ktfmt && \ |
| 66 | + chmod +x /usr/bin/ktfmt |
74 | 67 |
|
75 | 68 | # Java
|
76 | 69 | RUN echo "25157797a0a972c2290b5bc71530c4f7ad646458025e3484412a6e5a9b8c9aa6 google-java-format-1.25.2-all-deps.jar" > google-java-format-1.25.2-all-deps.jar.sha256 && \
|
77 | 70 | curl -fsSL --output google-java-format-1.25.2-all-deps.jar "https://github.com/google/google-java-format/releases/download/v1.25.2/google-java-format-1.25.2-all-deps.jar" && \
|
78 | 71 | sha256sum google-java-format-1.25.2-all-deps.jar.sha256 -c && \
|
79 | 72 | rm google-java-format-1.25.2-all-deps.jar.sha256 && \
|
80 | 73 | mv google-java-format-1.25.2-all-deps.jar /usr/bin/ && \
|
81 |
| - echo '#!/usr/bin/bash\njava -jar /usr/bin/google-java-format-1.25.2-all-deps.jar $@' > /usr/bin/google-java-format && \ |
| 74 | + echo "#!/bin/sh" >> /usr/bin/google-java-format && \ |
| 75 | + echo '/usr/bin/java -jar /usr/bin/google-java-format-1.25.2-all-deps.jar $@' >> /usr/bin/google-java-format && \ |
82 | 76 | chmod +x /usr/bin/google-java-format
|
83 | 77 |
|
84 |
| -# Kotlin |
85 |
| -RUN echo "5e7eb28a0b2006d1cefbc9213bfc73a8191ec2f85d639ec4fc4ec0cd04212e82 ktfmt-0.54-jar-with-dependencies.jar" > ktfmt-0.54-jar-with-dependencies.jar.sha256 && \ |
86 |
| - curl -fsSL --output ktfmt-0.54-jar-with-dependencies.jar "https://github.com/facebook/ktfmt/releases/download/v0.54/ktfmt-0.54-jar-with-dependencies.jar" && \ |
87 |
| - sha256sum ktfmt-0.54-jar-with-dependencies.jar.sha256 -c && \ |
88 |
| - rm ktfmt-0.54-jar-with-dependencies.jar.sha256 && \ |
89 |
| - mv ktfmt-0.54-jar-with-dependencies.jar /usr/bin/ && \ |
90 |
| - echo '#!/usr/bin/bash\njava -jar /usr/bin/ktfmt-0.54-jar-with-dependencies.jar $@' > /usr/bin/ktfmt && \ |
91 |
| - chmod +x /usr/bin/ktfmt |
92 | 78 |
|
93 |
| -# Go |
94 |
| -COPY --from=goimports-builder /go/bin/goimports /usr/bin |
95 |
| -COPY --from=goimports-builder /usr/local/go/ /usr/local/go/ |
| 79 | +# Javascript |
| 80 | +ARG BIOME_DL_LINK="https://github.com/biomejs/biome/releases/download/cli/v1.9.4/biome-linux-x64-musl" |
| 81 | +ARG BIOME_HASH="02ca13dcbb5d78839e743b315b03c8c8832fa8178bb81c5e29ae5ad45ce96b82" |
| 82 | +RUN echo "${BIOME_HASH} biome" > biome.sha256 && \ |
| 83 | + curl -fsSL --output biome "${BIOME_DL_LINK}" && \ |
| 84 | + sha256sum biome.sha256 -c && \ |
| 85 | + rm biome.sha256 && \ |
| 86 | + mv biome /usr/bin/ && \ |
| 87 | + chmod +x /usr/bin/biome |
96 | 88 |
|
97 | 89 | # openapi-codegen
|
98 |
| -COPY --from=openapi-codegen-builder /app/target/release/openapi-codegen /usr/bin/ |
| 90 | +COPY --from=openapi-codegen-builder /app/target/${RUST_TARGET}/release/openapi-codegen /usr/bin/ |
99 | 91 |
|
100 | 92 | # Ruby
|
101 | 93 | COPY --from=rubyfmt-builder /app/target/release/rubyfmt-main /usr/bin/rubyfmt
|
102 | 94 |
|
| 95 | +# Go |
| 96 | +COPY --from=goimports-builder /usr/local/go/ /usr/local/go/ |
| 97 | +COPY --from=goimports-builder /go/bin/goimports /usr/bin |
| 98 | + |
| 99 | +# C# |
| 100 | +COPY --from=csharpier-builder /app/output/dotnet-csharpier /usr/bin/ |
| 101 | + |
| 102 | +# Rust |
| 103 | +# All of this craziness reduces the image size by about 600Mb |
| 104 | +RUN apk add --no-cache binutils && \ |
| 105 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ |
| 106 | + -y \ |
| 107 | + --profile minimal \ |
| 108 | + --no-modify-path \ |
| 109 | + --no-update-default-toolchain \ |
| 110 | + --default-toolchain nightly-2025-02-27 \ |
| 111 | + --component rustfmt && \ |
| 112 | + rm -rf /root/.rustup/toolchains/nightly-*/lib/rustlib && \ |
| 113 | + rm /root/.rustup/toolchains/nightly-*/bin/cargo* && \ |
| 114 | + rm /root/.rustup/toolchains/nightly-*/bin/rust-* && \ |
| 115 | + rm /root/.rustup/toolchains/nightly-*/bin/rustc && \ |
| 116 | + rm /root/.rustup/toolchains/nightly-*/bin/rustdoc && \ |
| 117 | + rm -rf /root/.rustup/toolchains/nightly-*/share && \ |
| 118 | + strip /root/.rustup/toolchains/nightly-*/lib/librustc_driver-*.so && \ |
| 119 | + apk del binutils |
0 commit comments