Skip to content

Commit

Permalink
merge 'trow_server' and 'registry_interface' into 'registry'
Browse files Browse the repository at this point in the history
  • Loading branch information
awoimbee committed May 13, 2024
1 parent c810bc2 commit 21d7b1e
Show file tree
Hide file tree
Showing 42 changed files with 98 additions and 261 deletions.
2 changes: 1 addition & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Trow Architecture

Trow started with a front-end and a backend communicating via gRPC,
gRPC was removed to simplify the structure, but you will still find that the trow_server
gRPC was removed to simplify the structure, but you will still find that the registry
module is very distinct from the rest of the trow crate.


Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ pub mod response;
mod routes;
pub mod types;

pub mod registry_interface;
pub mod trow_server;
pub mod registry;
#[cfg(feature = "sqlite")]
mod users;

Expand All @@ -17,7 +16,7 @@ use anyhow::{Context, Result};
use axum::extract::FromRef;
use axum::Router;
use thiserror::Error;
use trow_server::{ImageValidationConfig, RegistryProxiesConfig, TrowServer};
use registry::{ImageValidationConfig, RegistryProxiesConfig, TrowServer};
use uuid::Uuid;

//TODO: Make this take a cause or description
Expand Down Expand Up @@ -164,16 +163,16 @@ impl TrowConfig {
std::process::exit(0);
}

