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

rewrite #16

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### Linux template
*~
# Exclude any file inside the server and server-dev directory
server/*
server-dev/*

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
Expand Down
101 changes: 101 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
##
## StayInTarkov LINUX Container
##

ARG NODE=20.11.1

FROM alpine as git
RUN apk add git git-lfs

ARG SIT_COMMIT
ARG SIT_BRANCH=development
ARG SIT_PR
ARG SPT_COMMIT
ARG SPT_BRANCH=master
ARG SPT_PR


FROM git as spt
WORKDIR /opt
# invalidate cache and repull if upstream is different.
ADD https://dev.sp-tarkov.com/api/v1/repos/SPT-AKI/Server/git/refs/heads/${SPT_BRANCH} /opt/spt_version.json
# pull pr if provided, pull commit if provided, else single branch.
RUN if [ -n "$SPT_PR" ] && echo "$SPT_PR" | grep -Eq "^[0-9]+$"; then \
git clone https://dev.sp-tarkov.com/SPT-AKI/Server.git spt && \
cd spt && \
git fetch origin pull/$SPT_PR/head:pr_$SPT_PR && \
git checkout pr_$SPT_PR && \
git-lfs pull; \
elif [ -n "$SPT_COMMIT" ]; then \
git clone --single-branch --branch $SPT_BRANCH https://dev.sp-tarkov.com/SPT-AKI/Server.git spt && \
cd spt && \
git checkout $SPT_COMMIT && \
git-lfs pull; \
else \
git clone --single-branch --branch $SPT_BRANCH https://dev.sp-tarkov.com/SPT-AKI/Server.git spt && \
cd spt && \
git-lfs pull; \
fi

FROM git as sit
WORKDIR /opt
# invalidate cache and repull if upstream is different.
ADD https://api.github.com/repos/stayintarkov/SIT.Aki-Server-Mod/git/refs/heads/${SIT_BRANCH} /opt/sit_version.json
# pull pr if provided, pull commit if provided, else single branch.
RUN if [ -n "$SIT_PR" ] && echo "$SIT_PR" | grep -Eq "^[0-9]+$"; then \
git clone https://github.com/stayintarkov/SIT.Aki-Server-Mod.git sit && \
cd sit && \
git fetch origin pull/$SIT_PR/head:pr_$SIT_PR && \
git checkout pr_$SIT_PR && \
echo "pr_${SIT_PR}" > /opt/sit/version; \
elif [ -n "$SIT_COMMIT" ]; then \
git clone --single-branch --branch $SIT_BRANCH https://github.com/stayintarkov/SIT.Aki-Server-Mod.git sit && \
cd sit && \
git checkout $SIT_COMMIT && \
echo "$SIT_COMMIT" > /opt/sit/version; \
else \
git clone --single-branch --branch $SIT_BRANCH https://github.com/stayintarkov/SIT.Aki-Server-Mod.git sit && \
cat /opt/sit_version.json | sed -n 's/.*"sha":"\([^"]*\)".*/\1/p' > /opt/sit/version; \
fi
RUN echo "SIT version: $(cat /opt/sit/version)"

FROM node:${NODE}-alpine as builder
# spt needs git to build:release
RUN apk add git
COPY --from=spt /opt/spt /opt/builder
WORKDIR /opt/builder/project
RUN npm install
RUN npm run build:release
RUN mv build/ /opt/server/
COPY --from=sit /opt/sit /opt/server/user/mods/SITCoop
WORKDIR /opt/server/user/mods/SITCoop
RUN npm install
RUN rm -rf .git
RUN rm -rf /opt/builder

