Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft]: small refactoring of the Spin engine #63

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions containerd-shim-spin/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
use anyhow::{anyhow, ensure, Context, Result};
use containerd_shim_wasm::container::{Engine, RuntimeContext, Stdio};
use containerd_shim_wasm::sandbox::WasmLayer;
use containerd_shim_wasm::{
container::{Engine, RuntimeContext, Source, Stdio},
sandbox::WasmLayer,
};
use log::info;
use oci_spec::image::MediaType;
use spin_app::locked::LockedApp;
use spin_loader::cache::Cache;
use spin_loader::FilesMountStrategy;
use spin_loader::{cache::Cache, FilesMountStrategy};
use spin_manifest::schema::v2::AppManifest;
use spin_trigger::TriggerHooks;
use spin_trigger::{loader, RuntimeConfig, TriggerExecutor, TriggerExecutorBuilder};
use spin_oci::OciLoader;
use spin_trigger::{
loader::TriggerLoader, RuntimeConfig, TriggerExecutor, TriggerExecutorBuilder, TriggerHooks,
};
use spin_trigger_http::HttpTrigger;
use spin_trigger_redis::RedisTrigger;
use std::collections::hash_map::DefaultHasher;
use std::collections::HashSet;
use std::env;
use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io::Write;
use std::net::SocketAddr;
use std::net::ToSocketAddrs;
use std::path::{Path, PathBuf};
use std::{
radu-matei marked this conversation as resolved.
Show resolved Hide resolved
collections::{hash_map::DefaultHasher, HashSet},
env,
fs::File,
hash::{Hash, Hasher},
io::Write,
net::{SocketAddr, ToSocketAddrs},
path::{Path, PathBuf},
};
use tokio::runtime::Runtime;
use trigger_command::CommandTrigger;
use trigger_sqs::SqsTrigger;
Expand Down Expand Up @@ -97,10 +100,8 @@ impl std::fmt::Debug for AppSource {
impl SpinEngine {
async fn app_source(&self, ctx: &impl RuntimeContext, cache: &Cache) -> Result<AppSource> {
match ctx.entrypoint().source {
containerd_shim_wasm::container::Source::File(_) => {
Ok(AppSource::File(SPIN_MANIFEST_FILE_PATH.into()))
}
containerd_shim_wasm::container::Source::Oci(layers) => {
Source::File(_) => Ok(AppSource::File(SPIN_MANIFEST_FILE_PATH.into())),
Source::Oci(layers) => {
info!(" >>> configuring spin oci application {}", layers.len());

for layer in layers {
Expand Down Expand Up @@ -162,7 +163,7 @@ impl SpinEngine {
},
AppSource::Oci => {
let working_dir = PathBuf::from("/");
let loader = spin_oci::OciLoader::new(working_dir);
let loader = OciLoader::new(working_dir);

// TODO: what is the best way to get this info? It isn't used only saved in the locked file
let reference = "docker.io/library/wasmtest_spin:latest";
Expand Down Expand Up @@ -295,7 +296,7 @@ impl SpinEngine {
let locked_url = self.write_locked_app(&app, &working_dir).await?;

// Build trigger config
let mut loader = loader::TriggerLoader::new(working_dir.clone(), true);
let mut loader = TriggerLoader::new(working_dir.clone(), true);
match app_source {
AppSource::Oci => unsafe {
// Configure the loader to support loading AOT compiled components..
Expand Down
Loading