summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieuCoder <matthieu@matthieu-dev.xyz>2023-01-20 16:18:03 +0400
committerMatthieuCoder <matthieu@matthieu-dev.xyz>2023-01-20 16:18:03 +0400
commit8bc43e6ad22676096841569f36748f93f7fde850 (patch)
treede478981603fd18b7436a9ad1ba3b1b9d3d879a6
parentc77cd88ca8a0206c0f48528ed565b327c97f2e38 (diff)
add architectures and cross build
-rw-r--r--.dockerignore3
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock31
-rw-r--r--Cargo.toml1
-rw-r--r--Dockerfile46
-rw-r--r--docker-compose.yaml20
-rw-r--r--exes/gateway/Cargo.toml3
-rw-r--r--exes/gateway/src/main.rs7
-rw-r--r--exes/ratelimit/Cargo.toml3
-rw-r--r--exes/ratelimit/src/main.rs7
-rw-r--r--exes/rest/Cargo.toml3
-rw-r--r--exes/rest/src/main.rs7
-rw-r--r--exes/webhook/Cargo.toml3
-rw-r--r--exes/webhook/src/main.rs7
14 files changed, 38 insertions, 104 deletions
diff --git a/.dockerignore b/.dockerignore
index 27cfb9a..924efbb 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,2 +1,3 @@
target/
-docs/ \ No newline at end of file
+docs/
+bin/ \ No newline at end of file
diff --git a/.gitignore b/.gitignore
index bce375a..056ef90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ config.yml
config/*
build/
*.yml
+bin/ \ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 0552186..da521bd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -777,12 +777,6 @@ dependencies = [
]
[[package]]
-name = "fs_extra"
-version = "1.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
-
-[[package]]
name = "futures"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -885,7 +879,6 @@ dependencies = [
"serde",
"serde_json",
"shared",
- "tikv-jemallocator",
"tokio",
"tokio-stream",
"tracing",
@@ -1953,7 +1946,6 @@ dependencies = [
"serde_json",
"shared",
"test-log",
- "tikv-jemallocator",
"tokio",
"tokio-stream",
"tokio-test",
@@ -2074,7 +2066,6 @@ dependencies = [
"serde",
"serde_json",
"shared",
- "tikv-jemallocator",
"tokio",
"tokio-stream",
"tonic",
@@ -2570,27 +2561,6 @@ dependencies = [
]
[[package]]
-name = "tikv-jemalloc-sys"
-version = "0.5.2+5.3.0-patched"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ec45c14da997d0925c7835883e4d5c181f196fa142f8c19d7643d1e9af2592c3"
-dependencies = [
- "cc",
- "fs_extra",
- "libc",
-]
-
-[[package]]
-name = "tikv-jemallocator"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "20612db8a13a6c06d57ec83953694185a367e16945f66565e8028d2c0bd76979"
-dependencies = [
- "libc",
- "tikv-jemalloc-sys",
-]
-
-[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3291,7 +3261,6 @@ dependencies = [
"serde",
"serde_json",
"shared",
- "tikv-jemallocator",
"tokio",
"tracing",
"twilight-model",
diff --git a/Cargo.toml b/Cargo.toml
index cee8217..2c746fa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,7 +30,6 @@ tracing-futures = "0.2"
tracing-opentelemetry = "0.18"
opentelemetry = { version = "0.18", features = ["rt-tokio"] }
opentelemetry-http = "0.7"
-tikv-jemallocator = "0.5"
criterion = { version = "0.4", features = ["async_tokio"] }
tokio-test = "0.4.2"
diff --git a/Dockerfile b/Dockerfile
index 3eba9a0..3a3c34c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,33 +1,27 @@
-FROM rust AS chef
-USER root
-COPY .cargo .cargo
-RUN cargo install cargo-chef
-RUN apt-get update && apt-get install -y protobuf-compiler
-WORKDIR /app
-
-# Planning install
-FROM chef AS planner
+# syntax=docker/dockerfile:1
+FROM --platform=$BUILDPLATFORM tonistiigi/xx:master AS xx
+FROM --platform=$BUILDPLATFORM rust:alpine as alpine_rbuild
+RUN apk add clang lld protobuf-dev build-base git
+# Copy the xx scripts
+COPY --from=xx / /
+# Copy source code
COPY . .
-RUN cargo chef prepare --recipe-path recipe.json
-
-# Building all targets
-FROM chef AS builder
-COPY --from=planner /app/recipe.json recipe.json
-# Notice that we are specifying the --target flag!
-RUN cargo chef cook --release --recipe-path recipe.json
-COPY . .
-RUN cargo build --release
+RUN --mount=type=cache,target=/root/.cargo/git/db \
+ --mount=type=cache,target=/root/.cargo/registry/cache \
+ --mount=type=cache,target=/root/.cargo/registry/index \
+ cargo fetch
+ARG TARGETPLATFORM
+RUN --mount=type=cache,target=/root/.cargo/git/db \
+ --mount=type=cache,target=/root/.cargo/registry/cache \
+ --mount=type=cache,target=/root/.cargo/registry/index \
+ xx-cargo build --release --target-dir ./build
-# Base os
-FROM debian:latest AS runtime-base
-# RUN addgroup -S nova && adduser -S nova -G nova
-RUN apt-get update && apt-get install ca-certificates -y
+#Copy from the build/<target triple>/release folder to the out folder
+RUN mkdir ./out && cp ./build/*/release/* ./out || true
-# Final os
-FROM runtime-base AS runtime
+FROM alpine AS runtime
ARG COMPONENT
ENV COMPONENT=${COMPONENT}
-COPY --from=builder /app/target/release/${COMPONENT} /usr/local/bin/
-# USER nova
+COPY --from=alpine_rbuild /out/${COMPONENT} /usr/local/bin/
ENTRYPOINT /usr/local/bin/${COMPONENT}
diff --git a/docker-compose.yaml b/docker-compose.yaml
index 04ec54d..e222c20 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -21,7 +21,9 @@ services:
x-bake:
platforms:
- linux/amd64
- - linux/arm64
+ - linux/arm64/v8
+ - linux/arm/v7
+ - linux/arm/v6
args:
- COMPONENT=cache
volumes:
@@ -43,7 +45,9 @@ services:
x-bake:
platforms:
- linux/amd64
- - linux/arm64
+ - linux/arm64/v8
+ - linux/arm/v7
+ - linux/arm/v6
volumes:
- ./config/default.yml:/config/default.yml
environment:
@@ -62,7 +66,9 @@ services:
x-bake:
platforms:
- linux/amd64
- - linux/arm64
+ - linux/arm64/v8
+ - linux/arm/v7
+ - linux/arm/v6
volumes:
- ./config/default.yml:/config/default.yml
environment:
@@ -85,7 +91,9 @@ services:
x-bake:
platforms:
- linux/amd64
- - linux/arm64
+ - linux/arm64/v8
+ - linux/arm/v7
+ - linux/arm/v6
volumes:
- ./config/default.yml:/config/default.yml
environment:
@@ -106,7 +114,9 @@ services:
x-bake:
platforms:
- linux/amd64
- - linux/arm64
+ - linux/arm64/v8
+ - linux/arm/v7
+ - linux/arm/v6
volumes:
- ./config/default.yml:/config/default.yml
environment:
diff --git a/exes/gateway/Cargo.toml b/exes/gateway/Cargo.toml
index 375a020..3916138 100644
--- a/exes/gateway/Cargo.toml
+++ b/exes/gateway/Cargo.toml
@@ -22,6 +22,3 @@ twilight-gateway = { version = "0.14" }
twilight-model = "0.14"
bytes = "1.3.0"
async-nats = "0.26.0"
-
-[target.'cfg(not(target_os = "windows"))'.dependencies]
-tikv-jemallocator = { workspace = true } \ No newline at end of file
diff --git a/exes/gateway/src/main.rs b/exes/gateway/src/main.rs
index 900171c..f1b0298 100644
--- a/exes/gateway/src/main.rs
+++ b/exes/gateway/src/main.rs
@@ -1,11 +1,4 @@
use gateway::GatewayServer;
use leash::ignite;
-#[cfg(not(target_os = "windows"))]
-use tikv_jemallocator::Jemalloc;
-
-#[cfg(not(target_os = "windows"))]
-#[global_allocator]
-static GLOBAL: Jemalloc = Jemalloc;
-
ignite!(GatewayServer);
diff --git a/exes/ratelimit/Cargo.toml b/exes/ratelimit/Cargo.toml
index d7dc554..5be1a34 100644
--- a/exes/ratelimit/Cargo.toml
+++ b/exes/ratelimit/Cargo.toml
@@ -33,9 +33,6 @@ tracing-subscriber = { workspace = true }
test-log = { workspace = true }
env_logger = { workspace = true }
-[target.'cfg(not(target_os = "windows"))'.dependencies]
-tikv-jemallocator = { workspace = true }
-
[[bench]]
name = "bucket"
harness = false
diff --git a/exes/ratelimit/src/main.rs b/exes/ratelimit/src/main.rs
index b764367..2de812b 100644
--- a/exes/ratelimit/src/main.rs
+++ b/exes/ratelimit/src/main.rs
@@ -1,11 +1,4 @@
use leash::ignite;
use ratelimit::RatelimiterServerComponent;
-#[cfg(not(target_os = "windows"))]
-use tikv_jemallocator::Jemalloc;
-
-#[cfg(not(target_os = "windows"))]
-#[global_allocator]
-static GLOBAL: Jemalloc = Jemalloc;
-
ignite!(RatelimiterServerComponent);
diff --git a/exes/rest/Cargo.toml b/exes/rest/Cargo.toml
index d37da95..aed205f 100644
--- a/exes/rest/Cargo.toml
+++ b/exes/rest/Cargo.toml
@@ -30,6 +30,3 @@ hashring = "0.3.0"
tonic = "0.8.3"
tokio-stream = "0.1.11"
dns-lookup = "1.0.8"
-
-[target.'cfg(not(target_os = "windows"))'.dependencies]
-tikv-jemallocator = { workspace = true } \ No newline at end of file
diff --git a/exes/rest/src/main.rs b/exes/rest/src/main.rs
index 1e73e09..fe8ada7 100644
--- a/exes/rest/src/main.rs
+++ b/exes/rest/src/main.rs
@@ -1,11 +1,4 @@
use leash::ignite;
use rest::ReverseProxyServer;
-#[cfg(not(target_os = "windows"))]
-use tikv_jemallocator::Jemalloc;
-
-#[cfg(not(target_os = "windows"))]
-#[global_allocator]
-static GLOBAL: Jemalloc = Jemalloc;
-
ignite!(ReverseProxyServer);
diff --git a/exes/webhook/Cargo.toml b/exes/webhook/Cargo.toml
index 7b4a185..0078a70 100644
--- a/exes/webhook/Cargo.toml
+++ b/exes/webhook/Cargo.toml
@@ -19,6 +19,3 @@ ed25519-dalek = "1"
twilight-model = { version = "0.14" }
async-nats = "0.26.0"
-
-[target.'cfg(not(target_os = "windows"))'.dependencies]
-tikv-jemallocator = "0.5" \ No newline at end of file
diff --git a/exes/webhook/src/main.rs b/exes/webhook/src/main.rs
index bbacda7..f531725 100644
--- a/exes/webhook/src/main.rs
+++ b/exes/webhook/src/main.rs
@@ -1,11 +1,4 @@
use leash::ignite;
use webhook::WebhookServer;
-#[cfg(not(target_os = "windows"))]
-use tikv_jemallocator::Jemalloc;
-
-#[cfg(not(target_os = "windows"))]
-#[global_allocator]
-static GLOBAL: Jemalloc = Jemalloc;
-
ignite!(WebhookServer);