FROM alpine as server
RUN apk update
RUN apk --no-cache add libgcc libstdc++ libc6-compat screen dos2unix
RUN rm -rf /var/cache/apk/*
kapdon marked this conversation as resolved.
Show resolved Hide resolved

FROM server
WORKDIR /opt
COPY --from=builder /opt/server /opt/srv
COPY ./entrypoint.alpine.sh /opt/entrypoint.sh
# Fix for Windows
RUN dos2unix /opt/entrypoint.sh
# Set permissions
#RUN chmod o+rwx /opt -R
RUN chmod +x /opt/entrypoint.sh
kapdon marked this conversation as resolved.
Show resolved Hide resolved

# Exposing ports
EXPOSE 6969
EXPOSE 6970
EXPOSE 6971

VOLUME ["/opt/server"]

WORKDIR /opt/server
ENTRYPOINT ["/opt/entrypoint.sh"]
# Specify the default command to run when the container starts
CMD ["/opt/server/Aki.Server.exe"]
12 changes: 9 additions & 3 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ services:
tarkov-sitcoop-dev:
build:
context: .
dockerfile: Dockerfile.alpine
args:
SIT_BRANCH: "development"
SIT: "HEAD^"
SPT_BRANCH: "3.8.1-DEV"
SPT: "HEAD^"
SIT_COMMIT:
SIT_PR:
SPT_BRANCH: "master"
SPT_COMMIT:
SPT_PR:
container_name: sitcoop-dev
environment:
- BACKEND_IP=CHANGEME
#- SERVER_NAME=SIT
volumes:
- ./server-dev:/opt/server
ports:
Expand Down
81 changes: 81 additions & 0 deletions entrypoint.alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/ash

# Read the existing version from the version file (if it exists)
EXISTING_VERSION=$(cat /opt/server/version 2>/dev/null)
SIT_VERSION=$(cat /opt/srv/user/mods/SITCoop/version 2>/dev/null)

# Grab user ENV input if exists else default
SPT_IP=0.0.0.0
SPT_BACKEND_IP=${BACKEND_IP:-127.0.0.1}
NEW_SERVER_NAME=${SERVER_NAME:-SIT $SIT_VERSION}


echo "Stay In Tarkov Docker"
echo "github.com/StayInTarkov"

sit_setup() {
if [ -d "/opt/srv" ]; then
start=$(date +%s)
echo "Started copying files to your volume/directory.. Please wait."
cp -r /opt/srv/* /opt/server/
rm -r /opt/srv
end=$(date +%s)

echo "Files copied to your machine in $(($end-$start)) seconds."
echo "Starting the server to generate all the required files"
cd /opt/server
chown $(id -u):$(id -g) ./* -Rf
echo "set SPT_IP: $SPT_IP, updating http.json"
sed -ir 's/"ip": .*,/"ip": "'$SPT_IP'",/' /opt/server/Aki_Data/Server/configs/http.json

echo "BACKEND_IP: $SPT_BACKEND_IP, updating http.json"
sed -ir 's/"backendIp": .*,/"backendIp": "'$SPT_BACKEND_IP'",/' /opt/server/Aki_Data/Server/configs/http.json

sed -i "s/\"serverName\": \".*\"/\"serverName\": \"$NEW_SERVER_NAME\"/" /opt/server/Aki_Data/Server/configs/core.json
MODIFIED_NAME=$(sed -n 's/.*"serverName": "\([^"]*\)".*/\1/p' /opt/server/Aki_Data/Server/configs/core.json)
echo "Server Name: $MODIFIED_NAME, updating core.json"
# boot server once in bg to generate files.
screen -L -Logfile "install.log" -d -m -S AkiServer ./Aki.Server.exe
while [ ! -f "/opt/server/user/mods/SITCoop/config/coopConfig.json" ]; do
sleep 10 # sleep till coopConfig.json is generated
done
screen -S AkiServer -X "^C" # kill Aki.Server
echo "Follow the instructions to proceed!"
fi
}

# perform one-time server setup if no version file is found
if [ ! -e "/opt/server/version" ]; then
echo "No version file found, running first-time setup..."

sit_setup

# will prevent setup from running again
echo "saving $SIT_VERSION to /opt/server/version"
printf "%s" "$SIT_VERSION" > /opt/server/version
echo "SIT Version installed: $(cat /opt/server/version)"
exit 0
# existing version out of date run setup again.
elif [ "$EXISTING_VERSION" != "$SIT_VERSION" ] && [ -d "/opt/srv" ]; then
echo "new SIT version: $SIT_VERSION found"
echo "existing SIT version: $EXISTING_VERSION outdated, regenerating files."

sit_setup

# will prevent setup from running again
echo "saving $SIT_VERSION to /opt/server/version"
printf "%s" "$SIT_VERSION" > /opt/server/version
echo "SIT Version updated: $(cat /opt/server/version)"
exit 0
kapdon marked this conversation as resolved.
Show resolved Hide resolved
else
echo "existing SIT version: $EXISTING_VERSION"
echo "no update found, starting SIT..."
fi

# delete js n js.map files from existing mods (ignore SITCoop) and make sure server generates them fresh to prevent errors from copying windows artifact files.
find /opt/server/user/mods -type d -name "SITCoop" -prune -o \
-type f \( -name "*.js" -o -name "*.js.map" \) \
-exec sh -c 'for x; do ts="${x%.*}.ts"; [ -f "$ts" ] && rm "$x"; done' _ {} +
kapdon marked this conversation as resolved.
Show resolved Hide resolved

# continue to run whichever command was passed in (typically running Aki.Server.exe)
exec "$@"