Skip to content

Commit

Permalink
build: even better docker
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkens committed Sep 9, 2024
1 parent 508ef91 commit 1f02677
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
8 changes: 5 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target/
data/
.env
*
!Cargo.toml
!Cargo.lock
!/assets/
!/src/
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ version = "0.3.1"
edition = "2021"

[dependencies]
anyhow = "1.0.86"
axum = "0.7.5"
chrono = { version = "0.4.38", features = ["serde"] }
dotenvy = "0.15.7"
maud = { version = "0.26.0", features = ["axum"] }
reqwest = { version = "0.12.5", features = ["json", "rustls-tls"], default-features = false }
serde_json = "1.0.120"
serde = { version = "1.0.204", features = ["serde_derive"] }
tokio = { version = "1.38.1", features = ["full"] }
serde_json = "1.0.120"
serde_variant = "0.1.3"
sqlx = { version = "0.8.0", features = ["runtime-tokio", "sqlite"] }
chrono = { version = "0.4.38", features = ["serde"] }
anyhow = "1.0.86"
thousands = "0.2.0"
tokio = { version = "1.38.1", features = ["full"] }
tokio-cron-scheduler = "0.11.0"
tracing-subscriber = "0.3.18"
tracing = "0.1.40"
tower-http = { version = "0.5.2", features = ["trace", "cors"] }
dotenvy = "0.15.7"
serde_variant = "0.1.3"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"

[lints.rust]
dead_code = "allow"
Expand Down
17 changes: 7 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,31 @@ WORKDIR /app
ENV PKG_CONFIG_SYSROOT_DIR=/
RUN apk add --no-cache musl-dev openssl-dev zig
RUN cargo install --locked cargo-zigbuild cargo-chef
RUN rustup target add x86_64-unknown-linux-musl && rustup target add aarch64-unknown-linux-musl
RUN rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN true && \
cargo chef cook --recipe-path recipe.json --release --zigbuild --target x86_64-unknown-linux-musl && \
cargo chef cook --recipe-path recipe.json --release --zigbuild --target aarch64-unknown-linux-musl
RUN cargo chef cook --recipe-path recipe.json --release --zigbuild \
--target x86_64-unknown-linux-musl --target aarch64-unknown-linux-musl

COPY . .
RUN mkdir /app/linux && \
cargo zigbuild -r --target aarch64-unknown-linux-musl && \
cargo zigbuild -r --target x86_64-unknown-linux-musl && \
RUN cargo zigbuild -r --target x86_64-unknown-linux-musl --target aarch64-unknown-linux-musl && \
mkdir /app/linux && \
cp target/aarch64-unknown-linux-musl/release/ghstats /app/linux/arm64 && \
cp target/x86_64-unknown-linux-musl/release/ghstats /app/linux/amd64

FROM alpine:latest
FROM alpine:latest AS runtime
LABEL org.opencontainers.image.source="https://github.com/vladkens/ghstats"
ARG TARGETPLATFORM

WORKDIR /app
COPY --from=builder /app/${TARGETPLATFORM} /app/ghstats

ENV HOST=0.0.0.0
ENV PORT=8080
ENV HOST=0.0.0.0 PORT=8080
EXPOSE ${PORT}

HEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/health || exit 1
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ docker-run:

docker-log:
docker logs ghstats --follow

gh-cache-clear:
gh cache delete --all

0 comments on commit 1f02677

Please sign in to comment.