Skip to content

Commit

Permalink
test: πŸ§ͺ Add unit tests to validate directory mapping and existence of…
Browse files Browse the repository at this point in the history
… game folder (#49)

#minor
  • Loading branch information
JamesIves authored Oct 3, 2024
1 parent e14065c commit 16abd1e
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 69 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,60 @@ jobs:
IMAGE=jives/hlds:${{ matrix.game }}-beta
VERSION=beta
- name: Add Custom Mod Content πŸ“‚
run: |
mkdir -p ./mods/decay
touch ./mods/decay/plugin.ini
- name: Add Configuration πŸ“‚
run: |
mkdir -p ./config
touch ./config/test.cfg
- name: Run Docker Container 🐳
run: |
docker run -d -ti \
--name hlds \
-v "./config:/temp/config" \
-v "./mods:/temp/mods" \
-p 27015:27015/udp \
-p 27015:27015 \
-p 26900:26900/udp \
-e GAME=${GAME} \
jives/hlds:${{ env.GAME }}-beta \
"+log on +rcon_password changeme +maxplayers 12"
sleep 5
- name: Validate Directory Mappings πŸ“‚
run: |
# Check if plugin.ini exists in the decay directory
if [ "$(docker exec hlds ls /opt/steam/hlds/decay | grep -c 'plugin.ini')" -eq 0 ]; then
echo "plugin.ini file is missing in the decay directory!"
exit 1
fi
# Check if test.cfg exists in the game directory
if [ "$(docker exec hlds ls /opt/steam/hlds/${{ env.GAME }} | grep -c 'test.cfg')" -eq 0 ]; then
echo "test.cfg file is missing in the ${{ env.GAME }} directory!"
exit 1
fi
# Check if crazytank.bsp exists in the maps directory
if [ "$(docker exec hlds ls /opt/steam/hlds/${{ env.GAME }}/maps | grep -c 'crazytank.bsp')" -eq 0 ]; then
echo "crazytank.bsp file is missing in the maps directory!"
exit 1
fi
echo "Volume mappings work as expectected!"
- name: Validate Game Directory Is Present πŸ“‚
run: |
GAME_NAME=$(echo "${{ env.GAME }}" | sed 's/-legacy//')
if [ "$(docker exec hlds ls /opt/steam/hlds | grep -c "$GAME_NAME")" -eq 0 ]; then
echo "$GAME_NAME directory is missing!"
exit 1
fi
- name: Set repo owner to lowercase
id: repo_owner
run: echo "::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | awk '{print tolower($0)}')"
Expand All @@ -103,3 +157,10 @@ jobs:
FLAG=${{ env.FLAG }}
VERSION=beta
IMAGE=ghcr.io/${{ steps.repo_owner.outputs.repo_owner }}/hlds:${{ matrix.game }}-beta
- name: Cleanup 🧹
if: always()
run: |
docker stop hlds
docker rm hlds
docker system prune --all --force
77 changes: 74 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ on:
workflow_dispatch:
jobs:
build:
name: Build and Validate 🏁
runs-on: ubuntu-latest

concurrency: ci-${{ github.ref }}
env:
GAME: cstrike
steps:
- name: Checkout πŸ›ŽοΈ
uses: actions/checkout@v4
Expand All @@ -19,7 +22,75 @@ jobs:
- name: Build Docker Image 🐳
uses: docker/build-push-action@v6
env:
GAME: cstrike
GAME: ${{ env.GAME }}
with:
context: ./container
build-args: GAME=cstrike
build-args: |
GAME=${{ env.GAME }}
load: true

- name: Get Docker Image ID πŸ†”
id: get_image_id
run: echo "image_id=$(docker images -q | head -n 1)" >> $GITHUB_ENV

- name: Add Custom Mod Content πŸ“‚
run: |
mkdir -p ./mods/decay
touch ./mods/decay/plugin.ini
- name: Add Configuration πŸ“‚
run: |
mkdir -p ./config
mkdir -p ./config/maps
touch ./config/test.cfg
touch ./config/maps/crazytank.bsp
- name: Run Docker Container 🐳
run: |
docker run -d -ti \
--name hlds \
-v "./config:/temp/config" \
-v "./mods:/temp/mods" \
-p 27015:27015/udp \
-p 27015:27015 \
-p 26900:26900/udp \
-e GAME=${GAME} \
${{ env.image_id }} \
"+log on +rcon_password changeme +maxplayers 12 +map cs_italy"
- name: Validate Directory Mappings πŸ“‚
run: |
# Check if plugin.ini exists in the decay directory
if [ "$(docker exec hlds ls /opt/steam/hlds/decay | grep -c 'plugin.ini')" -eq 0 ]; then
echo "plugin.ini file is missing in the decay directory!"
exit 1
fi
# Check if test.cfg exists in the game directory
if [ "$(docker exec hlds ls /opt/steam/hlds/${{ env.GAME }} | grep -c 'test.cfg')" -eq 0 ]; then
echo "test.cfg file is missing in the ${{ env.GAME }} directory!"
exit 1
fi
# Check if crazytank.bsp exists in the maps directory
if [ "$(docker exec hlds ls /opt/steam/hlds/${{ env.GAME }}/maps | grep -c 'crazytank.bsp')" -eq 0 ]; then
echo "crazytank.bsp file is missing in the maps directory!"
exit 1
fi
echo "Volume mappings work as expectected!"
- name: Validate Game Directory Is Present πŸ“‚
run: |
GAME_NAME=$(echo "${{ env.GAME }}" | sed 's/-legacy//')
if [ "$(docker exec hlds ls /opt/steam/hlds | grep -c "$GAME_NAME")" -eq 0 ]; then
echo "$GAME_NAME directory is missing!"
exit 1
fi
- name: Cleanup 🧹
if: always()
run: |
docker stop hlds
docker rm hlds
docker system prune --all --force
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ docker run -d -ti \
-p 27015:27015/udp \
-p 27015:27015 \
-p 26900:26900/udp \
-e GAME=${GAME} \
jives/hlds:valve \
"+log on +rcon_password changeme +maxplayers 12 +map crossfire" # πŸ“£ Modify your server startup commands here. You can specify the image with the desired game you want the server to run in the line above.
```
Expand Down
5 changes: 3 additions & 2 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ If you wish to add server configurations, such as add-ons, plugins, map rotation
| β”‚ | β”œβ”€β”€ πŸ“œ crazytank.bsp
```


The `config` directory is volume-mapped within the directory for the game for which you're starting the container. For example, if you're starting a container for `cstrike`, you can add things like `mapcycle.txt` or `motd.txt` here, and it would appear within the corresponding `cstrike` directory within the container.

The config directory should be volume mapped to `/temp/config`, for example `./config:/temp/config"`, once the container starts it will re-write the files into the correct place so the Half-Life Dedicated Server client recognizes them.

> [!NOTE]
> The startup examples posted in the project README already have this directory volume mapped accordingly. If you've strayed from the suggested setup, [please refer back to it to get started](../../README.md).
Expand All @@ -30,7 +31,7 @@ The `config` directory is volume-mapped within the directory for the game for wh
> [!TIP]
> You can use this method to install server plugins such as AMX Mod, Meta Mod, etc., as the directory can handle nested folders too; for example, these can be placed in `config/addons/amxmodx` etc.
1. Create a folder called `config` alongside where you would typically start the server process. If you've cloned this project locally, you'd place your files alongside this README file.
1. Create a folder called `config` alongside where you would typically start the server process. If you've cloned this project locally, you'd place your files alongside this README file. If you're building a custom image, place them alongside the equivalent README in the `container` directory.
2. Add your config files to the directory.
3. Start the image as you usually would, either with `docker run` or `docker compose up`.

Expand Down
5 changes: 4 additions & 1 deletion container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ RUN dpkg --add-architecture i386 && \
RUN groupadd -r steam && \
useradd -r -g steam -m -d /opt/steam steam

# Creates the necessary directories for the Half-Life Dedicated Server.
# Creates the necessary directories for the Half-Life Dedicated Server, including the configuration and mods directories.
RUN mkdir /config
RUN mkdir /mods
RUN mkdir /temp
RUN mkdir /temp/config
RUN mkdir /temp/mods

# Sets the user to the steam user.
USER steam
Expand Down
26 changes: 1 addition & 25 deletions container/config/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
# Configs and Plugins

> [!WARNING]
> Configs added here will be included in the distributed image. This means users must override them on startup when using a distributed version.
If you wish to add server configurations, such as add-ons, plugins, map rotations, etc, you can add them to theΒ `config` directory. The `config` directory is volume-mapped within the directory for the game for which you're starting the container. For example, if you're starting a container for `cstrike`, you can add things like `mapcycle.txt` or `motd.txt` here, and it would appear within the corresponding `cstrike` directory on the server.

> [!NOTE]
> The startup examples posted in the project README already have this directory volume mapped accordingly. If you've strayed from the suggested setup, [please refer back to it to get started](../../README.md).
```
β”œβ”€β”€ hlds
β”‚ β”œβ”€β”€ cstrike
β”‚ β”‚ β”œβ”€β”€ models
β”‚ β”‚ β”œβ”€β”€ maps
β”‚ β”‚ β”œβ”€β”€ mapcycle.txt
β”‚ β”‚ β”œβ”€β”€ motd.txt
```

> [!TIP]
> You can use this method to install server plugins such as AMX Mod, Meta Mod, etc., as the directory can handle nested folders too; for example, these can be placed in `config/addons/amxmodx` etc.
1. Create a folder called `config` alongside where you would typically start the server process. If you've cloned this project locally, you'd place it alongside this README file.
2. Add your config files to the directory.
3. Start the image as you usually would, either with `docker run` or `docker compose up`.

For a list of all the available server configuration types, [refer to the Valve Developer Wiki](https://developer.valvesoftware.com/wiki/Main_Page).
[For setup instructions, please refer to the following README](../../config/README.md).
37 changes: 1 addition & 36 deletions container/mods/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
# Custom Mods

> [!WARNING]
> Mods added here will be included in the distributed image. This means users must override them on startup when using a distributed version.
If you want to run a custom mod, you can do so with the `mods` directory. The `mods` directory is volume mapped within the root directory of the Half-Life Dedicated Server client on startup. For example, if you wanted to add a mod named `decay`, you'd place it as a subfolder here, i.e., `mods/decay`. Once the container starts, it would be placed in the following directory.

```
β”œβ”€β”€ hlds
β”‚ β”œβ”€β”€ cstrike
β”‚ β”‚ β”œβ”€β”€ models
β”‚ β”‚ β”œβ”€β”€ maps
β”‚ β”‚ β”œβ”€β”€ autoexec.cfg
β”‚ β”œβ”€β”€ valve
β”‚ β”‚ β”œβ”€β”€ models
β”‚ β”‚ β”œβ”€β”€ maps
β”‚ β”‚ β”œβ”€β”€ autoexec.cfg
β”‚ β”œβ”€β”€ decay
β”‚ β”‚ β”œβ”€β”€ models
β”‚ β”‚ β”œβ”€β”€ maps
β”‚ β”‚ β”œβ”€β”€ autoexec.cfg
```

> [!NOTE]
> The startup examples posted in the project README already have this directory volume mapped accordingly. If you've strayed from the suggested setup, [please refer back to it to get started](../README.md).
1. Create a folder called `mods` alongside where you would normally start the server process. If you've cloned this project locally, you'd place it alongside this README file.
2. Add your mod files as a sub-directory of `mods`. For example if the mod name is `decay`, you'd place it in `mods/decay`.
3. Define the `GAME` environment variable for your mod name. The dedicated server client will use this to ensure that it starts a server for the correct mod, which corresponds with the directory name that was just created.

```bash
export GAME=decay
```

4. Start the image as you usually would, either with `docker run` or `docker compose up`. Most Half-Life mods require specific startup arguments. For more details, refer to the [Valve Developer Wiki](https://developer.valvesoftware.com/wiki/Half-Life_Dedicated_Server) and the instructions for the mod you're trying to run.

> [!TIP]
> When using a pre-built image, you'll likely want to use the `valve` base image (`jives/hlds:valve`).
[For setup instructions, please refer to the following README](../../mods/README.md).
4 changes: 3 additions & 1 deletion mods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ If you want to run a custom mod, you can do so with the `mods` directory. Your d

The `mods` directory is volume mapped within the root directory of the Half-Life Dedicated Server client on startup. For example, if you wanted to add a mod named `decay`, you'd place it as a subfolder here, i.e., `mods/decay`. Once the container starts, it would be placed in the following directory within the container.

The mods directory should be volume mapped to `/temp/mods`, for example `./mods:/temp/mods"`, once the container starts it will re-write the files into the correct place so the Half-Life Dedicated Server client recognizes them.

```
β”œβ”€β”€ πŸ“¦ hlds
β”‚ β”œβ”€β”€ πŸ“‚ cstrike
Expand All @@ -38,7 +40,7 @@ The `mods` directory is volume mapped within the root directory of the Half-Life
> [!NOTE]
> The startup examples posted in the project README already have this directory volume mapped accordingly. If you've strayed from the suggested setup, [please refer back to it to get started](../README.md).
1. Create a folder called `mods` alongside where you would normally start the server process. If you've cloned this project locally, you'd place your files longside this README file.
1. Create a folder called `mods` alongside where you would normally start the server process. If you've cloned this project locally, you'd place your files longside this README file. If you're building a custom image, place them alongside the equivalent README in the `container` directory.
2. Add your mod files as a sub-directory of `mods`. For example if the mod name is `decay`, you'd place it in `mods/decay`.
3. Define the `GAME` environment variable for your mod name. The dedicated server client will use this to ensure that it starts a server for the correct mod, which corresponds with the directory name that was just created.

Expand Down

0 comments on commit 16abd1e

Please sign in to comment.