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

Feature: add docker task #108

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build.sh
117 changes: 117 additions & 0 deletions .vscode/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

# Define color codes
RED="\e[31m"
ORANGE="\e[33m"
GREEN="\e[32m"
WHITE_BG="\e[47m"
RESET="\e[0m"

# Function to print colored messages
print_color() {
local color="$1"
local message="$2"
echo -e "${color}${message}${RESET}"
}


# Define directories
srcDir="$1"

# Check if directory is not empty
if [ -z "$srcDir" ]; then
print_color $RED "❌ Error: Argument 1 not provided"
exit 1
fi

# Check if directory does not exist
if [ ! -d "$srcDir" ]; then
print_color $RED "❌ Error: Directory '$srcDir' not found"
exit 1
fi

# Make amxxpc happy to find amxxpc32.so nearly
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$srcDir/scripting

destinationDir="$2"

# Check if directory is not empty
if [ -z "$destinationDir" ]; then
print_color $RED "❌ Error: Argument 2 not provided"
exit 1
fi

# Check if directory does not exist
if [ ! -d "$destinationDir" ]; then
print_color $RED "❌ Error: Directory '$destinationDir' not found"
exit 1
fi

scriptingDir="$destinationDir/scripting"



# Function to compile a .sma file
compile_sma() {
local smaFile="$1"
local outputPluginDir="$2"

pluginName=$(basename "${smaFile%.sma}")
relativeDir=$(dirname "${smaFile#$srcDir}")
outputPlugin="$outputPluginDir/${pluginName}.amxx"

# Create the output plugin directory if it doesn't exist
mkdir -p "$outputPluginDir"

# Print the name of the .sma file with white background
# print_color $WHITE_BG " - Compiling: $(basename $smaFile)"

# Get the last modification time of the output plugin file
lastModTime=$(stat -c %Y "$smaFile" 2>/dev/null)
now=$(date +%s)
diff=$((now-lastModTime))

# Check if the file exists and its last modification time is within the last minute

# Compile the .sma file and capture its output, excluding the lines with version and copyright info
compile_output=$("$scriptingDir/amxxpc" \
"$smaFile" \
-i"$srcDir/scripting" \
-i"$srcDir/scripting/include" \
-i"$srcDir/scripting/ReDeathmatch" \
-o"$outputPlugin" 2>&1 | grep -vE "AMX Mod X Compiler|Copyright|Could not locate output file")

# Check if there are any errors or warnings in the compile output
if echo "$compile_output" | grep -qi "error"; then
error_lines=$(echo "$compile_output" | grep -i "error" | sed 's/.*scripting\///')
warning_lines=$(echo "$compile_output" | grep -i "warning" | sed 's/.*scripting\///')
print_color $RED "❌ $error_lines"
if [ -n "$warning_lines" ]; then
print_color $ORANGE "⚠️ $warning_lines"
fi
elif echo "$compile_output" | grep -qi "warning"; then
warning_lines=$(echo "$compile_output" | grep -i "warning" | sed 's/.*scripting\///')
print_color $ORANGE "⚠️ $warning_lines"
else
print_color $GREEN " ✅ Compiled: $(basename $smaFile)"
fi

}

# Find and compile all .sma files in the source directory and its subdirectories
find $srcDir -name "*.sma" -type f | while read smaFile; do
relativeDir=$(dirname "${smaFile#$srcDir/scripting}")
outputPluginDir="$destinationDir/plugins$relativeDir"
compile_sma "$smaFile" "$outputPluginDir"
done

needCopyOther=$3
if [ "$needCopyOther" ]; then
echo ""

