Skip to content

Commit 7c435e8

Browse files
committed
Add new alpine based image
1 parent 60dcc54 commit 7c435e8

File tree

3 files changed

+92
-62
lines changed

3 files changed

+92
-62
lines changed

.github/workflows/docker-release.yml

+13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ jobs:
1818
platform:
1919
- runner: ubuntu-24.04
2020
name: amd64
21+
build-args: |
22+
DOTNET_PLATFORM=linux-musl-amd64
23+
RUST_TARGET=x86_64-unknown-linux-musl
24+
BIOME_DL_LINK=https://github.com/biomejs/biome/releases/download/cli/v1.9.4/biome-linux-x64-musl
25+
BIOME_HASH=02ca13dcbb5d78839e743b315b03c8c8832fa8178bb81c5e29ae5ad45ce96b82
2126
- runner: ubuntu-24.04-arm
2227
name: arm64
28+
build-args: |
29+
DOTNET_PLATFORM=linux-musl-arm64
30+
RUST_TARGET=aarch64-unknown-linux-musl
31+
BIOME_DL_LINK=https://github.com/biomejs/biome/releases/download/cli/v1.9.4/biome-linux-arm64-musl
32+
BIOME_HASH=d34937f7b5a6f816af289e972bfd49827921ed43f44547f78180f3e4f539cc41
2333
name: Build and publish ${{ matrix.platform.name }} docker image
2434
if: github.ref == 'refs/heads/main'
2535
runs-on: "${{ matrix.platform.runner }}"
@@ -41,6 +51,7 @@ jobs:
4151
uses: docker/build-push-action@v6
4252
with:
4353
tags: ${{ env.REGISTRY_IMAGE }}
54+
build-args: ${{ matrix.platform.build-args }}
4455
file: Dockerfile
4556
cache-from: type=gha
4657
cache-to: type=gha
@@ -73,6 +84,8 @@ jobs:
7384
- build
7485
steps:
7586
- uses: actions/checkout@v4
87+
with:
88+
fetch-depth: 0
7689

7790
- name: Download digests
7891
uses: actions/download-artifact@v4

Dockerfile

+78-61
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,119 @@
11
# 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"
34
WORKDIR /app
4-
5-
FROM chef AS planner
6-
5+
RUN rustup target add ${RUST_TARGET}
76
COPY Cargo.toml .
87
COPY Cargo.lock .
98
COPY build.rs .
109
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
3011

3112
# build rubyfmt
3213
FROM docker.io/rust:1.85 AS rubyfmt-builder
3314
WORKDIR /app
34-
3515
RUN apt-get update && \
3616
apt-get install -y --no-install-recommends ruby bison && \
3717
apt-get clean
38-
3918
RUN git clone https://github.com/fables-tales/rubyfmt.git \
4019
--recurse-submodules --shallow-submodules /app && \
4120
git checkout 71cbb4adc53d3d8b36a6f1b3dcff87865d0204b8
42-
4321
RUN cargo build --release
4422

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"
5023

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
5437

5538

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/*
5849

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
6750

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++
6856

69-
# Javascript
70-
COPY --from=ghcr.io/biomejs/biome:1.9.4 /usr/local/bin/biome /usr/bin/biome
7157

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
7467

7568
# Java
7669
RUN echo "25157797a0a972c2290b5bc71530c4f7ad646458025e3484412a6e5a9b8c9aa6 google-java-format-1.25.2-all-deps.jar" > google-java-format-1.25.2-all-deps.jar.sha256 && \
7770
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" && \
7871
sha256sum google-java-format-1.25.2-all-deps.jar.sha256 -c && \
7972
rm google-java-format-1.25.2-all-deps.jar.sha256 && \
8073
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 && \
8276
chmod +x /usr/bin/google-java-format
8377

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
9278

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
9688

9789
# 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/
9991

10092
# Ruby
10193
COPY --from=rubyfmt-builder /app/target/release/rubyfmt-main /usr/bin/rubyfmt
10294

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

src/postprocessing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl PostprocessorLanguage {
104104
// https://github.com/facebook/ktfmt
105105
Self::Kotlin => &[("ktfmt", &["--kotlinlang-style"])],
106106
// https://github.com/belav/csharpier
107-
Self::CSharp => &[("dotnet", &["csharpier", "--fast", "--no-msbuild-check"])],
107+
Self::CSharp => &[("dotnet-csharpier", &["--fast", "--no-msbuild-check"])],
108108
// https://github.com/google/google-java-format
109109
Self::Java => &[("google-java-format", &["-i", "-a"])],
110110
// https://github.com/biomejs/biome

0 commit comments

Comments
 (0)