diff --git a/Cargo.lock b/Cargo.lock index 8721dd4d3..f32e41a25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1144,8 +1144,10 @@ dependencies = [ "color-eyre", "dotenvy", "eyre", + "libsqlite3-sys", "mimalloc", "num_cpus", + "pq-sys", "tokio", ] @@ -3133,6 +3135,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ + "cc", "pkg-config", "vcpkg", ] @@ -3749,12 +3752,23 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "pq-src" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28fbf44fbf1d3e50d0ca0c6e6253f65d1bf01bb004a6ea553efb32e7081948c7" +dependencies = [ + "cc", + "openssl-sys", +] + [[package]] name = "pq-sys" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6cc05d7ea95200187117196eee9edd0644424911821aeb28a18ce60ea0b8793" dependencies = [ + "pq-src", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index 330e2612b..797a5fea0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,9 @@ git = "https://github.com/Noelware/azalia" rev = "a08c495a81b37ea6684c94d8b6c67f32b37b67e1" [profile.release] -opt-level = "z" -strip = true -debug = 0 -lto = "thin" +codegen-units = 1 # use a single codegen unit +opt-level = "s" # optimize for size +panic = "abort" # abort the process when a panic occurs +strip = true # strip all debug symbols +debug = 0 # disable debug information +lto = true # perform LTO on all crates (even our own) diff --git a/crates/bin/Cargo.toml b/crates/bin/Cargo.toml index 424ff8125..f7b236a4b 100644 --- a/crates/bin/Cargo.toml +++ b/crates/bin/Cargo.toml @@ -25,6 +25,12 @@ publish.workspace = true repository.workspace = true authors.workspace = true +[features] +default = [] + +bundled-pq = ["dep:pq-sys", "pq-sys/bundled"] +bundled-sqlite = ["dep:libsqlite3-sys", "libsqlite3-sys/bundled"] + [dependencies] charted-cli = { version = "0.1.0", path = "../cli" } charted-core.workspace = true @@ -32,6 +38,8 @@ clap.workspace = true color-eyre = { version = "0.6.3", features = ["issue-url"] } dotenvy = "0.15.7" eyre.workspace = true +libsqlite3-sys = { version = "0.30.1", optional = true } mimalloc = "0.1.43" num_cpus = "1.16.0" +pq-sys = { version = "0.6.3", optional = true } tokio = { workspace = true, features = ["rt", "rt-multi-thread"] } diff --git a/distribution/charted/docker/alpine.Dockerfile b/distribution/charted/docker/alpine.Dockerfile index 07fc165d9..dbf554c3a 100644 --- a/distribution/charted/docker/alpine.Dockerfile +++ b/distribution/charted/docker/alpine.Dockerfile @@ -25,9 +25,7 @@ RUN apk upgrade && apk add --no-cache \ gcompat \ pkgconfig \ openssl-dev \ - build-base \ - sqlite-dev \ - postgresql-dev + build-base WORKDIR /build COPY . . @@ -37,7 +35,7 @@ COPY . . RUN rm rust-toolchain.toml ENV RUSTFLAGS="--cfg tokio_unstable -C link-arg=-fuse-ld=mold -Ctarget-cpu=native -Ctarget-feature=-crt-static" -RUN cargo build --locked --release --package charted +RUN cargo build --locked --release --package charted --features bundled-sqlite --features bundled-pq ##### FINAL STAGE FROM alpine:3.20 @@ -45,10 +43,7 @@ FROM alpine:3.20 RUN apk upgrade && apk add --no-cache \ bash \ tini \ - curl \ - libgcc \ - sqlite-dev \ - postgresql-dev + curl WORKDIR /app/noelware/charted/server diff --git a/distribution/charted/docker/debian.Dockerfile b/distribution/charted/docker/debian.Dockerfile index 20dd68f67..66157eac2 100644 --- a/distribution/charted/docker/debian.Dockerfile +++ b/distribution/charted/docker/debian.Dockerfile @@ -16,55 +16,53 @@ ###### BINARY BUILD FROM rustlang/rust:nightly-bookworm-slim AS build -# ENV DEBIAN_FRONTEND=noninteractive -# RUN apt update && \ -# apt upgrade -y && \ -# apt install -y --no-install-recommends \ -# git \ -# mold \ -# ca-certificates \ -# libssl-dev \ -# build-essential \ -# pkg-config \ -# libpq5 \ -# libsqlite3-0 +ENV DEBIAN_FRONTEND=noninteractive +RUN apt update && \ + apt upgrade -y && \ + apt install -y --no-install-recommends \ + git \ + mold \ + ca-certificates \ + libssl-dev \ + build-essential \ + pkg-config -# WORKDIR /build -# COPY . . +WORKDIR /build +COPY . . -# # We want to use the Nightly version of Rust from the image itself, not what we -# # defined in `rust-toolchain.toml`. -# RUN rm rust-toolchain.toml +# We want to use the Nightly version of Rust from the image itself, not what we +# defined in `rust-toolchain.toml`. +RUN rm rust-toolchain.toml -# ENV RUSTFLAGS="--cfg tokio_unstable -C link-arg=-fuse-ld=mold -Ctarget-cpu=native" -# RUN cargo build --locked --release --package charted +ENV RUSTFLAGS="--cfg tokio_unstable -C link-arg=-fuse-ld=mold -Ctarget-cpu=native" +RUN cargo build --locked --release --package charted --features bundled-sqlite --features bundled-pq ##### FINAL STAGE FROM debian:bookworm-slim -# RUN apt update && apt upgrade -y && apt install -y bash tini curl libssl-dev pkg-config libpq5 libsqlite3-0 +RUN apt update && apt upgrade -y && apt install -y bash tini curl libssl-dev -# WORKDIR /app/noelware/charted/server +WORKDIR /app/noelware/charted/server -# COPY --from=build /build/target/release/charted /app/noelware/charted/server/bin/charted -# COPY distribution/charted/docker/scripts /app/noelware/charted/server/scripts -# COPY distribution/charted/docker/config /app/noelware/charted/server/config +COPY --from=build /build/target/release/charted /app/noelware/charted/server/bin/charted +COPY distribution/charted/docker/scripts /app/noelware/charted/server/scripts +COPY distribution/charted/docker/config /app/noelware/charted/server/config -# ENV CHARTED_DISTRIBUTION_TYPE=docker -# EXPOSE 3651 -# VOLUME /var/lib/noelware/charted/data +ENV CHARTED_DISTRIBUTION_TYPE=docker +EXPOSE 3651 +VOLUME /var/lib/noelware/charted/data -# RUN mkdir -p /var/lib/noelware/charted/data -# RUN groupadd -g 1001 noelware && \ -# useradd -rm -s /bin/bash -g noelware -u 1001 noelware && \ -# chown noelware:noelware /app/noelware/charted/server && \ -# chown noelware:noelware /var/lib/noelware/charted/data && \ -# chmod +x /app/noelware/charted/server/scripts/docker-entrypoint.sh +RUN mkdir -p /var/lib/noelware/charted/data +RUN groupadd -g 1001 noelware && \ + useradd -rm -s /bin/bash -g noelware -u 1001 noelware && \ + chown noelware:noelware /app/noelware/charted/server && \ + chown noelware:noelware /var/lib/noelware/charted/data && \ + chmod +x /app/noelware/charted/server/scripts/docker-entrypoint.sh -# # Create a symbolic link so you can just run `charted` without specifying -# # the full path. -# RUN ln -s /app/noelware/charted/server/bin/charted /usr/bin/charted +# Create a symbolic link so you can just run `charted` without specifying +# the full path. +RUN ln -s /app/noelware/charted/server/bin/charted /usr/bin/charted -# USER noelware -# ENTRYPOINT ["/app/noelware/charted/server/scripts/docker-entrypoint.sh"] -# CMD ["/app/noelware/charted/server/bin/charted", "server"] +USER noelware +ENTRYPOINT ["/app/noelware/charted/server/scripts/docker-entrypoint.sh"] +CMD ["/app/noelware/charted/server/bin/charted", "server"]