Skip to content

Commit

Permalink
Frontend Hosting and Docker Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Jan 16, 2025
1 parent 5179b57 commit 2437872
Show file tree
Hide file tree
Showing 40 changed files with 1,203 additions and 453 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ target/
.vscode/
test/
.env
site/node_modules/
docs/node_modules/
nr_tests.env
storage_tests
23 changes: 17 additions & 6 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ url = "2"
## Hashing
digestible = { git = "https://github.com/wyatt-herkamp/digestible.git", features = [
"base64",
"uuid",
"chrono",
] }
digest = { version = "0.10", features = ["std", "alloc"] }
md-5 = "0.10"
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ COPY . /home/build
WORKDIR /home/build

RUN apt-get update; apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_20.x | bash - \
&& curl -sL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh
RUN apt-get install -y libssl-dev pkg-config

WORKDIR /home/build/backend
RUN cargo build --release
# Build Frontend
WORKDIR /home/build/frontend
WORKDIR /home/build/site
RUN npm install
RUN npm run build

WORKDIR /home/build/backend
RUN cargo build --release --features frontend

LABEL org.label-schema.name="nitro_repo" \
org.label-schema.vendor="wyatt-herkamp" \
Expand All @@ -23,13 +23,13 @@ LABEL org.label-schema.name="nitro_repo" \
org.label-schema.description="An open source artifact manager. Written in Rust back end and an Vue front end to create a fast and modern experience"

# The Final Image
FROM rust:slim-bookworm
FROM debian:bookworm-slim

RUN apt-get install libssl1.1
RUN apt-get update -y && apt-get -y install libssl-dev openssl

RUN mkdir -p /opt/nitro-repo
RUN mkdir -p /app
COPY --from=build /home/build/target/release/nitro-repo /app/nitro-repo
COPY --from=build /home/build/target/release/nitro_repo /app/nitro-repo
COPY --from=build /home/build/entrypoint.sh /app/entrypoint.sh
WORKDIR /opt/nitro-repo
ENTRYPOINT ["/bin/sh", "entrypoint.sh"]
Expand Down
7 changes: 2 additions & 5 deletions crates/core/src/storage/storage_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ use std::{fmt::Display, path::PathBuf};

use http::Uri;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::map::IntoIter;
use thiserror::Error;
use tracing::instrument;
use utoipa::ToSchema;

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct StoragePathComponent(String);
Expand Down Expand Up @@ -59,15 +57,15 @@ impl AsRef<str> for StoragePathComponent {
}
}

