Skip to content

Commit

Permalink
Distroless musl build
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcristo committed Apr 29, 2023
1 parent c186c0b commit 28819d5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 183 deletions.
162 changes: 0 additions & 162 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde_json = "1"
# strum_macros = "0.24"
tokio = { version = "1", features = ["full"] }
# tower = { version = "0.4", features = ["full"] }
tower-http = { version = "0.4", features = ["full"] }
tower-http = { version = "0.4", features = ["auth", "fs", "validate-request"] }

[dev-dependencies]
# anyhow = "1"
20 changes: 9 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# syntax=docker/dockerfile:1
FROM rust:alpine AS chef
FROM --platform=linux/amd64 clux/muslrust:stable AS chef
WORKDIR /app
RUN apk add --no-cache build-base
RUN cargo install cargo-chef

FROM chef AS prepare
Expand All @@ -10,16 +9,15 @@ RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS build
COPY --from=prepare /app/recipe.json recipe.json
RUN apk add --no-cache openssl-dev
RUN cargo chef cook --release --recipe-path recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin gpt-html
RUN cargo build --release --target x86_64-unknown-linux-musl --bin gpt-html

FROM alpine AS runtime
ARG COMMIT_SHA
ENV COMMIT_SHA="$COMMIT_SHA"
ENV DOCKER="true"
FROM --platform=linux/amd64 gcr.io/distroless/static AS runtime
WORKDIR /app
COPY --from=build /app/target/release/gpt-html .
ARG COMMIT_SHA
ENV COMMIT_SHA="$COMMIT_SHA" \
DOCKER="true"
COPY --from=build /app/target/x86_64-unknown-linux-musl/release/gpt-html .
EXPOSE 9292
CMD ["/app/gpt-html"]
CMD ["./gpt-html"]
8 changes: 0 additions & 8 deletions src/env.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
use std::env;

use tokio::process::Command;

pub fn print() {
Command::new("env")
.spawn()
.expect("env command failed to start");
}

pub fn commit_sha() -> String {
env::var("COMMIT_SHA").unwrap_or_else(|_| "unknown".to_string())
}
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ async fn main() {
println!("Starting server...");

let addr = if env::docker() {
env::print();
SocketAddr::from(([0, 0, 0, 0], 8080))
} else {
SocketAddr::from(([127, 0, 0, 1], 8080))
Expand Down

0 comments on commit 28819d5

Please sign in to comment.