diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0bbabb60..638d392f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,10 +13,11 @@ jobs: with: workspaces: | "containerd-shim-* -> target" - - name: "Install dependencies" + - run: + rustup toolchain install nightly --component rustfmt + - name: Setup build env run: | - sudo apt-get update - sudo apt-get install -y protobuf-compiler libseccomp-dev + ./scripts/setup-linux.sh - name: fmt run: | make fmt @@ -43,10 +44,9 @@ jobs: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 - uses: azure/setup-kubectl@v4 - - name: "Install dependencies" + - name: Setup build env run: | - sudo apt-get update - sudo apt-get install -y protobuf-compiler libseccomp-dev + ./scripts/setup-linux.sh - name: Extract containerd-shim-spin-linux-${{ env.ARCH }} run: | mkdir -p ./bin diff --git a/Makefile b/Makefile index 2c746d8c..aebc7da8 100644 --- a/Makefile +++ b/Makefile @@ -61,16 +61,12 @@ tests/clean: .PHONY: fmt fmt: - $(foreach shim,$(SHIMS),cargo fmt --all --manifest-path=containerd-shim-$(shim)/Cargo.toml -- --check;) - $(foreach shim,$(SHIMS),cargo clippy --all-targets --all-features --workspace --manifest-path=containerd-shim-$(shim)/Cargo.toml -- -D warnings;) - cargo fmt --all -- --check + cargo +nightly fmt --all -- --check cargo clippy --all-targets --all-features --workspace -- --deny=warnings .PHONY: fix fix: - $(foreach shim,$(SHIMS),cargo fmt --all --manifest-path=containerd-shim-$(shim)/Cargo.toml;) - $(foreach shim,$(SHIMS),cargo clippy --all-targets --all-features --workspace --manifest-path=containerd-shim-$(shim)/Cargo.toml --fix -- -D warnings;) - cargo fmt --all + cargo +nightly fmt --all cargo clippy --all-targets --all-features --workspace --fix -- --deny=warnings .PHONY: build diff --git a/containerd-shim-spin/src/engine.rs b/containerd-shim-spin/src/engine.rs index b35a040d..199b30db 100644 --- a/containerd-shim-spin/src/engine.rs +++ b/containerd-shim-spin/src/engine.rs @@ -1,25 +1,26 @@ +use std::{ + collections::{hash_map::DefaultHasher, HashSet}, + env, + fs::File, + hash::{Hash, Hasher}, + io::Write, + net::{SocketAddr, ToSocketAddrs}, + path::{Path, PathBuf}, +}; + 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, 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_trigger::{loader, 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 tokio::runtime::Runtime; use trigger_command::CommandTrigger; use trigger_sqs::SqsTrigger; diff --git a/containerd-shim-spin/src/main.rs b/containerd-shim-spin/src/main.rs index 117d18a6..cd1ec867 100644 --- a/containerd-shim-spin/src/main.rs +++ b/containerd-shim-spin/src/main.rs @@ -1,6 +1,8 @@ use containerd_shim::Config; -use containerd_shim_wasm::container::Instance; -use containerd_shim_wasm::sandbox::cli::{revision, shim_main, version}; +use containerd_shim_wasm::{ + container::Instance, + sandbox::cli::{revision, shim_main, version}, +}; mod engine; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..90cc2cb0 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,6 @@ +newline_style = "Native" +unstable_features = true # Cargo fmt now needs to be called with `cargo +nightly fmt` +group_imports = "StdExternalCrate" # create three groups for std, external and local crates +# Merge imports from the same module +# See: https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#imports_granularity +imports_granularity = "Crate" \ No newline at end of file diff --git a/scripts/setup-linux.sh b/scripts/setup-linux.sh new file mode 100755 index 00000000..0204593f --- /dev/null +++ b/scripts/setup-linux.sh @@ -0,0 +1,4 @@ +#!/bin/bash +sudo apt -y update +sudo apt-get install -y protobuf-compiler libseccomp-dev + diff --git a/tests/src/integration_test.rs b/tests/src/integration_test.rs index b3703666..9b1c5375 100644 --- a/tests/src/integration_test.rs +++ b/tests/src/integration_test.rs @@ -1,10 +1,10 @@ #[cfg(test)] mod test { + use anyhow::Result; use redis::AsyncCommands; use tokio::process::Command; use crate::retry_get; - use anyhow::Result; const RETRY_TIMES: u32 = 5; const INTERVAL_IN_SECS: u64 = 10;