optimize build

This commit is contained in:
41666 2022-12-13 00:07:27 -05:00
parent 9ccd47afa0
commit 267a8c11c3
9 changed files with 66 additions and 184 deletions

0
.env
View file

160
Cargo.lock generated
View file

@ -46,7 +46,6 @@ name = "api"
version = "0.1.0"
dependencies = [
"async-graphql",
"async-graphql-axum",
"axum",
"chrono",
"lazy_static",
@ -97,23 +96,6 @@ dependencies = [
"thiserror",
]
[[package]]
name = "async-graphql-axum"
version = "5.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "077bf197d54397cff2324b79d86a7a21b2a83260e62e33eccae33009427897c9"
dependencies = [
"async-graphql",
"async-trait",
"axum",
"bytes",
"futures-util",
"http-body",
"serde_json",
"tokio-util",
"tower-service",
]
[[package]]
name = "async-graphql-derive"
version = "5.0.3"
@ -215,11 +197,9 @@ checksum = "08b108ad2665fa3f6e6a517c3d80ec3e77d224c47d605167aefaa5d7ef97fa48"
dependencies = [
"async-trait",
"axum-core",
"base64",
"bitflags",
"bytes",
"futures-util",
"headers",
"http",
"http-body",
"hyper",
@ -234,10 +214,8 @@ dependencies = [
"serde_json",
"serde_path_to_error",
"serde_urlencoded",
"sha-1",
"sync_wrapper",
"tokio",
"tokio-tungstenite 0.17.2",
"tower",
"tower-http",
"tower-layer",
@ -343,7 +321,6 @@ dependencies = [
name = "codegen"
version = "0.1.0"
dependencies = [
"futures",
"lazy_static",
"regex",
"reqwest",
@ -363,20 +340,6 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "combine"
version = "4.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
dependencies = [
"bytes",
"futures-core",
"memchr",
"pin-project-lite",
"tokio",
"tokio-util",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@ -813,31 +776,6 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "headers"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584"
dependencies = [
"base64",
"bitflags",
"bytes",
"headers-core",
"http",
"httpdate",
"mime",
"sha1",
]
[[package]]
name = "headers-core"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429"
dependencies = [
"http",
]
[[package]]
name = "heck"
version = "0.4.0"
@ -1453,17 +1391,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "r2d2"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93"
dependencies = [
"log",
"parking_lot 0.12.1",
"scheduled-thread-pool",
]
[[package]]
name = "rand"
version = "0.8.5"
@ -1494,27 +1421,6 @@ dependencies = [
"getrandom",
]
[[package]]
name = "redis"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "513b3649f1a111c17954296e4a3b9eecb108b766c803e2b99f179ebe27005985"
dependencies = [
"async-trait",
"bytes",
"combine",
"futures-util",
"itoa",
"percent-encoding",
"pin-project-lite",
"r2d2",
"ryu",
"sha1_smol",
"tokio",
"tokio-util",
"url",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
@ -1629,15 +1535,6 @@ dependencies = [
"windows-sys 0.36.1",
]
[[package]]
name = "scheduled-thread-pool"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "977a7519bff143a44f842fd07e80ad1329295bd71686457f18e496736f4bf9bf"
dependencies = [
"parking_lot 0.12.1",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -1736,17 +1633,6 @@ dependencies = [
"serde",
]
[[package]]
name = "sha-1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sha1"
version = "0.10.5"
@ -1758,12 +1644,6 @@ dependencies = [
"digest",
]
[[package]]
name = "sha1_smol"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]]
name = "sha2"
version = "0.10.6"
@ -1968,10 +1848,7 @@ name = "tasks"
version = "0.1.0"
dependencies = [
"async_once",
"dotenvy",
"lazy_static",
"once_cell",
"redis",
"sqlx",
"tokio",
]
@ -2122,18 +1999,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokio-tungstenite"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f714dd15bead90401d77e04243611caec13726c2408afd5b31901dfcdcb3b181"
dependencies = [
"futures-util",
"log",
"tokio",
"tungstenite 0.17.3",
]
[[package]]
name = "tokio-tungstenite"
version = "0.18.0"
@ -2145,7 +2010,7 @@ dependencies = [
"native-tls",
"tokio",
"tokio-native-tls",
"tungstenite 0.18.0",
"tungstenite",
]
[[package]]
@ -2156,7 +2021,6 @@ checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740"
dependencies = [
"bytes",
"futures-core",
"futures-io",
"futures-sink",
"pin-project-lite",
"tokio",
@ -2246,25 +2110,6 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "tungstenite"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0"
dependencies = [
"base64",
"byteorder",
"bytes",
"http",
"httparse",
"log",
"rand",
"sha-1",
"thiserror",
"url",
"utf-8",
]
[[package]]
name = "tungstenite"
version = "0.18.0"
@ -2530,7 +2375,6 @@ version = "0.1.0"
dependencies = [
"async_once",
"axum",
"chrono",
"futures",
"futures-util",
"lazy_static",
@ -2539,7 +2383,7 @@ dependencies = [
"serde_json",
"sqlx",
"tokio",
"tokio-tungstenite 0.18.0",
"tokio-tungstenite",
"url",
]

View file

@ -1,18 +1,47 @@
FROM rust:1.65.0-bullseye AS builder
ARG SERVICE
# Step -1: Grab mold
FROM debian:bullseye as mold
RUN apt-get update && apt-get install -y curl
ARG MOLD_VERSION=1.7.1
RUN curl -sSL https://github.com/rui314/mold/releases/download/v${MOLD_VERSION}/mold-${MOLD_VERSION}-x86_64-linux.tar.gz | tar xzv && \
mv mold-${MOLD_VERSION}-x86_64-linux/bin/mold /mold && \
rm -rf mold-${MOLD_VERSION}-x86_64-linux
# Step 1: Compute a recipe file
FROM rust as planner
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
COPY services ./services
COPY hack ./hack
RUN cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
RUN cargo build --bin ${SERVICE} --release
# Step 2: Cache project dependencies
FROM rust as cacher
WORKDIR /app
RUN cargo install cargo-chef
RUN apt-get update && apt-get install -y --no-install-recommends clang
COPY --from=mold /mold /mold
COPY --from=planner /app/recipe.json recipe.json
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
ENV RUSTFLAGS="-C link-arg=-fuse-ld=/mold"
RUN cargo chef cook --release --recipe-path recipe.json
FROM debian:bullseye-slim AS target
# Step 3: Build the binary
FROM rust as builder
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends clang
COPY . .
# Copy over the cached dependencies from above
COPY --from=cacher /app/target target
COPY --from=mold /mold /mold
COPY --from=cacher /usr/local/cargo /usr/local/cargo
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
ENV RUSTFLAGS="-C link-arg=-fuse-ld=/mold"
ARG SERVICE
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/${SERVICE} /app
RUN cargo build --release --bin ${SERVICE}
RUN chmod a+x /app
CMD /app
# Step 4:
# Create a tiny output image.
# It only contains our final binary.
FROM debian:bullseye-slim as runtime
ARG SERVICE
COPY --from=builder /app/target/release/${SERVICE} /app
ENTRYPOINT ["/app"]

18
Dockerfile.old Normal file
View file

@ -0,0 +1,18 @@
FROM rust:1.65.0-bullseye AS builder
ARG SERVICE
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
COPY services ./services
COPY hack ./hack
RUN cargo build --bin ${SERVICE} --release
FROM debian:bullseye-slim AS target
ARG SERVICE
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/${SERVICE} /app
RUN chmod a+x /app
CMD /app

View file

@ -8,7 +8,6 @@ reqwest = { version="0.11.13", features = ["json"] }
tera = { version = "1.17.1", default-features = false }
lazy_static = "1.4.0"
regex = "1.7.0"
futures = "0.3.25"
tokio = { version = "1.22.0", features = ["full"] }
serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.89"

View file

@ -9,10 +9,9 @@ edition = "2021"
serde_json = "1.0.89"
serde = "1.0.149"
async-graphql = { version = "5.0.3", features = ["chrono"] }
async-graphql-axum = "5.0.3"
axum = "0.6.1"
sqlx = { version = "0.6.2", features = [ "runtime-tokio-native-tls", "postgres", "chrono" ] }
tokio = { version = "1.23.0", features = [ "full" ] }
tokio = { version = "1.23.0" }
tower-http = { version = "0.3.5", features = ["cors"] }
lazy_static = "1.4.0"
reqwest = "0.11.13"

View file

@ -6,10 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
redis = { version = "0.22.1", features = ["aio", "r2d2", "tokio-comp"] }
once_cell = "1.16.0"
tokio = { version = "1.23.0", features = ["full"] }
tokio = { version = "1.23.0" }
sqlx = { version = "0.6.2", features = [ "runtime-tokio-native-tls" , "postgres" ] }
lazy_static = "1.4.0"
async_once = "0.2.6"
dotenvy = "0.15.6"

View file

@ -1,5 +1,4 @@
use async_once::AsyncOnce;
use dotenvy::dotenv;
use lazy_static::lazy_static;
use migrations::cmd_migrate;
use sqlx::query;
@ -58,8 +57,6 @@ fn cmd_help() {
#[tokio::main]
async fn main() {
dotenv().ok();
let command = args().nth(1).unwrap_or("help".to_string());
match command.as_str() {

View file

@ -10,7 +10,7 @@ lazy_static = "1.4.0"
tokio-tungstenite = { version = "0.18.0", features=["native-tls"] }
serde = { version = "1.0.149", features = ["derive"] }
serde_json = "1.0.89"
tokio = { version = "1.23.0", features = ["full"] }
tokio = { version = "1.23.0" }
sqlx = { version = "0.6.2", features = [ "runtime-tokio-native-tls" , "postgres" ] }
url = "2.3.1"
futures-util = "0.3.25"
@ -18,4 +18,3 @@ futures = "0.3.25"
async_once = "0.2.6"
serde-aux = "4.1.2"
axum = "0.6.1"
chrono = "0.4.23"