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

Added BepInEx Support #148

Merged
merged 12 commits into from
Feb 23, 2021
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root = true
[*]
# charset = utf-8
end_of_line = lf
indent_size = 4
indent_size = 2
indent_style = space
insert_final_newline = true
# max_line_length = 120
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Lint
run: cargo fmt -- --check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
target/
tmp/
*.env*
docker-compose.*.yml
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tab_spaces = 2
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "odin"
version = "1.1.0"
version = "1.2.0"
authors = ["mbround18 <[email protected]>"]
edition = "2018"

Expand All @@ -17,7 +17,6 @@ daemonize = "0.4"
tar = "0.4"
flate2 = "1.0"


[dev-dependencies]
rand = "0.8.3"

Expand Down
34 changes: 19 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# ------------------ #
# -- Odin Builder -- #
# ------------------ #
FROM mbround18/valheim-odin:latest as RustBuilder
ARG ODIN_IMAGE_VERSION=latest
FROM mbround18/valheim-odin:${ODIN_IMAGE_VERSION} as RustBuilder

# --------------- #
# -- Steam CMD -- #
# --------------- #
FROM cm2network/steamcmd:root

RUN apt-get update \
&& apt-get install -y \
htop net-tools nano \
netcat curl wget \
cron sudo gosu dos2unix \
libsdl2-2.0-0 jq \
&& rm -rf /var/lib/apt/lists/* \
&& gosu nobody true \
RUN apt-get update \
&& apt-get install -y \
htop net-tools nano gcc g++ \
netcat curl wget zip unzip \
cron sudo gosu dos2unix \
libsdl2-2.0-0 jq libc6-dev \
&& rm -rf /var/lib/apt/lists/* \
&& gosu nobody true \
&& dos2unix

# Container informaiton
Expand Down Expand Up @@ -49,19 +50,22 @@ ENV AUTO_BACKUP_DAYS_TO_LIVE "3"
ENV AUTO_BACKUP_ON_UPDATE "0"
ENV AUTO_BACKUP_ON_SHUTDOWN "0"

COPY --chmod=755 ./src/scripts/*.sh /home/steam/scripts/
COPY --chmod=755 ./src/scripts/entrypoint.sh /entrypoint.sh
COPY --from=RustBuilder --chmod=755 /data/odin/target/release/odin /usr/local/bin/odin
COPY --chown=steam:steam ./src/scripts/steam_bashrc.sh /home/steam/.bashrc
COPY ./src/scripts/*.sh /home/steam/scripts/
COPY ./src/scripts/entrypoint.sh /entrypoint.sh
COPY --from=RustBuilder /data/odin/target/release/odin /usr/local/bin/odin
COPY ./src/scripts/steam_bashrc.sh /home/steam/.bashrc

RUN usermod -u ${PUID} steam \
&& groupmod -g ${PGID} steam \
&& chsh -s /bin/bash steam \
&& printf "${GITHUB_SHA}\n${GITHUB_REF}\n${GITHUB_REPOSITORY}\n" >/home/steam/.version
&& printf "${GITHUB_SHA}\n${GITHUB_REF}\n${GITHUB_REPOSITORY}\n" >/home/steam/.version \
&& chmod 755 -R /home/steam/scripts/ \
&& chmod 755 /entrypoint.sh \
&& chmod 755 /usr/local/bin/odin


HEALTHCHECK --interval=1m --timeout=3s \
CMD gosu steam pidof valheim_server.x86_64 || exit 1
CMD pidof valheim_server.x86_64 || exit 1

ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
CMD ["/bin/bash", "/home/steam/scripts/start_valheim.sh"]
3 changes: 2 additions & 1 deletion Dockerfile.odin
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ FROM rust:latest as RustBuilder
WORKDIR /data/odin
COPY . .

RUN cargo build --release
RUN cargo build --release && find . ! -name 'odin' -type f -exec rm -f {} +


ENTRYPOINT ["/data/odin/target/release/odin"]
CMD ["--version"]
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
<img src="https://img.shields.io/github/workflow/status/mbround18/valheim-docker/Rust?label=Docker&style=for-the-badge">
</a>



## Docker

> [If you are looking for a guide on how to get started click here](https://github.com/mbround18/valheim-docker/discussions/28)
>
> Mod Support! It is supported to launch the server with BepInEx but!!!!! as a disclaimer! You take responsibility for debugging why your server won't start.
> Modding is not supported by the Valheim officially currently; Which means you WILL run into errors. This repo has been tested with running ValheimPlus as a test mod and does not have any issues.
> See [Getting started with mods]

### Environment Variables

> See further on down for advanced environment variables.

| Variable | Default | Required | Description |
|--------------------------|------------------------|----------|-------------|
| TZ | `America/Los_Angeles` | FALSE | Sets what timezone your container is running on. This is used for timestamps and cron jobs. [Click Here for which timezones are valid.](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) |
Expand All @@ -39,7 +43,6 @@
| AUTO_BACKUP_DAYS_TO_LIVE | `3` | FALSE | This is the number of days you would like to keep backups for. While backups are compressed and generally small it is best to change this number as needed. |
| AUTO_BACKUP_ON_UPDATE | `0` | FALSE | Create a backup on right before updating and starting your server. |
| AUTO_BACKUP_ON_SHUTDOWN | `0` | FALSE | Create a backup on shutdown. |
| ODIN_CONFIG_FILE | `config.json` | FALSE | This file stores start parameters to restart the instance, change if you run multiple container instances on the same host |

### Docker Compose

Expand Down Expand Up @@ -100,6 +103,36 @@ services:
- ./valheim/backups:/home/steam/backups
```

### Advanced Environment Variables

> Editing or adding these can cause issues! They are intended to give you more access to the system.

#### Odin Specific

> These are set automatically by [Odin];
> you DO NOT need to set these and only mess with them if you Know what you are doing.

| Variable | Default | Required | Description |
|--------------------------|------------------------|----------|-------------|
| DEBUG_MOD | `0` | FALSE | Set to `1` if you want a noisy output and to see what Odin is doing.
| ODIN_CONFIG_FILE | `config.json` | FALSE | This file stores start parameters to restart the instance, change if you run multiple container instances on the same host |
| ODIN_WORKING_DIR | `$PWD` | FALSE | Sets the directory you wish to run `odin` commands in and can be used to set where valheim is managed from. |

#### BepInEx/Modded Variables

> These are set automatically by [Odin] for a basic BepInEx installation;
> you DO NOT need to set these and only mess with them if you Know what you are doing.

| Variable | Default | Required | Description |
|--------------------------|----------------------------------------------------------|----------|-------------|
| LD_PRELOAD | `libdoorstop_x64.so` | TRUE | Sets which library to preload on Valheim start. |
| LD_LIBRARY_PATH | `./linux64:/home/steam/valheim/doorstop_libs` | TRUE | Sets which library paths it should look in for preload libs. |
| DOORSTOP_ENABLE | `TRUE` | TRUE | Enables Doorstop or not. |
| DOORSTOP_LIB | `libdoorstop_x64.so` | TRUE | Which doorstop lib to load |
| DOORSTOP_LIBS | `/home/steam/valheim/doorstop_libs` | TRUE | Where to look for doorstop libs. |
| DOORSTOP_INVOKE_DLL_PATH | `/home/steam/valheim/BepInEx/core/BepInEx.Preloader.dll` | TRUE | BepInEx preload dll to load. |
| DYLD_LIBRARY_PATH | `"/home/steam/valheim/doorstop_libs"` | TRUE | Sets the library paths. NOTE: This variable is weird and MUST have quotes around it! |
| DYLD_INSERT_LIBRARIES | `/home/steam/valheim/doorstop_libs/libdoorstop_x64.so` | TRUE | Sets which library to load. |

### [Odin]

Expand All @@ -108,7 +141,8 @@ This repo has a CLI tool called [Odin] in it! It is used for managing the server
## Versions:

- latest (Stable):
- [#100] Added backup feature to run based on cronjob.
- [#100] Added backup feature to run based on cronjob.
- [#148] Added Mod support
- 1.2.0 (Stable):
- Readme update to include the versions section and environment variables section.
- [#18] Changed to `root` as the default user to allow updated steams User+Group IDs.
Expand All @@ -135,6 +169,7 @@ This repo has a CLI tool called [Odin] in it! It is used for managing the server
- Has a bug in which it does not read passed in variables appropriately to Odin. Env variables are not impacted see [#3].

[//]: <> (Github Issues below...........)
[#148]: https://github.com/mbround18/valheim-docker/pull/148
[#100]: https://github.com/mbround18/valheim-docker/pull/100
[#89]: https://github.com/mbround18/valheim-docker/pull/89
[#77]: https://github.com/mbround18/valheim-docker/pull/77
Expand All @@ -151,6 +186,7 @@ This repo has a CLI tool called [Odin] in it! It is used for managing the server
[//]: <> (Links below...................)
[Odin]: ./docs/odin.md
[Valheim]: https://www.valheimgame.com/
[Getting started with mods]: ./docs/getting_started_with_mods.md
[If you need help figuring out a cron schedule click here]: https://crontab.guru/#0_1_*_*_*

[//]: <> (Image Base Url: https://github.com/mbround18/valheim-docker/blob/main/docs/assets/name.png?raw=true)
23 changes: 23 additions & 0 deletions docs/getting_started_with_mods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Getting started with Mods

> For this example we will be going over installing ValheimPlus. There is a lot of mysteries when it comes to modding but this should help you get started.

## Steps

1. Download the mod file, for our example we want the `UnixServer.zip` from `https://github.com/nxPublic/ValheimPlus/releases`
2. Place the file in your server volume mount. `cp UnixServer.zip /home/youruser/valheim/server`
3. Unzip the archive `unzip UnixServer.zip -d .` hit A to replace all as needed.
4. Restart your server.

> Odin automatically detects if you are running with BepInEx and adds the environment variables appropriately.
>
> DISCLAIMER! Modding your server can cause a lot of errors.
> Please do NOT post an issue on the valheim-docker repo based on mod issues.
> By installing mods, you agree that you will do a root cause analysis to why your server is failing before you make a post.
> Modding is currently unsupported by the Valheim developers and limited support by the valheim-docker repo.
> If you have issues please contact the MOD developer FIRST based on the output logs.

## Valheim Updated Help!!!!

Mod development is slow, and the more mods you have the more complicated it will be to keep everything up to date.
It is a suggestion that you turn off the AUTO_UPDATE variable when you are using mods and refrain from updating your local client until all your mods have been updated.
2 changes: 1 addition & 1 deletion src/cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ subcommands:
takes_value: true
- install:
about: Installs Valheim with steamcmd
version: "2.0"
version: "2.1"
author: mbround18
- start:
about: Starts Valheim
Expand Down
40 changes: 20 additions & 20 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ use std::fs::File;
use std::process::exit;

pub fn invoke(args: &ArgMatches) {
let input = args.value_of("INPUT_DIR").unwrap();
let output = args.value_of("OUTPUT_FILE").unwrap();
debug!("Creating archive of {}", input);
debug!("Output set to {}", output);
let tar_gz = match File::create(output) {
Ok(file) => file,
Err(_) => {
error!("Failed to create backup file at {}", output);
exit(1)
}
};
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
match tar.append_dir_all("saves", input) {
Ok(_) => debug!("Successfully created backup zip at {}", output),
Err(_) => {
error!("Failed to add {} to backup file", input);
exit(1)
}
};
let input = args.value_of("INPUT_DIR").unwrap();
let output = args.value_of("OUTPUT_FILE").unwrap();
debug!("Creating archive of {}", input);
debug!("Output set to {}", output);
let tar_gz = match File::create(output) {
Ok(file) => file,
Err(_) => {
error!("Failed to create backup file at {}", output);
exit(1)
}
};
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
match tar.append_dir_all("saves", input) {
Ok(_) => debug!("Successfully created backup zip at {}", output),
Err(_) => {
error!("Failed to add {} to backup file", input);
exit(1)
}
};
}
7 changes: 5 additions & 2 deletions src/commands/configure.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::files::config::{config_file, write_config};
use clap::ArgMatches;
use log::debug;

pub fn invoke(args: &ArgMatches) {
let config = config_file();
write_config(config, args);
debug!("Pulling config file...");
let config = config_file();
debug!("Writing config file...");
write_config(config, args);
}
29 changes: 17 additions & 12 deletions src/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use crate::executable::execute_mut;
use crate::steamcmd::steamcmd_command;
use crate::utils::get_working_dir;
use log::info;
use log::{debug, info};
use std::process::{ExitStatus, Stdio};

pub fn invoke(app_id: i64) -> std::io::Result<ExitStatus> {
info!("Installing {} to {}", app_id, get_working_dir());
let login = "+login anonymous".to_string();
let force_install_dir = format!("+force_install_dir {}", get_working_dir());
let app_update = format!("+app_update {}", app_id);
let mut steamcmd = steamcmd_command();
let install_command = steamcmd
.args(&[login, force_install_dir, app_update])
.arg("+quit")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());
execute_mut(install_command)
info!("Installing {} to {}", app_id, get_working_dir());
let login = "+login anonymous".to_string();
debug!("Argument set: {}", login);
let force_install_dir = format!("+force_install_dir {}", get_working_dir());
debug!("Argument set: {}", force_install_dir);
let app_update = format!("+app_update {}", app_id);
debug!("Argument set: {}", app_update);
let mut steamcmd = steamcmd_command();
debug!("Setting up install command...");
let install_command = steamcmd
.args(&[login, force_install_dir, app_update])
.arg("+quit")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());
debug!("Launching up install command...");
execute_mut(install_command)
}
Loading