Compare commits
5 Commits
develop
...
5f4561aa87
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f4561aa87 | |||
| b73f51faa4 | |||
| 1f899cc5e9 | |||
| d8f1910dd0 | |||
| 193ee5f87c |
@@ -17,6 +17,11 @@ services:
|
|||||||
ACC_IMAGE: acc-wine:latest
|
ACC_IMAGE: acc-wine:latest
|
||||||
ACC_SERVERS_PATH: /data/servers
|
ACC_SERVERS_PATH: /data/servers
|
||||||
ACC_SERVERS_HOST_PATH: /opt/acc-servers
|
ACC_SERVERS_HOST_PATH: /opt/acc-servers
|
||||||
|
# ACC_CPUSET: Pin all ACC containers to specific CPU cores (e.g., "0-11").
|
||||||
|
# Reduces simulation timing misses ("not enough CPU power" in accServer.exe).
|
||||||
|
# Set the CPU governor to 'performance' on the host for best results:
|
||||||
|
# echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||||
|
# ACC_CPUSET: "0-11"
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
# ACC Server container: Wine + accServer.exe
|
# ACC Server container: Wine Staging + accServer.exe
|
||||||
# Game files are bind-mounted from the host at /acc/game.
|
# Game files are bind-mounted from the host at /acc/game.
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
# Install Wine, Xvfb (headless display for Wine), and minimal runtime deps.
|
# Install Wine Staging from WineHQ (newer than Debian's packages, includes fsync support).
|
||||||
RUN dpkg --add-architecture i386 && \
|
RUN dpkg --add-architecture i386 && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends wget ca-certificates && \
|
||||||
wine \
|
mkdir -pm755 /etc/apt/keyrings && \
|
||||||
wine32 \
|
wget -q -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key && \
|
||||||
wine64 \
|
echo "deb [arch=amd64,i386 signed-by=/etc/apt/keyrings/winehq-archive.key] https://dl.winehq.org/wine-builds/debian/ bookworm main" \
|
||||||
|
> /etc/apt/sources.list.d/winehq.list && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y --install-recommends \
|
||||||
|
winehq-staging \
|
||||||
xvfb \
|
xvfb \
|
||||||
ca-certificates \
|
|
||||||
tcpdump \
|
tcpdump \
|
||||||
&& \
|
&& \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
@@ -22,6 +25,10 @@ WORKDIR /root
|
|||||||
ENV WINEARCH=win64
|
ENV WINEARCH=win64
|
||||||
ENV WINEPREFIX=/root/.wine
|
ENV WINEPREFIX=/root/.wine
|
||||||
ENV WINEDEBUG=-all
|
ENV WINEDEBUG=-all
|
||||||
|
# fsync uses Linux futex2 for Wine synchronization — reduces timing jitter under load.
|
||||||
|
# Falls back to esync (eventfd) if fsync is unavailable; falls back to standard if neither.
|
||||||
|
ENV WINEFSYNC=1
|
||||||
|
ENV WINEESYNC=1
|
||||||
|
|
||||||
# Copy entrypoint script.
|
# Copy entrypoint script.
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|||||||
13
go.mod
13
go.mod
@@ -3,7 +3,7 @@ module acc-server-manager
|
|||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/docker/docker v24.0.9+incompatible
|
github.com/docker/docker v27.5.1+incompatible
|
||||||
github.com/docker/go-connections v0.6.0
|
github.com/docker/go-connections v0.6.0
|
||||||
github.com/gofiber/fiber/v2 v2.52.8
|
github.com/gofiber/fiber/v2 v2.52.8
|
||||||
github.com/gofiber/swagger v1.1.0
|
github.com/gofiber/swagger v1.1.0
|
||||||
@@ -26,9 +26,14 @@ require (
|
|||||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||||
github.com/Microsoft/go-winio v0.4.21 // indirect
|
github.com/Microsoft/go-winio v0.4.21 // indirect
|
||||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/distribution/reference v0.6.0 // indirect
|
||||||
github.com/docker/distribution v2.7.1+incompatible // indirect
|
github.com/docker/distribution v2.7.1+incompatible // indirect
|
||||||
github.com/docker/go-units v0.5.0 // indirect
|
github.com/docker/go-units v0.5.0 // indirect
|
||||||
github.com/fasthttp/websocket v1.5.3 // indirect
|
github.com/fasthttp/websocket v1.5.3 // indirect
|
||||||
|
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||||
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||||
github.com/go-openapi/spec v0.21.0 // indirect
|
github.com/go-openapi/spec v0.21.0 // indirect
|
||||||
@@ -44,6 +49,7 @@ require (
|
|||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 // indirect
|
github.com/mattn/go-sqlite3 v1.14.22 // indirect
|
||||||
|
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||||
github.com/moby/term v0.5.2 // indirect
|
github.com/moby/term v0.5.2 // indirect
|
||||||
github.com/morikuni/aec v1.1.0 // indirect
|
github.com/morikuni/aec v1.1.0 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
@@ -56,6 +62,11 @@ require (
|
|||||||
github.com/swaggo/files/v2 v2.0.0 // indirect
|
github.com/swaggo/files/v2 v2.0.0 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 // indirect
|
||||||
|
go.opentelemetry.io/otel v1.42.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/metric v1.42.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/trace v1.42.0 // indirect
|
||||||
golang.org/x/sys v0.41.0 // indirect
|
golang.org/x/sys v0.41.0 // indirect
|
||||||
golang.org/x/time v0.9.0 // indirect
|
golang.org/x/time v0.9.0 // indirect
|
||||||
golang.org/x/tools v0.33.0 // indirect
|
golang.org/x/tools v0.33.0 // indirect
|
||||||
|
|||||||
25
go.sum
25
go.sum
@@ -6,18 +6,31 @@ github.com/Microsoft/go-winio v0.4.21 h1:+6mVbXh4wPzUrl1COX9A+ZCvEpYsOBZ6/+kwDnv
|
|||||||
github.com/Microsoft/go-winio v0.4.21/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
|
github.com/Microsoft/go-winio v0.4.21/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
|
||||||
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
|
||||||
|
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||||
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
|
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
|
||||||
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||||
github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0=
|
github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0=
|
||||||
github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||||
|
github.com/docker/docker v27.5.1+incompatible h1:4PYU5dnBYqRQi0294d1FBECqT9ECWeQAIfE8q4YnPY8=
|
||||||
|
github.com/docker/docker v27.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||||
github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94=
|
github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94=
|
||||||
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
|
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
|
||||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||||
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||||
github.com/fasthttp/websocket v1.5.3 h1:TPpQuLwJYfd4LJPXvHDYPMFWbLjsT91n3GpWtCQtdek=
|
github.com/fasthttp/websocket v1.5.3 h1:TPpQuLwJYfd4LJPXvHDYPMFWbLjsT91n3GpWtCQtdek=
|
||||||
github.com/fasthttp/websocket v1.5.3/go.mod h1:46gg/UBmTU1kUaTcwQXpUxtRwG2PvIZYeA8oL6vF3Fs=
|
github.com/fasthttp/websocket v1.5.3/go.mod h1:46gg/UBmTU1kUaTcwQXpUxtRwG2PvIZYeA8oL6vF3Fs=
|
||||||
|
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||||
|
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||||
|
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
||||||
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
||||||
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
||||||
@@ -67,6 +80,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
|
|||||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
||||||
|
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
||||||
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
|
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
|
||||||
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
|
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
|
||||||
github.com/morikuni/aec v1.1.0 h1:vBBl0pUnvi/Je71dsRrhMBtreIqNMYErSAbEeb8jrXQ=
|
github.com/morikuni/aec v1.1.0 h1:vBBl0pUnvi/Je71dsRrhMBtreIqNMYErSAbEeb8jrXQ=
|
||||||
@@ -104,6 +119,16 @@ github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVS
|
|||||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 h1:OyrsyzuttWTSur2qN/Lm0m2a8yqyIjUVBZcxFPuXq2o=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0/go.mod h1:C2NGBr+kAB4bk3xtMXfZ94gqFDtg/GkI7e9zqGh5Beg=
|
||||||
|
go.opentelemetry.io/otel v1.42.0 h1:lSQGzTgVR3+sgJDAU/7/ZMjN9Z+vUip7leaqBKy4sho=
|
||||||
|
go.opentelemetry.io/otel v1.42.0/go.mod h1:lJNsdRMxCUIWuMlVJWzecSMuNjE7dOYyWlqOXWkdqCc=
|
||||||
|
go.opentelemetry.io/otel/metric v1.42.0 h1:2jXG+3oZLNXEPfNmnpxKDeZsFI5o4J+nz6xUlaFdF/4=
|
||||||
|
go.opentelemetry.io/otel/metric v1.42.0/go.mod h1:RlUN/7vTU7Ao/diDkEpQpnz3/92J9ko05BIwxYa2SSI=
|
||||||
|
go.opentelemetry.io/otel/trace v1.42.0 h1:OUCgIPt+mzOnaUTpOQcBiM/PLQ/Op7oq6g4LenLmOYY=
|
||||||
|
go.opentelemetry.io/otel/trace v1.42.0/go.mod h1:f3K9S+IFqnumBkKhRJMeaZeNk9epyhnCmQh/EysQCdc=
|
||||||
go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
|
go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
|
||||||
go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
|
go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
|||||||
@@ -1,39 +1,70 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"acc-server-manager/local/middleware"
|
||||||
|
"acc-server-manager/local/model"
|
||||||
|
"acc-server-manager/local/service"
|
||||||
"acc-server-manager/local/utl/common"
|
"acc-server-manager/local/utl/common"
|
||||||
"acc-server-manager/local/utl/configs"
|
"acc-server-manager/local/utl/configs"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"go.uber.org/dig"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SystemController struct {
|
type SystemController struct {
|
||||||
|
systemService *service.SystemService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSystemController
|
type SystemControllerParams struct {
|
||||||
// Initializes SystemController.
|
dig.In
|
||||||
//
|
RouteGroups *common.RouteGroups
|
||||||
// Args:
|
AuthMiddleware *middleware.AuthMiddleware
|
||||||
// *services.SystemService: Service control service
|
SystemService *service.SystemService `optional:"true"`
|
||||||
// *Fiber.RouterGroup: Fiber Router Group
|
}
|
||||||
// Returns:
|
|
||||||
// *SystemController: Controller for service control interactions
|
|
||||||
func NewSystemController(routeGroups *common.RouteGroups) *SystemController {
|
|
||||||
ac := &SystemController{}
|
|
||||||
|
|
||||||
apiGroup := routeGroups.System
|
// NewSystemController initializes SystemController.
|
||||||
apiGroup.Get("/health", ac.getFirst)
|
func NewSystemController(p SystemControllerParams) *SystemController {
|
||||||
|
ac := &SystemController{systemService: p.SystemService}
|
||||||
|
|
||||||
|
apiGroup := p.RouteGroups.System
|
||||||
|
apiGroup.Get("/health", ac.getHealth)
|
||||||
|
|
||||||
|
if p.SystemService != nil {
|
||||||
|
apiGroup.Post("/migrate-image", p.AuthMiddleware.Authenticate, ac.migrateImage)
|
||||||
|
}
|
||||||
|
|
||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
|
|
||||||
// getFirst returns service control status
|
// getHealth returns the current version string.
|
||||||
//
|
//
|
||||||
// @Summary Return service control status
|
// @Summary Return service health / version
|
||||||
// @Description Return service control status
|
// @Description Return service health / version
|
||||||
// @Tags system
|
// @Tags system
|
||||||
// @Success 200 {array} string
|
// @Success 200 {string} string
|
||||||
// @Router /system/health [get]
|
// @Router /system/health [get]
|
||||||
func (ac *SystemController) getFirst(c *fiber.Ctx) error {
|
func (ac *SystemController) getHealth(c *fiber.Ctx) error {
|
||||||
return c.SendString(configs.Version)
|
return c.SendString(configs.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// migrateImage godoc
|
||||||
|
//
|
||||||
|
// @Summary Migrate all Docker server containers to current ACC image
|
||||||
|
// @Description Pulls the current ACC_IMAGE, removes old containers, optionally stops running servers
|
||||||
|
// @Tags system
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.MigrateImageRequest true "Migration options"
|
||||||
|
// @Success 200 {object} model.MigrationResult
|
||||||
|
// @Router /system/migrate-image [post]
|
||||||
|
func (ac *SystemController) migrateImage(c *fiber.Ctx) error {
|
||||||
|
var req model.MigrateImageRequest
|
||||||
|
if err := c.BodyParser(&req); err != nil {
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "invalid request"})
|
||||||
|
}
|
||||||
|
result, err := ac.systemService.MigrateImage(c.Context(), req.StopRunning)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(result)
|
||||||
|
}
|
||||||
|
|||||||
24
local/model/system.go
Normal file
24
local/model/system.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type MigrateImageRequest struct {
|
||||||
|
StopRunning bool `json:"stopRunning"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerMigrationEntry struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
WasRunning bool `json:"wasRunning"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerMigrationError struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MigrationResult struct {
|
||||||
|
Image string `json:"image"`
|
||||||
|
Migrated []ServerMigrationEntry `json:"migrated"`
|
||||||
|
Skipped []ServerMigrationEntry `json:"skipped"`
|
||||||
|
Failed []ServerMigrationError `json:"failed"`
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types/container"
|
||||||
dockerclient "github.com/docker/docker/client"
|
dockerclient "github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/pkg/stdcopy"
|
"github.com/docker/docker/pkg/stdcopy"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -40,7 +40,7 @@ func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, han
|
|||||||
go func() {
|
go func() {
|
||||||
defer s.cancels.Delete(server.ID)
|
defer s.cancels.Delete(server.ID)
|
||||||
|
|
||||||
rc, err := s.client.ContainerLogs(streamCtx, server.ContainerID, types.ContainerLogsOptions{
|
rc, err := s.client.ContainerLogs(streamCtx, server.ContainerID, container.LogsOptions{
|
||||||
ShowStdout: true,
|
ShowStdout: true,
|
||||||
ShowStderr: true,
|
ShowStderr: true,
|
||||||
Follow: true,
|
Follow: true,
|
||||||
@@ -81,7 +81,7 @@ func (s *DockerLogStreamer) GetLastLines(ctx context.Context, server *model.Serv
|
|||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rc, err := s.client.ContainerLogs(ctx, server.ContainerID, types.ContainerLogsOptions{
|
rc, err := s.client.ContainerLogs(ctx, server.ContainerID, container.LogsOptions{
|
||||||
ShowStdout: true,
|
ShowStdout: true,
|
||||||
ShowStderr: true,
|
ShowStderr: true,
|
||||||
Tail: strconv.Itoa(n),
|
Tail: strconv.Itoa(n),
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
dockerclient "github.com/docker/docker/client"
|
dockerclient "github.com/docker/docker/client"
|
||||||
@@ -63,19 +62,24 @@ func (r *DockerRuntime) Create(ctx context.Context, server *model.Server) error
|
|||||||
fmt.Sprintf("%s:/acc/game:rw", hostServerPath),
|
fmt.Sprintf("%s:/acc/game:rw", hostServerPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hostConfig := &container.HostConfig{
|
||||||
|
Binds: binds,
|
||||||
|
PortBindings: portBindings,
|
||||||
|
RestartPolicy: container.RestartPolicy{Name: "unless-stopped"},
|
||||||
|
// NET_RAW is required for tcpdump packet capture in debug mode (DEBUG_MODE=1).
|
||||||
|
CapAdd: []string{"NET_RAW"},
|
||||||
|
}
|
||||||
|
if cpuset := env.GetACCCpuset(); cpuset != "" {
|
||||||
|
hostConfig.CpusetCpus = cpuset
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := r.client.ContainerCreate(ctx, &container.Config{
|
resp, err := r.client.ContainerCreate(ctx, &container.Config{
|
||||||
Image: image,
|
Image: image,
|
||||||
ExposedPorts: exposedPorts,
|
ExposedPorts: exposedPorts,
|
||||||
Env: []string{
|
Env: []string{
|
||||||
fmt.Sprintf("SERVER_PORT=%d", server.Port),
|
fmt.Sprintf("SERVER_PORT=%d", server.Port),
|
||||||
},
|
},
|
||||||
}, &container.HostConfig{
|
}, hostConfig, nil, nil, server.ServiceName)
|
||||||
Binds: binds,
|
|
||||||
PortBindings: portBindings,
|
|
||||||
RestartPolicy: container.RestartPolicy{Name: "unless-stopped"},
|
|
||||||
// NET_RAW is required for tcpdump packet capture in debug mode (DEBUG_MODE=1).
|
|
||||||
CapAdd: []string{"NET_RAW"},
|
|
||||||
}, nil, nil, server.ServiceName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create container %s: %v", server.ServiceName, err)
|
return fmt.Errorf("failed to create container %s: %v", server.ServiceName, err)
|
||||||
}
|
}
|
||||||
@@ -94,7 +98,7 @@ func (r *DockerRuntime) Delete(ctx context.Context, serverID uuid.UUID) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.client.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{
|
err = r.client.ContainerRemove(ctx, containerID, container.RemoveOptions{
|
||||||
Force: true,
|
Force: true,
|
||||||
RemoveVolumes: false,
|
RemoveVolumes: false,
|
||||||
})
|
})
|
||||||
@@ -119,7 +123,7 @@ func (r *DockerRuntime) Start(ctx context.Context, serverID uuid.UUID) (string,
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.client.ContainerStart(ctx, containerID, types.ContainerStartOptions{}); err != nil {
|
if err := r.client.ContainerStart(ctx, containerID, container.StartOptions{}); err != nil {
|
||||||
return "", fmt.Errorf("failed to start container: %v", err)
|
return "", fmt.Errorf("failed to start container: %v", err)
|
||||||
}
|
}
|
||||||
return model.StatusRunning.String(), nil
|
return model.StatusRunning.String(), nil
|
||||||
@@ -209,7 +213,7 @@ func (r *DockerRuntime) resolveContainerID(ctx context.Context, serverID uuid.UU
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *DockerRuntime) findContainerByName(ctx context.Context, name string) (string, error) {
|
func (r *DockerRuntime) findContainerByName(ctx context.Context, name string) (string, error) {
|
||||||
containers, err := r.client.ContainerList(ctx, types.ContainerListOptions{
|
containers, err := r.client.ContainerList(ctx, container.ListOptions{
|
||||||
All: true,
|
All: true,
|
||||||
Filters: filters.NewArgs(filters.Arg("name", "/"+name)),
|
Filters: filters.NewArgs(filters.Arg("name", "/"+name)),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -100,4 +100,7 @@ func registerDockerProviders(c *dig.Container) {
|
|||||||
c.Provide(func(client *dockerclient.Client) platform.LogStreamer {
|
c.Provide(func(client *dockerclient.Client) platform.LogStreamer {
|
||||||
return NewDockerLogStreamer(client)
|
return NewDockerLogStreamer(client)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
c.Provide(NewSystemService)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
115
local/service/system_service.go
Normal file
115
local/service/system_service.go
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"acc-server-manager/local/model"
|
||||||
|
"acc-server-manager/local/platform"
|
||||||
|
"acc-server-manager/local/repository"
|
||||||
|
"acc-server-manager/local/utl/env"
|
||||||
|
"acc-server-manager/local/utl/logging"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types/container"
|
||||||
|
dockerimage "github.com/docker/docker/api/types/image"
|
||||||
|
dockerclient "github.com/docker/docker/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SystemService struct {
|
||||||
|
dockerClient *dockerclient.Client
|
||||||
|
repo *repository.ServerRepository
|
||||||
|
runtime platform.ServerRuntime
|
||||||
|
serverService *ServerService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSystemService(
|
||||||
|
dockerClient *dockerclient.Client,
|
||||||
|
repo *repository.ServerRepository,
|
||||||
|
runtime platform.ServerRuntime,
|
||||||
|
serverService *ServerService,
|
||||||
|
) *SystemService {
|
||||||
|
return &SystemService{
|
||||||
|
dockerClient: dockerClient,
|
||||||
|
repo: repo,
|
||||||
|
runtime: runtime,
|
||||||
|
serverService: serverService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SystemService) MigrateImage(ctx context.Context, stopRunning bool) (*model.MigrationResult, error) {
|
||||||
|
image := env.GetACCImage()
|
||||||
|
|
||||||
|
reader, err := s.dockerClient.ImagePull(ctx, image, dockerimage.PullOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to pull image %s: %v", image, err)
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(io.Discard, reader); err != nil {
|
||||||
|
logging.Warn("Error draining image pull response for %s: %v", image, err)
|
||||||
|
}
|
||||||
|
reader.Close()
|
||||||
|
logging.Info("Pulled image %s", image)
|
||||||
|
|
||||||
|
servers, err := s.repo.GetAll(ctx, &model.ServerFilter{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to list servers: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &model.MigrationResult{Image: image}
|
||||||
|
|
||||||
|
for _, server := range *servers {
|
||||||
|
statusStr, _ := s.runtime.Status(ctx, server.ID)
|
||||||
|
isRunning := statusStr == model.StatusRunning.String()
|
||||||
|
|
||||||
|
if isRunning && !stopRunning {
|
||||||
|
result.Skipped = append(result.Skipped, model.ServerMigrationEntry{
|
||||||
|
ID: server.ID.String(),
|
||||||
|
Name: server.Name,
|
||||||
|
WasRunning: true,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
entry := model.ServerMigrationEntry{
|
||||||
|
ID: server.ID.String(),
|
||||||
|
Name: server.Name,
|
||||||
|
WasRunning: isRunning,
|
||||||
|
}
|
||||||
|
|
||||||
|
if isRunning {
|
||||||
|
if _, err := s.runtime.Stop(ctx, server.ID); err != nil {
|
||||||
|
result.Failed = append(result.Failed, model.ServerMigrationError{
|
||||||
|
ID: server.ID.String(),
|
||||||
|
Name: server.Name,
|
||||||
|
Error: fmt.Sprintf("stop failed: %v", err),
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if server.ContainerID != "" {
|
||||||
|
if err := s.dockerClient.ContainerRemove(ctx, server.ContainerID, container.RemoveOptions{Force: true}); err != nil {
|
||||||
|
logging.Warn("Failed to remove container %s for server %s: %v", server.ContainerID, server.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
server.ContainerID = ""
|
||||||
|
if err := s.repo.Update(ctx, &server); err != nil {
|
||||||
|
logging.Warn("Failed to clear ContainerID for server %s: %v", server.ID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if isRunning {
|
||||||
|
if _, err := s.runtime.Start(ctx, server.ID); err != nil {
|
||||||
|
result.Failed = append(result.Failed, model.ServerMigrationError{
|
||||||
|
ID: server.ID.String(),
|
||||||
|
Name: server.Name,
|
||||||
|
Error: fmt.Sprintf("restart failed: %v", err),
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
s.serverService.StartAccServerRuntime(&server)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Migrated = append(result.Migrated, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version = "0.13.0"
|
Version = "0.13.1"
|
||||||
Prefix = "v1"
|
Prefix = "v1"
|
||||||
Secret string
|
Secret string
|
||||||
SecretCode string
|
SecretCode string
|
||||||
|
|||||||
4
local/utl/env/env.go
vendored
4
local/utl/env/env.go
vendored
@@ -65,6 +65,10 @@ func GetACCServersPath() string {
|
|||||||
return DefaultACCServersPath
|
return DefaultACCServersPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetACCCpuset() string {
|
||||||
|
return os.Getenv("ACC_CPUSET")
|
||||||
|
}
|
||||||
|
|
||||||
func GetACCServersHostPath() string {
|
func GetACCServersHostPath() string {
|
||||||
if p := os.Getenv("ACC_SERVERS_HOST_PATH"); p != "" {
|
if p := os.Getenv("ACC_SERVERS_HOST_PATH"); p != "" {
|
||||||
return p
|
return p
|
||||||
|
|||||||
Reference in New Issue
Block a user