This commit is contained in:
Mateusz Gruszczyński
2026-09-16 22:38:45 +02:00
parent bb39ab9dfa
commit e02557bb65
15 changed files with 136 additions and 55 deletions
+51 -13
View File
@@ -1,29 +1,67 @@
# syntax=docker/dockerfile:1.7
ARG RUST_VERSION=1.89
ARG XX_VERSION=1.9.0
FROM --platform=$TARGETPLATFORM rust:${RUST_VERSION}-trixie AS builder-trixie
# Cross-compilation helpers. Builder stages always run on BUILDPLATFORM, so an
# amd64 host can compile arm64 without running rustc/cargo under QEMU.
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-trixie AS builder-trixie
COPY --from=xx / /
WORKDIR /src
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential pkg-config \
&& rm -rf /var/lib/apt/lists/*
COPY Cargo.toml Cargo.lock build.rs ./
&& apt-get install -y --no-install-recommends clang lld llvm file pkg-config
ARG TARGETPLATFORM
RUN xx-apt-get update \
&& xx-apt-get install -y --no-install-recommends xx-c-essentials \
&& rm -rf /var/lib/apt/lists/* \
&& xx-cargo --version >/dev/null
COPY Cargo.toml Cargo.lock ./
RUN --mount=type=cache,id=gree-controller-cargo-registry,target=/usr/local/cargo/registry \
--mount=type=cache,id=gree-controller-cargo-git,target=/usr/local/cargo/git \
cargo fetch --locked
COPY build.rs ./
COPY src ./src
COPY web ./web
COPY lang ./lang
COPY presets ./presets
COPY docs ./docs
RUN cargo build --locked --release
COPY docs/openapi.json ./docs/openapi.json
RUN --mount=type=cache,id=gree-controller-cargo-registry,target=/usr/local/cargo/registry \
--mount=type=cache,id=gree-controller-cargo-git,target=/usr/local/cargo/git \
--mount=type=cache,id=gree-controller-target-trixie,target=/src/target \
set -eux; \
xx-cargo build --locked --release --target-dir /src/target; \
binary="/src/target/$(xx-cargo --print-target-triple)/release/gree-controller"; \
xx-verify "$binary"; \
mkdir -p /out; \
cp "$binary" /out/gree-controller
FROM --platform=$TARGETPLATFORM rust:${RUST_VERSION}-alpine AS builder-alpine
FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-alpine AS builder-alpine
COPY --from=xx / /
WORKDIR /src
RUN apk add --no-cache build-base pkgconfig musl-dev
COPY Cargo.toml Cargo.lock build.rs ./
RUN apk add --no-cache clang lld llvm file pkgconf
ARG TARGETPLATFORM
RUN xx-apk add --no-cache xx-c-essentials \
&& xx-cargo --version >/dev/null
COPY Cargo.toml Cargo.lock ./
RUN --mount=type=cache,id=gree-controller-cargo-registry,target=/usr/local/cargo/registry \
--mount=type=cache,id=gree-controller-cargo-git,target=/usr/local/cargo/git \
cargo fetch --locked
COPY build.rs ./
COPY src ./src
COPY web ./web
COPY lang ./lang
COPY presets ./presets
COPY docs ./docs
RUN cargo build --locked --release
COPY docs/openapi.json ./docs/openapi.json
RUN --mount=type=cache,id=gree-controller-cargo-registry,target=/usr/local/cargo/registry \
--mount=type=cache,id=gree-controller-cargo-git,target=/usr/local/cargo/git \
--mount=type=cache,id=gree-controller-target-alpine,target=/src/target \
set -eux; \
xx-cargo build --locked --release --target-dir /src/target; \
binary="/src/target/$(xx-cargo --print-target-triple)/release/gree-controller"; \
xx-verify "$binary"; \
mkdir -p /out; \
cp "$binary" /out/gree-controller
FROM --platform=$TARGETPLATFORM debian:trixie-slim AS runtime-trixie
ARG BUILD_VERSION=dev
@@ -39,7 +77,7 @@ LABEL io.hass.version="${BUILD_VERSION}" \
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates tzdata jq iproute2 curl \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder-trixie /src/target/release/gree-controller /usr/local/bin/gree-controller
COPY --from=builder-trixie /out/gree-controller /usr/local/bin/gree-controller
COPY ha-addon/run.sh /usr/local/bin/run.sh
RUN chmod 0755 /usr/local/bin/run.sh /usr/local/bin/gree-controller
EXPOSE 8787/tcp
@@ -57,7 +95,7 @@ LABEL io.hass.version="${BUILD_VERSION}" \
org.opencontainers.image.version="${BUILD_VERSION}" \
org.opencontainers.image.architecture="${TARGETARCH}"
RUN apk add --no-cache ca-certificates tzdata jq iproute2 curl
COPY --from=builder-alpine /src/target/release/gree-controller /usr/local/bin/gree-controller
COPY --from=builder-alpine /out/gree-controller /usr/local/bin/gree-controller
COPY ha-addon/run.sh /usr/local/bin/run.sh
RUN chmod 0755 /usr/local/bin/run.sh /usr/local/bin/gree-controller
EXPOSE 8787/tcp