let ts_builder = trow_server::build_server(
let ts_builder = registry::build_server(
self.data_dir.clone(),
self.proxy_registry_config.clone(),
self.image_validation_config.clone(),
);
let trow_server = ts_builder.get_server()?;
let registry = ts_builder.get_server()?;

let server_state = TrowServerState {
config: self.clone(),
client: trow_server,
client: registry,
};
Ok(routes::create_app(server_state))
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn digest<D: ShaDigest + Default, R: Read>(reader: &mut R) -> io::Result<String>
mod test {
use std::io::BufReader;

use crate::registry_interface::digest::{Digest, DigestAlgorithm};
use crate::registry::digest::{Digest, DigestAlgorithm};

#[test]
fn sha256_digest_test() {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/trow_server/manifest.rs → src/registry/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use serde_json::{self, Value};
use thiserror::Error;

use crate::registry_interface::digest::{Digest, DigestError};
use crate::registry::digest::{Digest, DigestError};

pub trait FromJson {
fn from_json(raw: &Value) -> Result<Self>
Expand Down Expand Up @@ -220,7 +220,7 @@ mod test {
use serde_json::{self, Value};

use super::{FromJson, Manifest, OCIManifest};
use crate::registry_interface::Digest;
use crate::registry::Digest;

#[test]
fn valid_v2_2() {
Expand Down
File renamed without changes.
File renamed without changes.
50 changes: 46 additions & 4 deletions src/registry_interface/mod.rs → src/registry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
pub use admission::AdmissionValidation;
mod admission;
pub mod api_types;
mod image;
pub mod manifest;
mod metrics;
mod proxy_auth;
mod server;
pub mod storage;
mod temporary_file;

use std::path::PathBuf;

pub use admission::ImageValidationConfig;
use anyhow::Result;
pub use proxy_auth::{RegistryProxiesConfig, SingleRegistryProxyConfig};
pub use server::TrowServer;


pub use blob_storage::{BlobReader, BlobStorage, ContentInfo, UploadInfo};
pub use catalog_operations::{CatalogOperations, ManifestHistory};
pub use digest::{Digest, DigestAlgorithm};
pub use manifest_storage::{ManifestReader, ManifestStorage};
pub use metrics::{Metrics, MetricsError};
use thiserror::Error;
use tokio::io::{AsyncRead, AsyncSeek};

pub mod admission;
pub mod blob_storage;
pub mod catalog_operations;
#[allow(dead_code)]
pub mod digest;
pub mod manifest_storage;
pub mod metrics;

// Storage Driver Error
#[derive(Error, Debug)]
Expand Down Expand Up @@ -48,3 +62,31 @@ pub trait RegistryStorage: ManifestStorage + BlobStorage + CatalogOperations {
/// individually. This significantly decrease the memory usage of the registry
fn support_streaming(&self) -> bool;
}

pub struct TrowServerBuilder {
data_path: PathBuf,
proxy_registry_config: Option<RegistryProxiesConfig>,
image_validation_config: Option<ImageValidationConfig>,
}

pub fn build_server(
data_path: PathBuf,
proxy_registry_config: Option<RegistryProxiesConfig>,
image_validation_config: Option<ImageValidationConfig>,
) -> TrowServerBuilder {
TrowServerBuilder {
data_path,
proxy_registry_config,
image_validation_config,
}
}

impl TrowServerBuilder {
pub fn get_server(self) -> Result<TrowServer> {
TrowServer::new(
self.data_path,
self.proxy_registry_config,
self.image_validation_config,
)
}
}
File renamed without changes.
141 changes: 8 additions & 133 deletions src/trow_server/server.rs → src/registry/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ use reqwest::header::{HeaderMap, HeaderValue};
use reqwest::{self, Method};
use thiserror::Error;
use tracing::{event, Level};
use trow_server::api_types::MetricsResponse;
use registry::api_types::MetricsResponse;

use super::image::RemoteImage;
use super::manifest::{manifest_media_type, Manifest, OCIManifest};
use super::proxy_auth::{ProxyClient, SingleRegistryProxyConfig};
use super::storage::{is_path_writable, StorageBackendError, TrowStorageBackend};
use super::{metrics, ImageValidationConfig, RegistryProxiesConfig};
use crate::registry_interface::blob_storage::Stored;
use crate::registry_interface::catalog_operations::HistoryEntry;
use crate::registry_interface::digest::Digest;
use crate::registry_interface::{BlobReader, ContentInfo, ManifestReader, StorageDriverError};
use crate::trow_server;
use crate::trow_server::api_types::Status;
use crate::trow_server::storage::WriteBlobRangeError;
use crate::registry::blob_storage::Stored;
use crate::registry::catalog_operations::HistoryEntry;
use crate::registry::digest::Digest;
use crate::registry::{BlobReader, ContentInfo, ManifestReader, StorageDriverError};
use crate::registry;
use crate::registry::api_types::Status;
use crate::registry::storage::WriteBlobRangeError;
use crate::types::*;

pub static SUPPORTED_DIGESTS: [&str; 1] = ["sha256"];
Expand Down Expand Up @@ -274,35 +274,6 @@ impl TrowServer {
Ok(())
}

// pub async fn delete_blob(&self, name: &str, digest: &Digest) -> Result<(), StorageDriverError> {
// event!(
// Level::INFO,
// "Attempting to delete blob {} in {}",
// digest,
// name
// );
// let rn = (name.to_string());

// self.delete_blob_local(&rn, digest)
// .await
// .map_err(|_| StorageDriverError::InvalidDigest)?;
// Ok(())
// }

// async fn get_catalog(
// &self,
// start_value: Option<&str>,
// num_results: Option<u32>,
// ) -> Result<Vec<String>, StorageDriverError> {
// let num_results = num_results.unwrap_or(u32::MAX);
// let start_value = start_value.unwrap_or_default();

// self.get_catalog_part(num_results, start_value)
// .await
// .map_err(|_| StorageDriverError::Internal)
// .map(|rc| rc.raw())
// }

pub async fn get_tags(
&self,
repo: &str,
Expand Down Expand Up @@ -331,104 +302,8 @@ impl TrowServer {
.await
.map_err(|_| StorageDriverError::Internal)
}

// async fn validate_admission(
// &self,
// admission_req: &AdmissionRequest<Pod>,
// host_name: &str,
// ) -> AdmissionResponse {
// self.validate_admission_internal(admission_req, host_name)
// .await
// .unwrap_or_else(|e| {
// AdmissionResponse::from(admission_req).deny(format!("Internal error: {}", e))
// })
// }

// async fn mutate_admission(
// &self,
// admission_req: &AdmissionRequest<Pod>,
// host_name: &str,
// ) -> AdmissionResponse {
// self.mutate_admission_internal(admission_req, host_name)
// .await
// .unwrap_or_else(|e| {
// AdmissionResponse::from(admission_req).deny(format!("Internal error: {}", e))
// })
// }

// async fn is_healthy(&self) -> bool {
// self.is_healthy().await.is_healthy
// }

// async fn is_ready(&self) -> bool {
// self.is_ready().await.is_ready
// }

// async fn get_metrics(
// &self,
// ) -> Result<MetricsResponse, crate::registry_interface::MetricsError> {
// self.get_metrics().await.map_err(|_| MetricsError::Internal)
// }

// async fn complete_upload(
// &self,
// repo_name: &str,
// uuid: &str,
// digest: &Digest,
// ) -> Result<(), Status> {
// event!(
// Level::INFO,
// "Complete Upload called for repository {} with upload id {} digest {}",
// repo_name,
// uuid,
// digest
// );

// let req = CompleteRequest {
// repo_name: repo_name.to_string(),
// uuid: uuid.to_string(),
// user_digest: digest.to_string(),
// };

// self.trow_server.complete_upload(req).await?;

// Ok(())
// }

// async fn get_manifest_history(
// &self,
// repo_name: &str,
// reference: &str,
// limit: u32,
// last_digest: &str,
// ) -> Result<ManifestHistory> {
// event!(
// Level::INFO,
// "Getting manifest history for repo {} ref {} limit {} last_digest {}",
// repo_name,
// reference,
// limit,
// last_digest
// );
// let mr = ManifestHistoryRequest {
// tag: reference.to_owned(),
// repo_name: repo_name.to_string(),
// limit,
// last_digest: last_digest.to_owned(),
// };
// let stream = self.trow_server.get_manifest_history(mr).await?;
// let mut history = ManifestHistory::new(format!("{}:{}", repo_name, reference));

// for entry in stream {
// history.insert(entry.digest, entry.date);
// }

// Ok(history)
// }
}

////////////////////////////////////////////////////////////////////////////////////////////////////

impl TrowServer {
pub fn new(
data_path: PathBuf,
Expand Down
10 changes: 5 additions & 5 deletions src/trow_server/storage.rs → src/registry/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use walkdir::WalkDir;

use super::manifest::{Manifest, ManifestError};
use super::server::{PROXY_DIR, SUPPORTED_DIGESTS};
use crate::registry_interface::blob_storage::Stored;
use crate::registry_interface::catalog_operations::HistoryEntry;
use crate::registry_interface::Digest;
use crate::trow_server::temporary_file::TemporaryFile;
use crate::registry::blob_storage::Stored;
use crate::registry::catalog_operations::HistoryEntry;
use crate::registry::Digest;
use crate::registry::temporary_file::TemporaryFile;
use crate::types::BoundedStream;

// Storage Driver Error
Expand Down Expand Up @@ -530,7 +530,7 @@ mod tests {
use std::io::Write;

use super::*;
use crate::trow_server::manifest;
use crate::registry::manifest;

#[test]
fn trow_storage_backend_new() {
Expand Down
File renamed without changes.
19 changes: 0 additions & 19 deletions src/registry_interface/admission.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/registry_interface/metrics.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/response/accepted_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod test {
use axum::http::StatusCode;
use axum::response::IntoResponse;

use crate::registry_interface::{Digest, DigestAlgorithm};
use crate::registry::{Digest, DigestAlgorithm};
use crate::types::{AcceptedUpload, Uuid};

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/response/blob_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use futures::AsyncRead;
use tokio_util::codec::{BytesCodec, FramedRead};
use tokio_util::compat::FuturesAsyncReadCompatExt;

use crate::registry_interface::BlobReader;
use crate::registry::BlobReader;

impl<S: AsyncRead + Send + 'static> IntoResponse for BlobReader<S> {
fn into_response(self) -> Response {
Expand Down
Loading

0 comments on commit 21d7b1e

Please sign in to comment.