]> git.puffer.fish Git - matthieu/nova.git/commitdiff
base
authorMatthieuCoder <matthieu@matthieu-dev.xyz>
Wed, 18 Jan 2023 12:03:49 +0000 (16:03 +0400)
committerMatthieuCoder <matthieu@matthieu-dev.xyz>
Wed, 18 Jan 2023 12:03:49 +0000 (16:03 +0400)
.circleci/config.yml [deleted file]
Dockerfile
Makefile
exes/cache/src/main.rs
exes/gateway/src/lib.rs
exes/ratelimit/src/lib.rs
exes/webhook/src/lib.rs
libs/shared/src/nats.rs
libs/shared/src/redis.rs

diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644 (file)
index 0754c1c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-version: 2.1
-
-# Define the jobs we want to run for this project
-jobs:
-  build:
-    machine:
-      image: ubuntu
-    environment:
-      DOCKER_BUILDKIT: 1
-      BUILDX_PLATFORMS: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6
-    steps:
-      - checkout
-      - run:
-          name: Unit Tests
-          command: make test
-      - run:
-          name: Log in to docker hub
-          command: |
-            docker login -u $DOCKER_USER -p $DOCKER_PASS
-      - run:
-          name: Build from dockerfile
-          command: |
-            TAG=edge make build
-      - run:
-          name: Push to docker hub
-          command: |
-            TAG=edge make push
-
-# Orchestrate our job run sequence
-workflows:
-  build_and_test:
-    jobs:
-      - build
-      - test
\ No newline at end of file
index 88525e953daad721e8556d67f930f748e54abd1c..3eba9a00f6abde1859318964ea2c9e4c7e8795fe 100644 (file)
@@ -1,31 +1,33 @@
-# syntax=docker/dockerfile:1
-FROM --platform=$BUILDPLATFORM tonistiigi/xx:master AS xx
-FROM --platform=$BUILDPLATFORM rust:alpine as rbuild
-RUN apk add clang lld protobuf protobuf-dev git build-base mingw-w64-gcc
-COPY . .
-COPY --from=xx / /
+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
 
-ARG TARGETPLATFORM
-RUN xx-cargo build --release --target-dir ./build
+# Planning install
+FROM chef AS planner
+COPY . .
+RUN cargo chef prepare --recipe-path recipe.json
 
-FROM --platform=$BUILDPLATFORM alpine as passwd
-RUN addgroup -S nova && adduser -S nova -G nova
+# Building all targets
+FROM chef AS builder
+COPY --from=planner /app/recipe.json recipe.json
 
-FROM --platform=$BUILDPLATFORM golang:alpine as gbuild
-RUN apk add clang lld
-COPY --from=xx / /
-ARG TARGETPLATFORM
-COPY --from=rbuild /build/release/liball_in_one.a ./build/lib/liball_in_one.a
+# Notice that we are specifying the --target flag!
+RUN cargo chef cook --release --recipe-path recipe.json
 COPY . .
-RUN go build -a -ldflags '-s' -o build/bin/nova cmd/nova/nova.go
+RUN cargo build --release 
 
+# 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
 
-FROM scratch as component
-COPY --from=passwd /etc/passwd /etc/passwd
+# Final os
+FROM runtime-base AS runtime
 ARG COMPONENT
 ENV COMPONENT=${COMPONENT}
-COPY --from=rbuild /build/release/${COMPONENT} /usr/local/bin/
-USER nova
+COPY --from=builder /app/target/release/${COMPONENT} /usr/local/bin/
+USER nova
 ENTRYPOINT /usr/local/bin/${COMPONENT}
