Skip to content

Commit

Permalink
Merge pull request #46 from Hirevo/refactor/workspace
Browse files Browse the repository at this point in the history
Split codebase into a workspace of multiple library crates
  • Loading branch information
Hirevo authored Jul 3, 2020
2 parents 1652f13 + 4e4de0b commit ca2c787
Show file tree
Hide file tree
Showing 80 changed files with 390 additions and 200 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
!docker/postgresql/postgresql-compose.yaml
!docker/startup.sh
!migrations
!src
!alexandrie
!alexandrie-index
!alexandrie-storage
!alexandrie-rendering
!syntect-dumps
!syntect-syntaxes
!syntect-themes
Expand Down
39 changes: 35 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 7 additions & 84 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,84 +1,7 @@
[package]
name = "alexandrie"
version = "0.1.0"
edition = "2018"
authors = ["Nicolas Polomack <nicolas@polomack.eu>"]
description = "An alternative crate registry, implemented in Rust."
repository = "https://github.com/Hirevo/alexandrie"
documentation = "https://crates.polomack.eu/docs/alexandrie"
keywords = ["crates", "cargo", "web", "registry"]
categories = ["development-tools"]
license = "MIT OR Apache-2.0"

default-run = "alexandrie"

[badges]
codecov = { repository = "Hirevo/alexandrie"}

[dependencies]
# core
tide = "0.10.0"

# data types
url = "2.1.1"
semver = { version = "0.10.0", features = ["serde"] }
chrono = { version = "0.4.11", features = ["serde"] }

# file formats
serde = { version = "1.0.111", features = ["derive"] }
json = { package = "serde_json", version = "1.0.53" }
toml = "0.5.6"

# binary parsing
byteorder = "1.3.4"

# (en|de)coding / hashing
ring = "0.16.14"
hex = "0.4.2"
base64 = "0.12.1"
percent-encoding = "2.1.0"

# database
diesel = { version = "1.4.4", features = ["r2d2", "chrono"] }
diesel_migrations = "1.4.0"

# async primitives
async-std = { version = "1.6.0", features = ["unstable", "attributes"] }
futures = "0.3.5"

# error handling
thiserror = "1.0.19"

# README rendering
syntect = "4.2.0"
cmark = { package = "pulldown-cmark", version = "0.7.1" }
flate2 = "1.0.14"
tar = "0.4.28"
ammonia = "3.0.0"

# frontend
handlebars = { version = "3.1.0", features = ["dir_source"], optional = true }
cookie = { version = "0.14.1", features = ["percent-encode"], optional = true }
time = { version = "0.2.16", optional = true }
num-format = { version = "0.4.0", optional = true }
bigdecimal = { version = "0.1.0", features = ["serde"], optional = true }

# git2
git2 = { version = "0.13.6", optional = true }

# logs
log = "0.4.8"
slog = "2.5.2"
slog-stdlog = "4.0.0"
slog-scope = "4.3.0"
slog-term = "2.6.0"
slog-async = "2.5.0"

[features]
default = ["frontend", "sqlite"]
# default = ["frontend", "mysql"]
# default = ["frontend", "postgres"]
frontend = ["handlebars", "num-format", "bigdecimal", "cookie", "time", "diesel/numeric"]
mysql = ["diesel/mysql", "diesel_migrations/mysql"]
sqlite = ["diesel/sqlite", "diesel_migrations/sqlite"]
postgres = ["diesel/postgres", "diesel_migrations/postgres"]
[workspace]
members = [
"alexandrie",
"alexandrie-index",
"alexandrie-storage",
"alexandrie-rendering"
]
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ RUN \
WORKDIR /alexandrie

# copy source data
COPY src src
COPY alexandrie alexandrie
COPY alexandrie-index alexandrie-index
COPY alexandrie-storage alexandrie-storage
COPY alexandrie-rendering alexandrie-rendering
COPY syntect-syntaxes syntect-syntaxes
COPY syntect-themes syntect-themes
COPY migrations migrations
Expand All @@ -39,8 +42,7 @@ COPY Cargo.toml Cargo.toml
COPY Cargo.lock Cargo.lock

# build the app
RUN cargo build --release --no-default-features --features "${DATABASE} frontend git2"

RUN cd alexandrie && cargo build --release --no-default-features --features "${DATABASE} frontend git2"

### Second stage: copy built application
FROM debian:buster-slim as runner
Expand Down
30 changes: 30 additions & 0 deletions alexandrie-index/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "alexandrie-index"
version = "0.1.0"
edition = "2018"
authors = ["Nicolas Polomack <nicolas@polomack.eu>"]
description = "The index management library for Alexandrie, an alternative crate registry."
repository = "https://github.com/Hirevo/alexandrie"
documentation = "https://crates.polomack.eu/docs/alexandrie"
keywords = ["crates", "cargo", "web", "registry"]
categories = ["development-tools"]
license = "MIT OR Apache-2.0"

