From c9e576baf05cd1a7e72f263a946924119008d2f5 Mon Sep 17 00:00:00 2001 From: jiaxiao zhou Date: Sun, 7 Apr 2024 23:13:21 +0000 Subject: [PATCH 1/3] feat(*): add rustfmt.toml to fmt imports this commit adds a rustfmt.toml to configure rustfmt tool it requires nightly rust so the command to fmt is `cargo +nightly fmt --all` Signed-off-by: jiaxiao zhou --- containerd-shim-spin/src/engine.rs | 31 +++++++++++++++--------------- containerd-shim-spin/src/main.rs | 6 ++++-- rustfmt.toml | 6 ++++++ tests/src/integration_test.rs | 2 +- 4 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 rustfmt.toml diff --git a/containerd-shim-spin/src/engine.rs b/containerd-shim-spin/src/engine.rs index b35a040..199b30d 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 117d18a..cd1ec86 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 0000000..90cc2cb --- /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/tests/src/integration_test.rs b/tests/src/integration_test.rs index b370366..9b1c537 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; From 96fac602dc6ace06ce748c1102182db1904dafd3 Mon Sep 17 00:00:00 2001 From: jiaxiao zhou Date: Sun, 7 Apr 2024 23:23:05 +0000 Subject: [PATCH 2/3] feat(ci): add nightly target to ci since now rustfmt requires nightly built of rust Signed-off-by: jiaxiao zhou --- .github/workflows/ci.yaml | 14 +++++++------- Makefile | 8 ++------ scripts/setup-linux.sh | 4 ++++ 3 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 scripts/setup-linux.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0bbabb6..f82c033 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 @@ -42,11 +43,10 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 - - uses: azure/setup-kubectl@v4 - - name: "Install dependencies" + - uses: azure/setup-kubesctl@v4 + - 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 2c746d8..aebc7da 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/scripts/setup-linux.sh b/scripts/setup-linux.sh new file mode 100644 index 0000000..0204593 --- /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 + From 1203e8ff3400ebfff9dd3b520595b0cea563d814 Mon Sep 17 00:00:00 2001 From: jiaxiao zhou Date: Sun, 7 Apr 2024 23:32:43 +0000 Subject: [PATCH 3/3] add exec permission to setup-linux.sh Signed-off-by: jiaxiao zhou --- .github/workflows/ci.yaml | 2 +- scripts/setup-linux.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 scripts/setup-linux.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f82c033..638d392 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -43,7 +43,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 - - uses: azure/setup-kubesctl@v4 + - uses: azure/setup-kubectl@v4 - name: Setup build env run: | ./scripts/setup-linux.sh diff --git a/scripts/setup-linux.sh b/scripts/setup-linux.sh old mode 100644 new mode 100755