-
-FROM scratch as all_in_one
index c1adb771023fc0718dcecf9e8c4fa9a38171aa50..4257bd66ab28e7aa5b781c13b45803a223f9bd0a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,10 +3,6 @@ ifeq ($(OS),Windows_NT)
        EXTENSION += .exe
 endif
 PROJECTS = $(shell find exes/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n')
-PLATFORMS :=
-ifdef BUILDX_PLATFORMS
-       PLATFORMS += --platform ${BUILDX_PLATFORMS}
-endif
 
 # Static libraries
 target/release/lib%.a: libs/%
@@ -31,19 +27,13 @@ build/bin/nova$(EXTENSION): build/lib/liball_in_one.a
        @mkdir -p build/bin
        go build -a -ldflags '-s' -o build/bin/nova cmd/nova/nova.go
 
-docker-%:
-       
-       
-docker: $(PROJECTS:%=docker-%)
 BINS=$(PROJECTS:%=build/bin/%$(EXTENSION))
-bins: $(BINS) build/bin/nova$(EXTENSION)
-
-all: docker bins
+all: $(BINS) build/bin/nova$(EXTENSION)
 
 clean:
        rm -rf build
        rm -rf $(PROJECTS:%=target/release/%$(EXTENSION))
-       rm -rf target/release/liball_in_one.a 
+       rm -rf target/release/liball_in_one.a
 
 test:
        cargo test
index 5d43a46716f2e2391e87808f3cbbafed0cf82df1..c0dff6d3d774f400fa4e0fba5248d24c2467422e 100644 (file)
@@ -1,6 +1,6 @@
-use std::{error::Error, future::IntoFuture};
+use std::{error::Error, future::Future, pin::Pin};
 
-use async_nats::Subscriber;
+use async_nats::{Client, Subscriber};
 use managers::{
     automoderation::Automoderation, bans::Bans, channels::Channels,
     guild_schedules::GuildSchedules, guilds::Guilds, integrations::Integrations, invites::Invites,
@@ -42,7 +42,9 @@ struct Cache {
 async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
     let settings: Settings<CacheConfiguration> = Settings::new("cache").unwrap();
     info!("loaded configuration: {:?}", settings);
-    let nats = settings.nats.into_future().await?;
+    let nats =
+        Into::<Pin<Box<dyn Future<Output = anyhow::Result<Client>> + Send>>>::into(settings.nats)
+            .await?;
 
     let mut cache = Cache::default();
 
index 1f41e5092f7ffdf25f7502f7b05dc415ee76a75c..ddc4bbd36c78c0a150253aec23f9e2debf253730 100644 (file)
@@ -18,7 +18,7 @@ use shared::{
     config::Settings,
     payloads::{CachePayload, DispatchEventTagged},
 };
-use std::{convert::TryFrom, future::IntoFuture, str::FromStr};
+use std::{convert::TryFrom, future::Future, pin::Pin, str::FromStr};
 use tokio::{select, sync::oneshot};
 use tokio_stream::StreamExt;
 use tracing_opentelemetry::OpenTelemetrySpanExt;
@@ -51,7 +51,10 @@ impl Component for GatewayServer {
                 .shard(settings.shard, settings.shard_total)?
                 .build();
 
-            let nats = settings.nats.into_future().await?;
+            let nats = Into::<Pin<Box<dyn Future<Output = anyhow::Result<Client>> + Send>>>::into(
+                settings.nats,
+            )
+            .await?;
             shard.start().await?;
 
             loop {
index 773d56468afd73facf139ab13fe3fbad469855c9..d1bd6e03a27f0b7fe222ba9848e07341fdf3f288 100644 (file)
@@ -15,8 +15,10 @@ use config::Ratelimit;
 use grpc::RLServer;
 use leash::{AnyhowResultFuture, Component};
 use proto::nova::ratelimit::ratelimiter::ratelimiter_server::RatelimiterServer;
+use redis::aio::MultiplexedConnection;
 use shared::config::Settings;
-use std::future::IntoFuture;
+use std::future::Future;
+use std::pin::Pin;
 use tokio::sync::oneshot;
 use tonic::transport::Server;
 
@@ -36,7 +38,10 @@ impl Component for RatelimiterServerComponent {
     ) -> AnyhowResultFuture<()> {
         Box::pin(async move {
             let listening_address = settings.server.listening_adress;
-            let redis = settings.redis.into_future().await?;
+            let redis = Into::<
+                Pin<Box<dyn Future<Output = anyhow::Result<MultiplexedConnection>> + Send>>,
+            >::into(settings.redis)
+            .await?;
 
             let server = RLServer::new(RedisLock::new(redis));
 
index 2f0bb7c64fd954b3c6887fd4dbe4ffe8797d6537..933f38ea9a5e7d5d12271a5c735f232eaf29c843 100644 (file)
 
 mod config;
 mod handler;
-use std::future::IntoFuture;
+use std::{future::Future, pin::Pin};
 
 use crate::{
     config::Webhook,
     handler::{make_service::MakeSvc, WebhookService},
 };
+use async_nats::Client;
 use hyper::Server;
 use leash::{AnyhowResultFuture, Component};
 use shared::config::Settings;
@@ -40,7 +41,10 @@ impl Component for WebhookServer {
 
             let bind = settings.server.listening_adress;
             info!("Nats connected!");
-            let nats = settings.nats.into_future().await?;
+            let nats = Into::<Pin<Box<dyn Future<Output = anyhow::Result<Client>> + Send>>>::into(
+                settings.nats,
+            )
+            .await?;
 
             let make_service = MakeSvc::new(WebhookService {
                 config: settings.config,
index 1d835d34deced1a039fb29cc5f5959dac9871c30..7d4d3d1e9bf0a3ca76290feedfc90ce919b1bf33 100644 (file)
@@ -1,7 +1,4 @@
-use std::{
-    future::{Future, IntoFuture},
-    pin::Pin,
-};
+use std::{future::Future, pin::Pin};
 
 use async_nats::Client;
 use serde::Deserialize;
@@ -11,12 +8,8 @@ pub struct Configuration {
     pub host: String,
 }
 
-impl IntoFuture for Configuration {
-    type Output = anyhow::Result<Client>;
-
-    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
-
-    fn into_future(self) -> Self::IntoFuture {
-        Box::pin(async move { Ok(async_nats::connect(self.host).await?) })
+impl From<Configuration> for Pin<Box<dyn Future<Output = anyhow::Result<Client>> + Send>> {
+    fn from(value: Configuration) -> Self {
+        Box::pin(async move { Ok(async_nats::connect(value.host).await?) })
     }
 }
index 5cae869db2899ff2bcb023242cade6014c765dcd..77aa97f78562780153aa3f76da7e49bf4a528249 100644 (file)
@@ -1,22 +1,18 @@
 use redis::{aio::MultiplexedConnection, Client};
 use serde::Deserialize;
-use std::{
-    future::{Future, IntoFuture},
-    pin::Pin,
-};
+use std::{future::Future, pin::Pin};
 
 #[derive(Clone, Debug, Deserialize)]
 pub struct Configuration {
     pub url: String,
 }
 
-impl IntoFuture for Configuration {
-    type Output = anyhow::Result<MultiplexedConnection>;
-    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
-
-    fn into_future(self) -> Self::IntoFuture {
+impl From<Configuration>
+    for Pin<Box<dyn Future<Output = anyhow::Result<MultiplexedConnection>> + Send>>
+{
+    fn from(value: Configuration) -> Self {
         Box::pin(async move {
-            let con = Client::open(self.url)?;
+            let con = Client::open(value.url)?;
             let (multiplex, ready) = con.create_multiplexed_tokio_connection().await?;
 
             tokio::spawn(ready);