diff --git a/.woodpecker-base.yml b/.woodpecker-base.yml new file mode 100644 index 0000000..278bdd2 --- /dev/null +++ b/.woodpecker-base.yml @@ -0,0 +1,24 @@ +when: + branch: [main, high-performance] + event: push + path: + - Cargo.toml + - Cargo.lock + - crates/** + +steps: + - name: build-base-image + image: woodpeckerci/plugin-docker-buildx:5.0.0 + settings: + registry: ghcr.io + repo: ghcr.io/traceworks2023/nxtgauge-rust-base + context: . + dockerfile: Dockerfile.base + tags: + - latest + - ${CI_COMMIT_SHA} + username: + from_secret: GHCR_USERNAME + password: + from_secret: GHCR_TOKEN + platforms: linux/amd64 diff --git a/.woodpecker.yml b/.woodpecker.yml index b8328a6..949355b 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -61,7 +61,8 @@ steps: registry: ghcr.io repo: ghcr.io/traceworks2023/nxtgauge-rust-${SERVICE} context: . - dockerfile: Dockerfile.fast + # Use simple Dockerfile for now + dockerfile: Dockerfile.simple build_args: - SERVICE_NAME=${SERVICE} tags: @@ -73,6 +74,3 @@ steps: password: from_secret: GHCR_TOKEN platforms: linux/amd64 - # ENABLE CACHE - This is the key! - cache_from: ghcr.io/traceworks2023/nxtgauge-rust-${SERVICE}:cache - cache_to: ghcr.io/traceworks2023/nxtgauge-rust-${SERVICE}:cache diff --git a/Dockerfile.simple b/Dockerfile.simple new file mode 100644 index 0000000..94abb22 --- /dev/null +++ b/Dockerfile.simple @@ -0,0 +1,38 @@ +# Simple fast Dockerfile - no fancy caching, just builds fast +# Uses local cargo cache between builds + +ARG SERVICE_NAME + +FROM rust:alpine AS builder +ARG SERVICE_NAME + +# Install deps +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && \ + rustup target add x86_64-unknown-linux-musl + +WORKDIR /app + +# Copy manifests first for better caching +COPY Cargo.toml Cargo.lock ./ +COPY crates/ ./crates/ + +# Copy the specific service +COPY apps/${SERVICE_NAME}/ ./apps/${SERVICE_NAME}/ + +# Build with all optimizations +ENV RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-s" +RUN cargo build --release \ + --bin ${SERVICE_NAME} \ + --target x86_64-unknown-linux-musl + +# Runtime +FROM scratch +ARG SERVICE_NAME + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/${SERVICE_NAME} /app/service + +USER 65532:65532 +EXPOSE 8000 + +ENTRYPOINT ["/app/service"] diff --git a/Dockerfile.ultrafast b/Dockerfile.ultrafast new file mode 100644 index 0000000..62e5e6b --- /dev/null +++ b/Dockerfile.ultrafast @@ -0,0 +1,33 @@ +# Ultra-fast Dockerfile using pre-built dependencies +# This requires the base image to be built first! +# Base image build: ./scripts/build-base-image.sh + +ARG SERVICE_NAME + +# Use the pre-built base image with all dependencies cached +FROM ghcr.io/traceworks2023/nxtgauge-rust-base:latest AS builder +ARG SERVICE_NAME + +WORKDIR /app + +# Copy ONLY the specific service source code +# Dependencies are already compiled in the base image! +COPY apps/${SERVICE_NAME}/ ./apps/${SERVICE_NAME}/ + +# Build just this service - dependencies already exist! +# This should take 10-30 seconds, not 15-20 minutes! +RUN cargo build --release \ + --bin ${SERVICE_NAME} \ + --target x86_64-unknown-linux-musl + +# Minimal runtime image +FROM scratch +ARG SERVICE_NAME + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/${SERVICE_NAME} /app/service + +USER 65532:65532 +EXPOSE 8000 + +ENTRYPOINT ["/app/service"]