Compare commits
6 Commits
0460c12a52
...
2f6ddb422a
| Author | SHA1 | Date |
|---|---|---|
|
|
2f6ddb422a | |
|
|
f1c7323a7b | |
|
|
dea1033a33 | |
|
|
efc8114704 | |
|
|
a3131b39b3 | |
|
|
beae48e72e |
|
|
@ -0,0 +1,4 @@
|
|||
target/
|
||||
.git/
|
||||
server/data/
|
||||
server/test.db/
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
platform: 'linux/amd64'
|
||||
branches:
|
||||
exclude: [main]
|
||||
|
||||
pipeline:
|
||||
build:
|
||||
image: 'rust:1.70-alpine3.18'
|
||||
commands:
|
||||
- apk add --no-cache build-base libarchive libarchive-dev
|
||||
- cargo build --verbose
|
||||
when:
|
||||
event: [push]
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
platform: 'linux/amd64'
|
||||
|
||||
branches:
|
||||
exclude: [main]
|
||||
|
||||
pipeline:
|
||||
clippy:
|
||||
image: 'rust:1.70-alpine3.18'
|
||||
commands:
|
||||
- rustup component add clippy
|
||||
- cargo clippy -- --no-deps -Dwarnings
|
||||
when:
|
||||
event: [push]
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
platform: 'linux/amd64'
|
||||
|
||||
branches:
|
||||
exclude: [main]
|
||||
|
||||
pipeline:
|
||||
lint:
|
||||
image: 'rust:1.70-alpine3.18'
|
||||
commands:
|
||||
- rustup component add rustfmt
|
||||
- cargo fmt -- --check
|
||||
when:
|
||||
event: [push]
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,64 @@
|
|||
FROM rust:1.70-alpine3.18 AS builder
|
||||
|
||||
ARG DI_VER=1.2.5
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# RUN apk add --no-cache \
|
||||
# build-base \
|
||||
# curl \
|
||||
# make \
|
||||
# unzip \
|
||||
# pkgconf \
|
||||
# openssl openssl-libs-static openssl-dev \
|
||||
# libarchive-static libarchive-dev \
|
||||
# zlib-static zlib-dev \
|
||||
# bzip2-static bzip2-dev \
|
||||
# xz-static xz-dev \
|
||||
# expat-static expat-dev \
|
||||
# zstd-static zstd-dev \
|
||||
# lz4-static lz4-dev \
|
||||
# acl-static acl-dev
|
||||
RUN apk add --no-cache \
|
||||
build-base \
|
||||
curl \
|
||||
make \
|
||||
unzip \
|
||||
pkgconf \
|
||||
libarchive libarchive-dev
|
||||
|
||||
# Build dumb-init
|
||||
RUN curl -Lo - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \
|
||||
cd "dumb-init-${DI_VER}" && \
|
||||
make SHELL=/bin/sh && \
|
||||
mv dumb-init .. && \
|
||||
cd ..
|
||||
|
||||
COPY . .
|
||||
|
||||
# ENV LIBARCHIVE_STATIC=1 \
|
||||
# LIBARCHIVE_LIB_DIR=/usr/lib \
|
||||
# LIBARCHIVE_INCLUDE_DIR=/usr/include \
|
||||
# LIBARCHIVE_LDFLAGS='-lssl -lcrypto -L/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4'
|
||||
# LIBARCHIVE_LDFLAGS='-L/usr/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4 -lsqlite3'
|
||||
|
||||
RUN cargo build --release && \
|
||||
du -h target/release/rieterd && \
|
||||
readelf -d target/release/rieterd && \
|
||||
chmod +x target/release/rieterd
|
||||
# [ "$(readelf -d target/debug/rieterd | grep NEEDED | wc -l)" = 0 ] && \
|
||||
# chmod +x target/debug/rieterd
|
||||
|
||||
|
||||
FROM alpine:3.18
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache \
|
||||
libarchive
|
||||
|
||||
COPY --from=builder /app/dumb-init /bin/dumb-init
|
||||
COPY --from=builder /app/target/debug/rieterd /bin/rieterd
|
||||
|
||||
ENTRYPOINT ["/bin/dumb-init", "--"]
|
||||
CMD ["/bin/rieterd"]
|
||||
|
|
@ -11,6 +11,9 @@ axum = { version = "0.6.18", features = ["http2"] }
|
|||
clap = { version = "4.3.12", features = ["env", "derive"] }
|
||||
futures = "0.3.28"
|
||||
libarchive = { path = "../libarchive" }
|
||||
sea-orm = { version = "0.12.1", features = ["sqlx-sqlite", "runtime-tokio-rustls", "macros"] }
|
||||
sea-orm-migration = "0.12.1"
|
||||
serde = { version = "1.0.178", features = ["derive"] }
|
||||
sha256 = "1.1.4"
|
||||
tokio = { version = "1.29.1", features = ["full"] }
|
||||
tokio-util = { version = "0.7.8", features = ["io"] }
|
||||
|
|
@ -19,3 +22,9 @@ tower-http = { version = "0.4.1", features = ["fs", "trace"] }
|
|||
tracing = "0.1.37"
|
||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
||||
uuid = { version = "1.4.0", features = ["v4"] }
|
||||
|
||||
[profile.release]
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
strip = true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
use axum::extract::{Query, State};
|
||||
use axum::routing::get;
|
||||
use axum::Json;
|
||||
use axum::Router;
|
||||
use sea_orm::entity::EntityTrait;
|
||||
use sea_orm::query::QueryOrder;
|
||||
use sea_orm::PaginatorTrait;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::db::entities::repo;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Pagination {
|
||||
page: Option<u64>,
|
||||
per_page: Option<u64>,
|
||||
}
|
||||
|
||||
pub fn router() -> Router<crate::Global> {
|
||||
Router::new().route("/repos", get(get_repos))
|
||||
}
|
||||
|
||||
async fn get_repos(
|
||||
State(global): State<crate::Global>,
|
||||
Query(params): Query<Pagination>,
|
||||
) -> crate::Result<Json<Vec<repo::Model>>> {
|
||||
let repos = repo::Entity::find()
|
||||
.order_by_asc(repo::Column::Id)
|
||||
.paginate(&global.db, params.per_page.unwrap_or(25))
|
||||
.fetch_page(params.page.unwrap_or(0))
|
||||
.await?;
|
||||
|
||||
Ok(Json(repos))
|
||||
}
|
||||
|
|
@ -47,6 +47,8 @@ impl Cli {
|
|||
pub async fn run(&self) {
|
||||
self.init_tracing();
|
||||
|
||||
let db = crate::db::init("sqlite://test.db").await.unwrap();
|
||||
|
||||
let config = Config {
|
||||
repo_dir: self.repo_dir.clone(),
|
||||
pkg_dir: self.pkg_dir.clone(),
|
||||
|
|
@ -56,10 +58,12 @@ impl Cli {
|
|||
let global = Global {
|
||||
config,
|
||||
repo_manager: Arc::new(RwLock::new(repo_manager)),
|
||||
db,
|
||||
};
|
||||
|
||||
// build our application with a single route
|
||||
let app = Router::new()
|
||||
.nest("/api", crate::api::router())
|
||||
.merge(crate::repo::router(&global))
|
||||
.with_state(global)
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod repo;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
||||
|
||||
pub use super::repo::Entity as Repo;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
|
||||
#[sea_orm(table_name = "repo")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m_20230730_000001_create_repo_tables"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
// Define how to apply this migration: Create the Bakery table.
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Repo::Table)
|
||||
.col(
|
||||
ColumnDef::new(Repo::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Repo::Name).string().not_null().unique_key())
|
||||
.col(ColumnDef::new(Repo::Description).string())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// Define how to rollback this migration: Drop the Bakery table.
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Repo::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
pub enum Repo {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
Description,
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
mod m20230730_000001_create_repo_tables;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20230730_000001_create_repo_tables::Migration)]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
pub mod entities;
|
||||
mod migrator;
|
||||
|
||||
use migrator::Migrator;
|
||||
use sea_orm::ConnectOptions;
|
||||
use sea_orm::Database;
|
||||
use sea_orm_migration::MigratorTrait;
|
||||
|
||||
pub async fn init<C: Into<ConnectOptions>>(
|
||||
opt: C,
|
||||
) -> Result<sea_orm::DatabaseConnection, sea_orm::DbErr> {
|
||||
let db = Database::connect(opt).await?;
|
||||
|
||||
Migrator::up(&db, None).await?;
|
||||
|
||||
Ok(db)
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ pub type Result<T> = std::result::Result<T, ServerError>;
|
|||
pub enum ServerError {
|
||||
IO(io::Error),
|
||||
Axum(axum::Error),
|
||||
Db(sea_orm::DbErr),
|
||||
}
|
||||
|
||||
impl fmt::Display for ServerError {
|
||||
|
|
@ -17,6 +18,7 @@ impl fmt::Display for ServerError {
|
|||
match self {
|
||||
ServerError::IO(err) => write!(fmt, "{}", err),
|
||||
ServerError::Axum(err) => write!(fmt, "{}", err),
|
||||
ServerError::Db(err) => write!(fmt, "{}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +30,10 @@ impl IntoResponse for ServerError {
|
|||
match self {
|
||||
ServerError::IO(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
ServerError::Axum(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
ServerError::Db(sea_orm::DbErr::RecordNotFound(_)) => {
|
||||
StatusCode::NOT_FOUND.into_response()
|
||||
}
|
||||
ServerError::Db(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -49,3 +55,9 @@ impl From<tokio::task::JoinError> for ServerError {
|
|||
ServerError::IO(err.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<sea_orm::DbErr> for ServerError {
|
||||
fn from(err: sea_orm::DbErr) -> Self {
|
||||
ServerError::Db(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
mod api;
|
||||
mod cli;
|
||||
mod db;
|
||||
mod error;
|
||||
mod repo;
|
||||
|
||||
use clap::Parser;
|
||||
pub use error::{Result, ServerError};
|
||||
use repo::RepoGroupManager;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
|
|
@ -18,6 +21,7 @@ pub struct Config {
|
|||
pub struct Global {
|
||||
config: Config,
|
||||
repo_manager: Arc<RwLock<RepoGroupManager>>,
|
||||
db: DatabaseConnection,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ pub fn router(global: &crate::Global) -> Router<crate::Global> {
|
|||
delete(delete_package).get(serve_repos.clone()),
|
||||
)
|
||||
.fallback(serve_repos)
|
||||
.with_state(global.clone())
|
||||
}
|
||||
|
||||
async fn post_package_archive(
|
||||
|
|
|
|||
Loading…
Reference in New Issue