/// A Storage path is a UTF-8 only path. Where the root is the base of the storage.
/// A Storage path is a UTF-8 only path. Where the root is the base of the repository.
#[derive(Debug, Clone, Hash, PartialEq, Eq, Default)]
pub struct StoragePath {
components: Vec<StoragePathComponent>,
trailing_slash: Option<bool>,
}
impl utoipa::__dev::ComposeSchema for StoragePath {
fn compose(
mut generics: Vec<utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>>,
_: Vec<utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>>,
) -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
utoipa::openapi::ObjectBuilder::new()
.schema_type(utoipa::openapi::schema::SchemaType::new(
Expand Down Expand Up @@ -129,7 +127,6 @@ impl StoragePath {
pub fn is_directory(&self) -> bool {
self.trailing_slash == Some(true)
}

}
impl From<Vec<StoragePathComponent>> for StoragePath {
fn from(value: Vec<StoragePathComponent>) -> Self {
Expand Down
1 change: 0 additions & 1 deletion crates/storage/src/dyn_storage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use nr_core::storage::StoragePath;
use serde_json::Value;
use uuid::Uuid;

use crate::{
Expand Down
3 changes: 1 addition & 2 deletions crates/storage/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::time::SystemTimeError;

use thiserror::Error;

use crate::{
local::{error::LocalStorageError, LocalStorage},
local::error::LocalStorageError,
s3::S3StorageError,
InvalidConfigType, PathCollisionError,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::{fmt::Debug, fs::File, io, path::Path};
use crate::{is_hidden_file, local::error::LocalStorageError, FileMeta};

use super::{
utils::MetadataUtils, FileContent, FileContentBytes, FileHashes, SerdeMime, StorageFileReader,
FileHashes, SerdeMime, StorageFileReader,
};
use chrono::{DateTime, FixedOffset, Local};
use chrono::{DateTime, FixedOffset};

use derive_more::derive::From;
use nr_core::storage::FileTypeCheck;
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/fs/file_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use utoipa::ToSchema;

use crate::{
fs::utils::MetadataUtils,
local::{error::LocalStorageError, LocalStorage},
local::error::LocalStorageError,
meta::RepositoryMeta,
path::PathUtils,
};
Expand Down
2 changes: 2 additions & 0 deletions crates/storage/src/fs/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub enum ExtensionError {
}

pub trait PathUtils {
/// Gets the parent directory of the path or returns an error if it does not exist.
#[allow(unused)]
fn parent_or_err(&self) -> Result<&Path, ParentDirectoryDoesNotExist>;
/// Appends an extension to the path.
fn add_extension(&self, extension: &str) -> Result<PathBuf, ExtensionError>;
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/fs/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
fs::File,
io,
path::{Path, PathBuf},
path::PathBuf,
};

use chrono::{offset::LocalResult, DateTime, FixedOffset, Local, TimeZone};
Expand Down
22 changes: 17 additions & 5 deletions crates/storage/src/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl LocalStorageInner {
/// ## Ok
/// - First value is the path to the file
/// - Second is the directory that the file is in
#[instrument(level = "debug")]
pub fn get_path_for_creation(
&self,
repository: Uuid,
Expand All @@ -77,12 +78,16 @@ impl LocalStorageInner {
let mut iter = location.clone().into_iter().peekable();
while let Some(part) = iter.next() {
if iter.peek().is_none() {
debug!(?part, "Last Part of Path");
parent_directory = path.clone();
}
path = path.join(part.as_ref());
conflicting_path.push_mut(part.as_ref());
trace!(?path, ?conflicting_path, "Checking Path");
if path.exists() {
trace!(?path, "Path Exists");
if path.is_file() {
warn!(?path, "Path is a file");
return Err(PathCollisionError {
path: location.clone(),
conflicts_with: conflicting_path,
Expand Down Expand Up @@ -159,7 +164,7 @@ impl Storage for LocalStorage {
config: BorrowedStorageTypeConfig::Local(&self.config),
}
}
#[instrument(name = "local_storage_save")]
#[instrument(name = "Storage::save_file", fields(storage_type = "local"))]
async fn save_file(
&self,
repository: Uuid,
Expand All @@ -186,7 +191,7 @@ impl Storage for LocalStorage {
}
Ok((bytes_written, new_file))
}
#[instrument(name = "local_storage_delete")]
#[instrument(name = "Storage::delete_file", fields(storage_type = "local"))]
async fn delete_file(
&self,
repository: Uuid,
Expand All @@ -206,7 +211,7 @@ impl Storage for LocalStorage {
}
Ok(true)
}
#[instrument(name = "local_storage_get_info")]
#[instrument(name = "Storage::get_file_information", fields(storage_type = "local"))]
async fn get_file_information(
&self,
repository: Uuid,
Expand All @@ -221,7 +226,7 @@ impl Storage for LocalStorage {
let meta = StorageFileMeta::read_from_path(path)?;
Ok(Some(meta))
}
#[instrument(name = "local_storage_open_file")]
#[instrument(name = "Storage::open_file", fields(storage_type = "local"))]
async fn open_file(
&self,
repository: Uuid,
Expand All @@ -239,12 +244,16 @@ impl Storage for LocalStorage {
};
Ok(Some(file))
}
#[instrument(name = "Storage::unload", fields(storage_type = "local"))]
async fn unload(&self) -> Result<(), LocalStorageError> {
info!(?self, "Unloading Local Storage");
// TODO: Implement Unload
Ok(())
}

#[instrument(
name = "Storage::validate_config_change",
fields(storage_type = "local")
)]
async fn validate_config_change(
&self,
config: StorageTypeConfig,
Expand All @@ -255,6 +264,7 @@ impl Storage for LocalStorage {
}
Ok(())
}
#[instrument(name = "Storage::get_repository_meta", fields(storage_type = "local"))]
async fn get_repository_meta(
&self,
repository: Uuid,
Expand All @@ -267,6 +277,7 @@ impl Storage for LocalStorage {
let meta = FileMeta::get_or_create_local(&path)?;
Ok(Some(meta.repository_meta))
}
#[instrument(name = "Storage::put_repository_meta", fields(storage_type = "local"))]
async fn put_repository_meta(
&self,
repository: Uuid,
Expand All @@ -285,6 +296,7 @@ impl Storage for LocalStorage {
FileMeta::set_repository_meta(path, value)?;
Ok(())
}
#[instrument(name = "Storage::file_exists", fields(storage_type = "local"))]
async fn file_exists(
&self,
repository: Uuid,
Expand Down
12 changes: 4 additions & 8 deletions crates/storage/src/s3/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{borrow::Cow, io::SeekFrom, ops::Deref, path, str::FromStr, sync::Arc};
use std::{borrow::Cow, ops::Deref, str::FromStr, sync::Arc};

use chrono::Local;
use futures::future::BoxFuture;
use mime::Mime;
use nr_core::storage::{self, StoragePath};
use nr_core::storage::StoragePath;
use regions::{CustomRegion, S3StorageRegion};
use s3::{
creds::{Credentials, Rfc3339OffsetDateTime},
Expand Down Expand Up @@ -48,7 +48,7 @@ impl S3StorageError {
}
}
use crate::{
error, meta::RepositoryMeta, utils::new_type_arc_type, BorrowedStorageConfig,
meta::RepositoryMeta, utils::new_type_arc_type, BorrowedStorageConfig,
BorrowedStorageTypeConfig, DirectoryFileType, DynStorage, FileContent, FileContentBytes,
FileFileType, FileHashes, FileType, InvalidConfigType, PathCollisionError, SerdeMime,
StaticStorageFactory, Storage, StorageConfig, StorageConfigInner, StorageError, StorageFactory,
Expand Down Expand Up @@ -302,7 +302,7 @@ impl S3StorageInner {

Ok(Some(meta))
}

#[instrument]
async fn get_object_tagging(&self, path: &str) -> Result<Option<Vec<Tag>>, S3StorageError> {
let (tags, status_code) = self.bucket.get_object_tagging(path).await?;
if status_code == 404 {
Expand All @@ -317,11 +317,7 @@ impl S3StorageInner {

Ok(Some(tags))
}
async fn is_path_a_directory(&self, path: &str) -> Result<bool, S3StorageError> {
let tags = self.get_object_tagging(path).await?;

Ok(false)
}
async fn get_meta_tags(&self, path: &str) -> Result<Option<S3MetaTags>, S3StorageError> {
let Some(tags) = self.get_object_tagging(path).await? else {
return Ok(None);
Expand Down
3 changes: 2 additions & 1 deletion crates/storage/src/s3/regions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use s3::Region;
use serde::{Deserialize, Serialize};
use strum::EnumIter;
use utoipa::ToSchema;

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ToSchema)]
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ToSchema, EnumIter)]
pub enum S3StorageRegion {
/// us-east-1
UsEast1,
Expand Down
5 changes: 2 additions & 3 deletions crates/storage/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::{env::current_dir, path::PathBuf};

use nr_core::{repository::config, testing::logging::TestingLoggerConfig};
use nr_core::testing::logging::TestingLoggerConfig;
use serde::{Deserialize, Serialize};
use tracing::info;
use uuid::Uuid;
pub mod tests;
use crate::{
local::{LocalConfig, LocalStorage, LocalStorageFactory},
s3::{regions::CustomRegion, S3Config, S3Credentials, S3StorageFactory},
StaticStorageFactory, StorageConfig, StorageConfigInner, StorageError, StorageFactory,
StorageTypeConfig,
StaticStorageFactory, StorageConfig, StorageConfigInner, StorageTypeConfig,
};
pub mod storage;
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
Loading

0 comments on commit 2437872

Please sign in to comment.