Refact/zomboid2.0 #230
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test Server Image | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build-and-run: | |
name: Build and Run Server | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
system: [ podman ] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set Variables | |
id: variables | |
run: | | |
echo "datetime=$(date +%Y%m%dT%H%M%SZ)" >> $GITHUB_OUTPUT | |
echo "userid=$(id -u)" >> $GITHUB_OUTPUT | |
echo "groupid=$(id -g)" >> $GITHUB_OUTPUT | |
- name: Make Volumes | |
id: volumes | |
run: | | |
podman volume create zomboid-server-podman | |
podman volume create zomboid-config-podman | |
echo "installdir=$(podman volume inspect zomboid-server-podman | jq -r '.[].Mountpoint' -)" >> $GITHUB_OUTPUT | |
echo "configdir=$(podman volume inspect zomboid-config-podman | jq -r '.[].Mountpoint' -)" >> $GITHUB_OUTPUT | |
####################### | |
# Podman Build System # | |
####################### | |
- name: Download the latest version of the Image | |
if: ${{ success() && matrix.system == 'podman' }} | |
run: | | |
podman pull docker.io/renegademaster/zomboid-dedicated-server:latest | |
- name: Build the Podman Image | |
if: ${{ success() && matrix.system == 'podman' }} | |
run: | | |
BUILDAH_LAYERS=true buildah bud \ | |
--file image/zomboid-server.Containerfile \ | |
--tag docker.io/renegademaster/zomboid-dedicated-server:${{ steps.variables.outputs.datetime }} \ | |
. | |
- name: Test Run the Podman Image | |
if: ${{ success() && matrix.system == 'podman' }} | |
continue-on-error: true | |
timeout-minutes: 10 | |
run: | | |
# Start a timed shutdown signal | |
(sleep 360 && podman exec \ | |
zomboid-server bash -c \ | |
"rcon -a $(cat ${{ steps.volumes.outputs.configdir }}/ip.txt):\${RCON_PORT} -p \${RCON_PASSWORD} quit") & | |
# Run the Podman Image | |
podman run \ | |
--rm \ | |
--name zomboid-server \ | |
--volume "zomboid-server-podman":/home/steam/ZomboidDedicatedServer \ | |
--volume "zomboid-config-podman":/home/steam/Zomboid \ | |
--env=AUTOSAVE_INTERVAL="16" \ | |
--env LOG_LEVEL=DEBUG \ | |
--env=DEFAULT_PORT="25496" \ | |
--env=GC_CONFIG="G1GC" \ | |
--env=MAP_NAMES="BedfordFalls;North;South;West" \ | |
--env=MAX_PLAYERS="14" \ | |
--env=MAX_RAM="6144m" \ | |
--env=MOD_NAMES="BedfordFalls" \ | |
--env=MOD_WORKSHOP_IDS="522891356" \ | |
--env=PAUSE_ON_EMPTY="true" \ | |
--env=PUBLIC_SERVER="false" \ | |
--env=RCON_PASSWORD="github_action_test_rcon_password" \ | |
--env=RCON_PORT="27025" \ | |
--env=SERVER_NAME="GitHubActionTest" \ | |
--env=SERVER_PASSWORD="github_action_test_password" \ | |
--env=UDP_PORT="25499" \ | |
docker.io/renegademaster/zomboid-dedicated-server:${{ steps.variables.outputs.datetime }} \ | |
2>&1 | tee ./container.log | |
- name: Investigate File Structure | |
run: | | |
pwd | |
echo '' | |
ls -lAuhFn ./ | tee ./root-fs-listing.txt | |
echo '' | |
tree -aL 10 ./ | tee ./root-fs-tree.txt | |
echo '' | |
ls -lAuhFn ${{ steps.volumes.outputs.installdir }} | tee ./dedicated-server-install-listing.txt | |
echo '' | |
ls -lAuhFn ${{ steps.volumes.outputs.configdir }} | tee ./dedicated-server-config-listing.txt | |
echo '' | |
tree -aL 10 ${{ steps.volumes.outputs.installdir }} | tee ./dedicated-server-install-tree.txt | |
echo '' | |
tree -aL 10 ${{ steps.volumes.outputs.configdir }} | tee ./dedicated-server-config-tree.txt | |
- name: Upload Docker Logs | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v2 | |
with: | |
name: docker-logs-${{ matrix.system }} | |
path: | | |
container.log | |
- name: Upload Server Configuration | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v2 | |
with: | |
name: server-configs-${{ matrix.system }} | |
path: | | |
podman-compose.yaml | |
${{ steps.volumes.outputs.configdir }}/Server/GitHubActionTest.ini | |
${{ steps.volumes.outputs.configdir }}/Server/GitHubActionTest_SandboxVars.lua | |
${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json | |
dedicated-server-install-listing.txt | |
dedicated-server-config-listing.txt | |
root-fs-listing.txt | |
dedicated-server-install-tree.txt | |
dedicated-server-config-tree.txt | |
root-fs-config-tree.txt | |
test-docker: | |
name: Test Server | |
runs-on: ubuntu-latest | |
needs: | |
- build-and-run | |
strategy: | |
matrix: | |
system: [ podman ] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Download Docker Logs | |
uses: actions/download-artifact@v2 | |
with: | |
name: docker-logs-${{ matrix.system }} | |
- name: Download Server Configs | |
uses: actions/download-artifact@v2 | |
with: | |
name: server-configs-${{ matrix.system }} | |
- name: Test - Server Started | |
run: | | |
check_for_config() { | |
if ! grep -q -iE "$1" "./container.log"; then | |
printf "Could not find [%s] in [%s]\n" "$1" "./container.log" | |
exit 1 | |
else | |
printf "Found [%s] in [%s]\n" "$1" "./container.log" | |
fi | |
} | |
check_for_config "LuaNet: Initialization \[DONE\]" | |
- name: Test - Server Stopped Gracefully | |
run: | | |
check_for_config() { | |
if ! grep -q -iE "$1" "./container.log"; then | |
printf "Could not find [%s] in [%s]\n" "$1" "./container.log" | |
exit 1 | |
else | |
printf "Found [%s] in [%s]\n" "$1" "./container.log" | |
fi | |
} | |
check_for_config "ZNet: \[-> CZombienet: RakNetPeerInterface_Shutdown" | |
- name: Test - Configuration Completed | |
run: | | |
check_for_config() { | |
if ! grep -q -iE "$1" "./container.log"; then | |
printf "Could not find [%s] in [%s]\n" "$1" "./container.log" | |
else | |
printf "Found [%s] in [%s]\n" "$1" "./container.log" | |
exit 1 | |
fi | |
} | |
check_for_config "sed: can't read" | |
check_for_config "not found!" | |
- name: Test - Server JVM Configuration Applied | |
run: | | |
check_for_config() { | |
if ! grep -q -iE "$1" "${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json"; then | |
printf "Could not find [%s] in [%s]\n" "$1" "${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json" | |
exit 1 | |
else | |
printf "Found [%s] in [%s]\n" "$1" "${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json" | |
fi | |
} | |
check_for_config "\-Xmx6144m" | |
check_for_config "\-XX:\+UseG1GC" | |
- name: Test - Server Configuration Applied | |
run: | | |
install_directory="${{ steps.volumes.outputs.installdir }}" | |
workshop_directory="${install_directory}/steamapps/workshop" | |
mods_directory="${workshop_directory}/content/108600/522891356/mods" | |
bedford_maps="${mods_directory}/Bedford Falls/media/maps" | |
map_search_string="$(cat << EOF | |
│ ├── content | |
│ │ └── 108600 | |
│ │ └── 522891356 | |
│ │ └── mods | |
│ │ └── Bedford Falls | |
│ │ ├── media | |
│ │ │ ├── lua | |
│ │ │ │ ├── client | |
EOF | |
)" | |
py_script="$(cat << EOF | |
to_find = """${map_search_string}""" | |
with open("dedicated-server-install-tree.txt", "r") as file: | |
file_string = file.read() | |
if (to_find in file_string): | |
print("FOUND") | |
else: | |
print("NOT_FOUND") | |
EOF | |
)" | |
check_for_config() { | |
if ! grep -q -iE "$1" "${{ steps.variables.outputs.docker-config-dir }}/Server/GitHubActionTest.ini"; then | |
printf "Could not find [%s] in [%s]\n" "$1" "${{ steps.variables.outputs.docker-config-dir }}/Server/GitHubActionTest.ini" | |
exit 1 | |
else | |
printf "Found [%s] in [%s]\n" "$1" "${{ steps.variables.outputs.docker-config-dir }}/Server/GitHubActionTest.ini" | |
fi | |
} | |
check_for_directory() { | |
if [[ $(python3 -c "${py_script}") == "FOUND" ]]; then | |
printf "Found map directory in [%s]\n" "${bedford_maps}" | |
else | |
printf "Could not find map directory in [%s]\n" "${bedford_maps}" | |
exit 1 | |
fi | |
} | |
check_for_config "DefaultPort=25496" | |
check_for_config "Map=BedfordFalls;North;South;West" | |
check_for_config "MaxPlayers=14" | |
check_for_config "Open=false" | |
check_for_config "Password=github_action_test_password" | |
check_for_config "PauseEmpty=true" | |
check_for_config "PublicName=GitHubActionTest" | |
check_for_config "RCONPassword=github_action_test_rcon_password" | |
check_for_config "RCONPort=27025" | |
check_for_config "SaveWorldEveryMinutes=16" | |
check_for_config "UDPPort=25499" | |
check_for_directory |