Added lib to service
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
RUST_LOG=warn,siren=info
|
||||
RUST_LOG=warn,service=info
|
||||
COMPOSE_PROJECT_NAME=siren
|
||||
|
||||
DATABASE_USER=siren
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "siren"
|
||||
name = "service"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
authors = ["Ben Sherriff <hello@bensherriff.com>"]
|
||||
@@ -7,6 +7,10 @@ repository = "https://github.com/bensherriff/siren"
|
||||
readme = "README.md"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[lib]
|
||||
name = "siren"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.4.0"
|
||||
actix-rt = "2.9.0"
|
||||
|
||||
@@ -1,36 +1,12 @@
|
||||
# Builder
|
||||
FROM rust:1.72.1-bookworm as builder
|
||||
WORKDIR /siren
|
||||
ADD src ./src/
|
||||
ADD Cargo.toml ./
|
||||
RUN apt-get update && apt-get install -y cmake && \
|
||||
cargo build --release --bin siren
|
||||
|
||||
# Packages
|
||||
FROM debian:bullseye-slim as packages
|
||||
WORKDIR /packages
|
||||
RUN apt-get update && apt-get install -y curl tar xz-utils && \
|
||||
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux > yt-dlp && \
|
||||
chmod +x yt-dlp && \
|
||||
curl -L https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz > ffmpeg.tar.xz && \
|
||||
tar -xJf ffmpeg.tar.xz --wildcards */bin/ffmpeg --transform='s/^.*\///' && rm ffmpeg.tar.xz
|
||||
WORKDIR /service
|
||||
USER root
|
||||
|
||||
# FROM debian:bullseye-slim as libraries
|
||||
# WORKDIR /libraries
|
||||
# RUN apt-get update && apt-get install -y unzip && \
|
||||
# curl -L https://download.pytorch.org/libtorch/cu117/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcu117.zip > libtorch.zip && \
|
||||
# unzip libtorch.zip && rm libtorch.zip
|
||||
COPY migrations ./migrations
|
||||
COPY data ./data
|
||||
COPY src ./src
|
||||
COPY Cargo.toml ./
|
||||
|
||||
# Runner
|
||||
FROM debian:bullseye-slim as runtime
|
||||
WORKDIR /siren
|
||||
RUN apt-get update && apt-get install -y libopus-dev libpq5 libpq-dev && apt-get auto-remove -y
|
||||
COPY --from=builder /siren/target/release/siren /usr/local/bin/siren
|
||||
COPY --from=packages /packages /usr/bin
|
||||
# COPY --from=libraries /libraries /usr/lib
|
||||
|
||||
# ARG LIBTORCH=/usr/lib/libtorch
|
||||
# ARG LD_LIBRARY_PATH=${LIBTORCH}/lib:${LD_LIBRARY_PATH}
|
||||
|
||||
# ADD migrations ./
|
||||
CMD ["siren"]
|
||||
RUN cargo build --release
|
||||
CMD ["./target/release/service"]
|
||||
@@ -2,11 +2,6 @@
|
||||
SHELL := /bin/bash
|
||||
|
||||
include .env
|
||||
include .version
|
||||
export $(shell sed 's/=.*//' .env)
|
||||
export $(shell sed 's/=.*//' .version)
|
||||
|
||||
SIREN_IMAGES = $(shell docker images 'siren' -a -q)
|
||||
|
||||
.PHONY: help build test up down exec clean
|
||||
|
||||
@@ -16,10 +11,7 @@ help: ## Help command
|
||||
@echo
|
||||
|
||||
build: ## Build the docker image
|
||||
docker build -t siren:${SIREN_VERSION} .
|
||||
|
||||
test: ## Run the docker app as a container
|
||||
docker run --env-file .env -it --rm --name siren siren:${SIREN_VERSION}
|
||||
docker compose build
|
||||
|
||||
db: ## Start the docker database
|
||||
docker compose up -d db
|
||||
@@ -30,8 +22,8 @@ up: ## Start the app
|
||||
down: ## Stop the app
|
||||
docker compose down
|
||||
|
||||
exec: ## Enter running docker container
|
||||
docker exec -it siren bash
|
||||
|
||||
clean: ## Cleanup docker images
|
||||
docker rmi $(SIREN_IMAGES)
|
||||
clean:
|
||||
docker compose down && \
|
||||
docker image rm siren-service || \
|
||||
docker network rm siren_frontend || \
|
||||
docker network rm siren-backend
|
||||
@@ -1,4 +0,0 @@
|
||||
fn main() {
|
||||
let home = std::env::var("HOME").expect("${HOME} is missing");
|
||||
println!("cargo:rustc-env=LD_LIBRARY_PATH={home}/.pyenv/versions/3.11.4/lib");
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
siren:
|
||||
image: siren:${SIREN_VERSION:-latest}
|
||||
service:
|
||||
image: siren-service:${SIREN_VERSION:-latest}
|
||||
container_name: siren-service
|
||||
build:
|
||||
context: .
|
||||
@@ -16,6 +16,8 @@ services:
|
||||
DATABASE_PORT: 5432
|
||||
SERVICE_HOST: siren
|
||||
SERVICE_PORT: 5000
|
||||
ports:
|
||||
- ${SERVICE_PORT:-5000}:5000
|
||||
depends_on:
|
||||
- db
|
||||
networks:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use siren::ServiceError;
|
||||
|
||||
use crate::{db::schema::messages::{self}, error_handler::ServiceError};
|
||||
use crate::db::schema::messages::{self};
|
||||
|
||||
#[derive(Queryable, Selectable, Serialize, Deserialize)]
|
||||
#[diesel(table_name = messages)]
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use actix_web::{get, post, web, HttpResponse, HttpRequest, ResponseError};
|
||||
use log::error;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use siren::{GetResponse, Metadata, ServiceError};
|
||||
|
||||
use crate::{db::{messages::{QueryMessage, QueryFilters, InsertMessage}, GetResponse, Metadata}, error_handler::ServiceError};
|
||||
use crate::db::messages::{QueryMessage, QueryFilters, InsertMessage};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct GetAllParams {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::error_handler::ServiceError;
|
||||
use diesel::{r2d2::ConnectionManager, PgConnection};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use siren::ServiceError;
|
||||
use crate::diesel_migrations::MigrationHarness;
|
||||
use lazy_static::lazy_static;
|
||||
use log::{error, info};
|
||||
@@ -55,18 +54,3 @@ pub fn connection() -> Result<DbConnection, ServiceError> {
|
||||
pub fn load_data() {
|
||||
spells::load_data();
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GetResponse<T> {
|
||||
pub data: T,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<Metadata>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Metadata {
|
||||
pub total: i32,
|
||||
pub limit: i32,
|
||||
pub page: i32,
|
||||
pub pages: i32
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use siren::ServiceError;
|
||||
|
||||
use crate::{db::{schema::spells::{self}, classes::AbilityType, conditions::ConditionType}, error_handler::ServiceError};
|
||||
use crate::db::{schema::spells::{self}, classes::AbilityType, conditions::ConditionType};
|
||||
|
||||
use super::{SchoolType, CastingTime, CastingType, SpellAttackType, SpellDamageType, Range, Area, Components, Duration, Source, Description, DurationType};
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use actix_web::{get, post, put, delete, web, HttpResponse, HttpRequest, ResponseError};
|
||||
use log::error;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use siren::{GetResponse, Metadata, ServiceError};
|
||||
|
||||
use crate::{db::{spells::{QuerySpell, QueryFilters}, GetResponse, Metadata}, error_handler::ServiceError};
|
||||
use crate::db::spells::{QuerySpell, QueryFilters};
|
||||
|
||||
use super::{Spell, InsertSpell};
|
||||
|
||||
|
||||
@@ -1,9 +1,38 @@
|
||||
use actix_web::{ResponseError, HttpResponse};
|
||||
use diesel::result::Error as DieselError;
|
||||
use reqwest::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
pub id: String,
|
||||
pub guild_id: i64,
|
||||
pub channel_id: i64,
|
||||
pub user_id: i64,
|
||||
pub created: i64,
|
||||
pub model: String,
|
||||
pub request: String,
|
||||
pub response: String,
|
||||
pub request_tags: Vec<String>,
|
||||
pub response_tags: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GetResponse<T> {
|
||||
pub data: T,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<Metadata>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Metadata {
|
||||
pub total: i32,
|
||||
pub limit: i32,
|
||||
pub page: i32,
|
||||
pub pages: i32
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ServiceError {
|
||||
pub status: u16,
|
||||
@@ -40,6 +69,18 @@ impl From<DieselError> for ServiceError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for ServiceError {
|
||||
fn from(error: reqwest::Error) -> ServiceError {
|
||||
ServiceError::new(500, format!("Unknown reqwest error: {}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for ServiceError {
|
||||
fn from(error: serde_json::Error) -> ServiceError {
|
||||
ServiceError::new(500, format!("Unknown serde_json error: {}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl ResponseError for ServiceError {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
let status_code = match StatusCode::from_u16(self.status) {
|
||||
@@ -54,4 +95,4 @@ impl ResponseError for ServiceError {
|
||||
|
||||
HttpResponse::build(status_code).json(serde_json::json!({ "status": status_code.as_u16(), "message": error_message }))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ use actix_web::{HttpServer, App};
|
||||
use dotenv::dotenv;
|
||||
use log::{error, info};
|
||||
|
||||
mod error_handler;
|
||||
mod db;
|
||||
|
||||
#[actix_web::main]
|
||||
|
||||
Reference in New Issue
Block a user