# [badges]
# codecov = { repository = "Hirevo/alexandrie"}

[dependencies]
# data types
semver = { version = "0.10.0", features = ["serde"] }

# file formats
serde = { version = "1.0.111", features = ["derive"] }
json = { package = "serde_json", version = "1.0.53" }

# error handling
thiserror = "1.0.19"

# git2
git2 = { version = "0.13.6", optional = true }

[features]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use crate::index::cli::CommandLineIndex;
use crate::cli::CommandLineIndex;

/// The configuration struct for the 'command-line' index management strategy.
///
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub mod cli;
#[cfg(feature = "git2")]
pub mod git2;

use crate::config::index::cli::CommandLineIndexConfig;
use crate::index::Index;
use crate::config::cli::CommandLineIndexConfig;
use crate::Index;

#[cfg(feature = "git2")]
use crate::config::index::git2::Git2IndexConfig;
use crate::config::git2::Git2IndexConfig;

/// The configuration enum for index management strategies.
///
Expand Down
43 changes: 43 additions & 0 deletions alexandrie-index/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use semver::Version;
use thiserror::Error;

/// The Error type for the registry.
///
/// It can represent any kind of error the registry might encounter.
#[derive(Error, Debug)]
pub enum Error {
/// An IO error (file not found, access forbidden, etc...).
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
/// JSON (de)serialization error (invalid JSON parsed, etc...).
#[error("JSON error: {0}")]
JSONError(#[from] json::Error),
/// Git2 error.
#[error("libgit2 error: {0}")]
#[cfg(feature = "git2")]
Git2Error(#[from] git2::Error),
/// Other index-specific error (crate not found, etc...).
#[error("index-specific error: {0}")]
IndexError(#[from] IndexError),
}

/// The Error type for Alexandrie's own errors.
#[derive(Error, Debug)]
pub enum IndexError {
/// The requested crate cannot be found.
#[error("no crate named '{name}' found")]
CrateNotFound {
/// The requested crate's name.
name: String,
},
/// The published crate version is lower than the current hosted version.
#[error("the published version is too low (hosted version is {hosted}, and thus {published} <= {hosted})")]
VersionTooLow {
/// The krate's name.
krate: String,
/// The available hosted version.
hosted: Version,
/// The proposed version to be published.
published: Version,
},
}
4 changes: 2 additions & 2 deletions src/index/cli.rs → alexandrie-index/src/index/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::process::{Command, Stdio};
use semver::{Version, VersionReq};

use crate::error::Error;
use crate::index::tree::Tree;
use crate::index::{CrateVersion, Indexer};
use crate::tree::Tree;
use crate::{CrateVersion, Indexer};

/// The 'command-line' crate index management strategy type.
///
Expand Down
4 changes: 2 additions & 2 deletions src/index/git2.rs → alexandrie-index/src/index/git2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::sync::Mutex;
use semver::{Version, VersionReq};

use crate::error::Error;
use crate::index::tree::Tree;
use crate::index::{CrateVersion, Indexer};
use crate::tree::Tree;
use crate::{CrateVersion, Indexer};

/// The 'git2' crate index management strategy type.
///
Expand Down
7 changes: 7 additions & 0 deletions alexandrie-index/src/index/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Index management through `git` shell command invocations.
pub mod cli;

/// Index management using [**`libgit2`**][libgit2].
/// [libgit2]: https://libgit2.org
#[cfg(feature = "git2")]
pub mod git2;
16 changes: 7 additions & 9 deletions src/index/mod.rs → alexandrie-index/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use semver::{Version, VersionReq};

/// Index management through `git` shell command invocations.
pub mod cli;
pub mod config;
pub mod error;

mod index;
mod models;
mod tree;

/// Index management using [**`libgit2`**][libgit2].
/// [libgit2]: https://libgit2.org
#[cfg(feature = "git2")]
pub mod git2;

pub use index::*;
pub use models::{CrateDependency, CrateDependencyKind, CrateVersion};

use crate::cli::CommandLineIndex;
use crate::error::Error;
use crate::index::cli::CommandLineIndex;

#[cfg(feature = "git2")]
use crate::index::git2::Git2Index;
use crate::git2::Git2Index;

/// The crate indexing management strategy type.
///
Expand Down
File renamed without changes.
Loading

0 comments on commit ca2c787

Please sign in to comment.