From 9d50a3f02d7dda1dfdf9849a9972602ce26ae1af Mon Sep 17 00:00:00 2001 From: MBRound18 <12646562+mbround18@users.noreply.github.com> Date: Fri, 13 Oct 2023 13:32:38 -0700 Subject: [PATCH 1/2] Fix | Argument Settings arent taking --- .github/workflows/docker-release.yml | 10 ++++ Cargo.lock | 52 ++++++++----------- Dockerfile.odin | 11 ++++- Makefile | 15 ++++++ src/odin/logger.rs | 2 +- src/odin/server/startup.rs | 74 +++++++++++++++++----------- 6 files changed, 101 insertions(+), 63 deletions(-) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 72656502..8e0f1cd3 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -56,6 +56,15 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GHCR_TOKEN }} + - name: "JQ: Install" + run: | + sudo apt-get install -y jq + + - name: "Cargo Make: Get Latest Version" + id: cargo-make + run: | + echo "version=$(curl -s https://api.github.com/repos/sagiegurari/cargo-make/releases/latest | jq -r '.tag_name')" >> $GITHUB_OUTPUT + - name: Build and push uses: docker/build-push-action@v5 with: @@ -70,3 +79,4 @@ jobs: "GITHUB_SHA=${GITHUB_SHA}" "GITHUB_REF=${GITHUB_REF}" "GITHUB_REPOSITORY=${GITHUB_REPOSITORY}" + "CARGO_MAKE_VERSION=${{ steps.cargo-make.outputs.version }}" diff --git a/Cargo.lock b/Cargo.lock index b5782d03..95c6aeb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -475,25 +475,14 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "errno-dragonfly", "libc", "windows-sys", ] -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "filetime" version = "0.2.22" @@ -508,9 +497,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -937,9 +926,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -967,9 +956,9 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "linux-raw-sys" -version = "0.4.8" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "lock_api" @@ -1269,9 +1258,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b1106fec09662ec6dd98ccac0f81cef56984d0b49f75c92d8cbad76e20c005c" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -1387,9 +1376,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.17" +version = "0.38.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25469e9ae0f3d0047ca8b93fc56843f38e6774f0914a107ff8b41be8be8e0b7" +checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" dependencies = [ "bitflags 2.4.0", "errno", @@ -1459,18 +1448,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", @@ -1766,9 +1755,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ "backtrace", "bytes", @@ -2267,11 +2256,10 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.8+zstd.1.5.5" +version = "2.0.9+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" dependencies = [ "cc", - "libc", "pkg-config", ] diff --git a/Dockerfile.odin b/Dockerfile.odin index d49a64c5..18d855af 100644 --- a/Dockerfile.odin +++ b/Dockerfile.odin @@ -21,7 +21,16 @@ RUN cargo chef cook --release --recipe-path recipe.json # -- Odin Project Mangement -- # # ---------------------------- # -FROM mbround18/cargo-make:latest as cargo-make +FROM rust:${RUST_VERSION} as cargo-make + +ARG CARGO_MAKE_VERSION=0.37.2 + +ADD https://github.com/sagiegurari/cargo-make/releases/download/${CARGO_MAKE_VERSION}/cargo-make-v${CARGO_MAKE_VERSION}-x86_64-unknown-linux-gnu.zip /tmp/cargo-make.zip +RUN unzip /tmp/cargo-make.zip -d /tmp \ + && mv /tmp/cargo-make-v${CARGO_MAKE_VERSION}-x86_64-unknown-linux-gnu/cargo-make /usr/local/bin/cargo-make \ + && rm -rf /tmp/cargo-make* \ + && chmod +x /usr/local/bin/cargo-make + # ------------------ # # -- Odin Builder -- # diff --git a/Makefile b/Makefile index 56445ff1..59e61a53 100644 --- a/Makefile +++ b/Makefile @@ -34,3 +34,18 @@ wsl.clean-all: wsl.clippy: wsl.sync cd $(BUILD_DIR) && cargo clippy + +docker.build: + docker compose -f docker-compose.dev.yml build + +docker.up: + docker compose -f docker-compose.dev.yml up + +docker.build-up: + docker compose -f docker-compose.dev.yml up --build + +docker.down: + docker compose -f docker-compose.dev.yml disown + +docker.ssh: + docker compose -f docker-compose.dev.yml exec valheim gosu valheim bash \ No newline at end of file diff --git a/src/odin/logger.rs b/src/odin/logger.rs index eaa905dc..48bbcaea 100644 --- a/src/odin/logger.rs +++ b/src/odin/logger.rs @@ -51,6 +51,6 @@ pub fn initialize_logger(debug: bool) -> Result<(), SetLoggerError> { } pub fn debug_mode() -> bool { - let debug_mode = env::var("DEBUG_MODE").unwrap_or(String::new()); + let debug_mode = env::var("DEBUG_MODE").unwrap_or_default(); parse_truthy(&debug_mode).unwrap_or(false) } diff --git a/src/odin/server/startup.rs b/src/odin/server/startup.rs index 1dc27ad6..cec33b46 100644 --- a/src/odin/server/startup.rs +++ b/src/odin/server/startup.rs @@ -55,61 +55,76 @@ pub fn start(config: ValheimArguments) -> CommandResult { constants::LD_LIBRARY_PATH_VAR, format!("{}/linux64", game_directory()).as_str(), ); - info!("Setting up base command"); - info!("Launching With Args: \n{:#?}", &config); + debug!("Setting up base command"); + debug!("Launching With Args: \n{:#?}", &config); // Sets the base command for the server - let mut base_command = command + let base_command = command .env("SteamAppId", fetch_var("APPID", "892970")) .current_dir(game_directory()); // Sets the name of the server, (Can be set with ENV variable NAME) - let name = format!("-name {}", fetch_var("NAME", config.name.as_str())); - base_command.arg(name); + let name = fetch_var("NAME", &config.name); + debug!("Setting name to: {}", &name); + base_command.arg("-name"); + base_command.arg(&name); // Sets the port of the server, (Can be set with ENV variable PORT) - let port = format!("-port {}", fetch_var("PORT", config.port.as_str())); - base_command.arg(port); + let port = fetch_var("PORT", &config.port); + debug!("Setting port to: {}", &port); + base_command.args(["-port", &port]); // Sets the world of the server, (Can be set with ENV variable WORLD) - let world = format!("-world {}", fetch_var("WORLD", config.world.as_str())); - base_command.arg(world); + let world = fetch_var("WORLD", &config.world); + debug!("Setting world to: {}", &fetch_var("WORLD", &world)); + base_command.arg("-world"); + base_command.arg(&world); // Determines if the server is public or not - let public = format!("-public {}", fetch_var("PUBLIC", config.public.as_str())); - base_command.arg(public); + let public = fetch_var("PUBLIC", config.public.as_str()); + debug!("Setting public to: {}", &public); + base_command.args(["-public", &public]); // Sets the save interval in seconds if let Some(save_interval) = &config.save_interval { - base_command.arg(format!("-saveinterval {}", save_interval)); + let interval = save_interval.to_string(); + debug!("Setting save interval to: {}", &interval); + base_command.args(["-saveinterval", &interval]); }; // Add set_key to the command if let Some(set_key) = &config.set_key { - base_command.arg(format!("-setkey {}", set_key)); + debug!("Setting set_key to: {}", &set_key); + base_command.args(["-setkey", &set_key]); }; // Add preset to the command if let Some(preset) = &config.preset { - base_command.arg(format!("-preset {}", preset)); + debug!("Setting preset to: {}", &preset); + base_command.args(["-preset", &preset]); }; // Add modifiers to the command if let Some(modifiers) = &config.modifiers { - base_command.args( - modifiers - .iter() - .map(|modifier| format!("-modifier {} {}", modifier.name, modifier.value)), - ); + modifiers.iter().for_each(|modifier| { + debug!( + "Setting modifier to: {} {}", + &modifier.name, &modifier.value + ); + base_command.args(["-modifier", &modifier.name, &modifier.value]); + }); }; // Extra args for the server - let extra_args = format!( - "-nographics -batchmode {}", - fetch_var("SERVER_EXTRA_LAUNCH_ARGS", "") - ) - .trim() - .to_string(); - base_command.arg(extra_args); + base_command.args({ + format!( + "-nographics -batchmode {}", + fetch_var("SERVER_EXTRA_LAUNCH_ARGS", "") + ) + .trim() + .to_string() + .split(' ') + .collect::>() + }); let is_public = config.public.eq("1"); let is_vanilla = fetch_var("TYPE", "vanilla").eq_ignore_ascii_case("vanilla"); @@ -123,18 +138,19 @@ pub fn start(config: ValheimArguments) -> CommandResult { exit(1) } else { info!("Password found, adding password flag."); - base_command = base_command.arg(format!("-password {}", config.password)); + base_command.arg("-password"); + base_command.arg(&config.password); } if fetch_var("ENABLE_CROSSPLAY", "0").eq("1") { info!("Launching with Crossplay! <3"); - base_command = base_command.arg("-crossplay") + base_command.arg("-crossplay"); } else { info!("No Crossplay Enabled!") } // Tack on save dir at the end. - base_command = base_command.arg(format!("-savedir {}", &saves_directory())); + base_command.args(["-savedir", &saves_directory()]); debug!("Base Command: {:#?}", base_command); From 35dff8abd0e84c7d1ab4a26a497dbf182a848297 Mon Sep 17 00:00:00 2001 From: MBRound18 <12646562+mbround18@users.noreply.github.com> Date: Fri, 13 Oct 2023 13:34:36 -0700 Subject: [PATCH 2/2] Linted --- .all-contributorsrc | 61 +++++++--------------------- .github/workflows/docker-release.yml | 2 +- README.md | 2 + 3 files changed, 17 insertions(+), 48 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 31444a5b..f62040ff 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3,9 +3,7 @@ "projectOwner": "mbround18", "repoType": "github", "repoHost": "https://github.com", - "files": [ - "README.md" - ], + "files": ["README.md"], "imageSize": 100, "commit": true, "commitConvention": "eslint", @@ -15,122 +13,91 @@ "name": "Mark", "avatar_url": "https://avatars.githubusercontent.com/u/3298808?v=4", "profile": "http://arneman.me/", - "contributions": [ - "doc" - ] + "contributions": ["doc"] }, { "login": "mbround18", "name": "Michael", "avatar_url": "https://avatars.githubusercontent.com/u/12646562?v=4", "profile": "https://m.bruno.fyi/", - "contributions": [ - "infra", - "code", - "doc" - ] + "contributions": ["infra", "code", "doc"] }, { "login": "imgbot[bot]", "name": "imgbot[bot]", "avatar_url": "https://avatars.githubusercontent.com/in/4706?v=4", "profile": "https://github.com/apps/imgbot", - "contributions": [ - "doc" - ] + "contributions": ["doc"] }, { "login": "AGhost-7", "name": "Jonathan Boudreau", "avatar_url": "https://avatars.githubusercontent.com/u/6957411?v=4", "profile": "https://github.com/AGhost-7", - "contributions": [ - "code" - ] + "contributions": ["code"] }, { "login": "Kellei2983", "name": "Lukáš Hruška", "avatar_url": "https://avatars.githubusercontent.com/u/32897629?v=4", "profile": "https://github.com/Kellei2983", - "contributions": [ - "doc" - ] + "contributions": ["doc"] }, { "login": "JulianVallee", "name": "Julian Vallée", "avatar_url": "https://avatars.githubusercontent.com/u/6720458?v=4", "profile": "http://vallee-design.de/", - "contributions": [ - "code" - ] + "contributions": ["code"] }, { "login": "Finomnis", "name": "Finomnis", "avatar_url": "https://avatars.githubusercontent.com/u/3129043?v=4", "profile": "https://github.com/Finomnis", - "contributions": [ - "code" - ] + "contributions": ["code"] }, { "login": "JustinByrne", "name": "Justin Byrne", "avatar_url": "https://avatars.githubusercontent.com/u/14056930?v=4", "profile": "https://tech.jrlbyrne.com/", - "contributions": [ - "doc" - ] + "contributions": ["doc"] }, { "login": "apeabody", "name": "Andrew Peabody", "avatar_url": "https://avatars.githubusercontent.com/u/14035345?v=4", "profile": "http://blog.andrewpeabody.com/", - "contributions": [ - "doc", - "code" - ] + "contributions": ["doc", "code"] }, { "login": "morales2k", "name": "Jorge Morales", "avatar_url": "https://avatars.githubusercontent.com/u/1074855?v=4", "profile": "https://github.com/morales2k", - "contributions": [ - "code" - ] + "contributions": ["code"] }, { "login": "spannerman79", "name": "Spanner_Man", "avatar_url": "https://avatars.githubusercontent.com/u/7542384?v=4", "profile": "https://github.com/spannerman79", - "contributions": [ - "doc" - ] + "contributions": ["doc"] }, { "login": "cameronwp", "name": "Cameron Pittman", "avatar_url": "https://avatars.githubusercontent.com/u/5186335?v=4", "profile": "https://hurtlingthrough.space/", - "contributions": [ - "doc" - ] + "contributions": ["doc"] }, { "login": "kodiakhq[bot]", "name": "kodiakhq[bot]", "avatar_url": "https://avatars.githubusercontent.com/in/29196?v=4", "profile": "https://github.com/apps/kodiakhq", - "contributions": [ - "infra", - "doc", - "code" - ] + "contributions": ["infra", "doc", "code"] } ], "contributorsPerLine": 7 diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 8e0f1cd3..32a1e63c 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -63,7 +63,7 @@ jobs: - name: "Cargo Make: Get Latest Version" id: cargo-make run: | - echo "version=$(curl -s https://api.github.com/repos/sagiegurari/cargo-make/releases/latest | jq -r '.tag_name')" >> $GITHUB_OUTPUT + echo "version=$(curl -s https://api.github.com/repos/sagiegurari/cargo-make/releases/latest | jq -r '.tag_name')" >> $GITHUB_OUTPUT - name: Build and push uses: docker/build-push-action@v5 diff --git a/README.md b/README.md index 46c1d7e0..0f22494e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ + [![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors-) + ## Table of Contents