# Copy directories without confirmation with green messages
print_color $GREEN " - Copying configs..."
cp -an $srcDir/configs/* $destinationDir/configs/
print_color $GREEN " - Copying data..."
cp -an $srcDir/data/* $destinationDir/data/
fi
87 changes: 87 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build AMX Mod X Plugins",
"type": "shell",
"command": "bash",
"args": [
".vscode/build.sh",
// sourceDir
"$PWD/cstrike/addons/amxmodx",
// outputDir
"D:/Dev/HLDS_Server/cstrike/addons/amxmodx",
// copy `data` and `configs` ?
"1"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Build ReDeathmatch Image",
"type": "docker-build",
"dockerBuild": {
"context": "${workspaceFolder}/",
"tag": "redeathmatch:${input:mod}",
"buildArgs": {
"MOD": "${input:mod}"
}
},
"group": {
"kind": "build",
"isDefault": false
}
},
{
"type": "shell",
"label": "Run HLDS container",
"command": "docker run --rm -ti -p 26900-27020:26900-27020/udp redeathmatch:${input:mod} ./hlds_run -game ${input:mod} +maxplayers 32 -bots +ip 0.0.0.0 -port 27016 +map de_dust2",
"dependsOn": [
"Build ReDeathmatch Image"
],
"group": {
"kind": "build",
"isDefault": false
}
}
],
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": false,
"clear": true
},
"problemMatcher": {
"fileLocation": "autoDetect",
"owner": "problem",
"pattern": {
// Group 1 - filename (absolute path for filename)
// Group 2 - beginning line
// Group 3 - ending line (optional)
// Group 4 - error | warning (severity)
// Group 5 - message
"regexp": "(.+?)\\((\\d+)(?:\\s--\\s(\\d+))?\\)\\s:\\s(warning|error)\\s\\d+:\\s(.*)",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"inputs": [
{
"type": "pickString",
"id": "mod",
"default": "cstrike",
"description": "Select mod.",
"options": [
"cstrike",
"czero"
]
}
]
}
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# syntax=docker/dockerfile:1

ARG MOD="cstrike"

FROM debian:trixie-slim AS build_stage

# Install required packages
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
ca-certificates=20240203 \
curl=8.5.0-2 \
libarchive-tools=3.7.2-1 \
lib32stdc++6=14-20240201-3 \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/bin/
ADD --chmod=755 https://github.com/hldsdocker/rehlds/master/utils/GetGithubReleaseUrl.sh GetGithubReleaseUrl

WORKDIR /root/hlds/cstrike

# Install Metamod-R
RUN releaseLink="https://github.com/theAsmodai/metamod-r/releases/download/1.3.0.149/metamod-bin-1.3.0.149.zip" \
&& curl -sSL ${releaseLink} | bsdtar -xf - --exclude='*.dll' --exclude='*.pdb' addons/*

# Install AMXModX 1.9.0
ARG AMXModX_URL="https://www.amxmodx.org/amxxdrop/1.9/amxmodx-1.9.0-git5294-base-linux.tar.gz"
RUN curl -sSL ${AMXModX_URL} | bsdtar -xf - addons/ \
&& echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" > addons/metamod/plugins.ini

# Install ReAPI
RUN releaseLink="https://github.com/s1lentq/reapi/releases/download/5.24.0.300/reapi-bin-5.24.0.300.zip" \
&& curl -sSL ${releaseLink} | bsdtar -xf - --exclude='*.dll' --exclude='*.pdb' addons/

COPY cstrike .

SHELL ["/bin/bash", "-c"]

WORKDIR /usr/local/bin/
COPY --chmod=755 .vscode/build.sh BuildAMXXPlugins

WORKDIR /root/hlds/cstrike/addons/amxmodx/
RUN BuildAMXXPlugins . .


WORKDIR /root/hlds/cstrike/
ARG YaPB_URL="https://github.com/yapb/yapb/releases/download/4.4.957/yapb-4.4.957-linux.tar.xz"
RUN curl -sSL ${YaPB_URL} | bsdtar -xf - addons/ \
&& echo "linux addons/yapb/bin/yapb.so" >> addons/metamod/plugins.ini


ARG MOD
FROM hldsdocker/rehlds-${MOD}:regamedll AS run_stage

COPY --chown=${APPUSER}:${APPUSER} --chmod=755 --from=build_stage /root/hlds/cstrike ${MOD}

# Activate Metamod-R
RUN sed -i 's/gamedll_linux ".*"/gamedll_linux "addons\/metamod\/metamod_i386.so"/' ${MOD}/liblist.gam