Skip to content

Commit

Permalink
initial abscissa_tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
Shella committed Jul 11, 2024
1 parent 06d4310 commit a45a854
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 18 deletions.
42 changes: 42 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ categories = ["command-line-utilities"]
keywords = ["container", "devops", "docker", "deployment", "systemd"]

[dependencies]
abscissa_core = "0.7"
abscissa_tokio = "0.7.0"
bytes = "1"
clap = "4"
hex = "0.4"
Expand All @@ -29,6 +31,7 @@ sha2 = "0.10"
tar = "0.4"
tokio-stream = "0.1"
walkdir = "2"
futures-util = "0.3"

[package.metadata.rpm.cargo]
buildflags = ["--release"]
Expand All @@ -39,5 +42,3 @@ canister = { path = "/usr/bin/canister" }
[dev-dependencies]
once_cell = "1"

[dependencies.abscissa_core]
version = "0.7"
9 changes: 6 additions & 3 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use abscissa_core::{
config::{self, CfgCell},
trace, Application, FrameworkError, StandardPaths,
};
use abscissa_tokio::TokioComponent;

/// Application state
pub static APPLICATION: AppCell<CanisterApplication> = AppCell::new();
Expand Down Expand Up @@ -47,10 +48,12 @@ impl Application for CanisterApplication {
/// beyond the default ones provided by the framework, this is the place
/// to do so.
fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
let components = self.framework_components(command)?;
let mut components = self.framework_components(command)?;

let mut component_registry = self.state.components_mut();
component_registry.register(components)
// Create `TokioComponent` and add it to your app's components here:
components.push(Box::new(TokioComponent::new()?));

self.state.components_mut().register(components)
}

/// Post-configuration lifecycle callback.
Expand Down
31 changes: 21 additions & 10 deletions src/commands/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::gcp::{Manifest, Storage, Token};
use crate::application::APPLICATION;
use crate::prelude::*;
use crate::unpacker::{HexDigest};
use abscissa_core::{Command, Runnable};
Expand All @@ -8,6 +9,7 @@ use std::process;
use std::fs;
use std::io;
use std::os::unix;
use std::path::PathBuf;

#[derive(Command, Debug, Default, Parser)]
pub struct DeployCommand {
Expand All @@ -20,7 +22,8 @@ pub struct DeployCommand {

impl Runnable for DeployCommand {
#[allow(clippy::complexity)]
fn run(&self) {
fn run(&self) {

let config = APPLICATION.config();
let project = &config.project;
let bucket = &config.bucket;
Expand All @@ -34,7 +37,15 @@ impl Runnable for DeployCommand {
process::exit(1);
});

let (image_id, m) = Manifest::get(&token, project, image, tag, proxy).unwrap_or_else(|e| {
abscissa_tokio::run(&APPLICATION, async {
Self::perform(project, bucket, image, tag, object_path, path, proxy, &token);
});
}
}

impl DeployCommand {
async fn perform(project: &String, bucket: &String, image: &String, tag: &String, object_path: &String, path: &PathBuf, proxy: Option<&str>, token: &Token) {
let (image_id, m) = Manifest::get(&token, project, image, tag, proxy).await.unwrap_or_else(|e| {
status_err!("Error, unable to fetch manifest: {}", e);
process::exit(1);
});
Expand All @@ -55,17 +66,17 @@ impl Runnable for DeployCommand {
process::exit(1);
});
debug!("response: {:?}", response);
/* let mut unpacker = Unpacker::new(response, config.path.join(image_id.to_string()));
unpacker.unpack().unwrap_or_else(|e| {
status_err!("Error, unable to unpack archive: {}", e);
process::exit(1);
});
let digest = unpacker.hex_digest();*/
/* let mut unpacker = Unpacker::new(response, config.path.join(image_id.to_string()));
unpacker.unpack().unwrap_or_else(|e| {
status_err!("Error, unable to unpack archive: {}", e);
process::exit(1);
});
let digest = unpacker.hex_digest();*/
debug!("digest: ");
status_ok!("Downloaded", "{} object from {}", object, bucket);
// debug!("hasher result: {}", digest.as_str());
// debug!("hasher result: {}", digest.as_str());
debug!("layer digest: {}", layer_digest.as_str());
// assert_eq!(digest, layer_digest);
// assert_eq!(digest, layer_digest);
let full_path = path.join(image_id.to_string());
let full_tag = path.join("current");
if let Err(e) = unix::fs::symlink(&full_path, &full_tag) {
Expand Down
6 changes: 3 additions & 3 deletions src/gcp/gcr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl fmt::Display for ImageId {
}

impl Manifest {
pub fn get(
pub async fn get(
token: &oauth::Token,
project: &str,
image: &str,
Expand All @@ -62,7 +62,7 @@ impl Manifest {

let url = format!("https://gcr.io/v2/{}/{}/manifests/{}", project, image, tag);

let mut response = client.get(url.as_str()).send()?;
let response = client.get(url.as_str()).send().await?;

let docker_digest_header = response
.headers()
Expand All @@ -80,7 +80,7 @@ impl Manifest {
debug!("{:?}", docker_digest);
debug!("response = {:?}", response);

let body = response.text()?;
let body = response.text().await?;
debug!("body = {:?}", body);
let image_id = ImageId(hex::encode(Sha256::digest(body.as_bytes())));
assert_eq!(image_id.0, *docker_digest);
Expand Down

0 comments on commit a45a854

Please sign in to comment.