Skip to content

Commit 5636b1a

Browse files
committed
feat: add dockerfile to run a server
1 parent 9533865 commit 5636b1a

File tree

8 files changed

+96
-10
lines changed

8 files changed

+96
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ test/
2121
gamemodes/reloadable-gamemode/
2222
gamemodes/remote-client/
2323
gamemodes/remote-server/
24-
server/
24+
server/
25+
target/

docker/base.Dockerfile renamed to docker/make.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ RUN apt-get update && apt-get install -y python3.8-dev:i386 libpython3.8-dev:i38
3737
WORKDIR /usr/src/pysamp
3838
COPY . .
3939

40-
RUN [ "cmake", "./src", "-G", "Unix Makefiles", "-DSAMPSDK_DIR=/root/sampsdk", "-DSAMPGDK_DIR=/root/sampgdk", "-DCMAKE_BUILD_TYPE=Debug" ]
41-
CMD make; cp ./PySAMP.so /target/
40+
RUN [ "cmake", "./src", "-G", "Unix Makefiles", "-DSAMPSDK_DIR=/root/sampsdk", "-DSAMPGDK_DIR=/root/sampgdk", "-DCMAKE_BUILD_TYPE=Debug", "-DPYTHON_INCLUDE_DIRS=/usr/include/i386-linux-gnu/python3.8", "-DPYTHON_LIBRARY=/usr/lib/i386-linux-gnu/libpython3.8.so" ]
41+
CMD make; cp ./PySAMP.so /target/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
docker build -f ./make.Dockerfile -t pysamp/make --build-arg BASE=ubuntu:bionic ../
12

2-
docker build -f ./base.Dockerfile -t pysamp/bionic --build-arg BASE=ubuntu:bionic ../
33
#docker build -f ./base.Dockerfile -t pysamp/eoan --build-arg BASE=ubuntu:eoan ../
44
#docker build -f ./base.Dockerfile -t pysamp/focal --build-arg BASE=ubuntu:focal ../
55

66
#docker build -f ./base.Dockerfile -t pysamp/stretch --build-arg BASE=debian:stretch ../
77
#docker build -f ./base.Dockerfile -t pysamp/buster --build-arg BASE=debian:buster ../
88

9-
docker run -v "$(cd ../ && pwd)"/target:/target --rm pysamp/stretch
9+
docker run --name pysamp -v "$(cd ../ && pwd)"/target:/target --rm pysamp/make

docker/scripts/check_server_config.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!python3
2+
import sys, os, random, string
3+
4+
if __name__ == "__main__":
5+
if len(sys.argv) < 2:
6+
print("Error, missing argument for server.cfg path")
7+
exit(1)
8+
updated_config = ''
9+
added_plugins = False
10+
with open(os.path.join(sys.argv[1], 'server.cfg')) as f:
11+
for line in f:
12+
if line.lstrip()[0] == '#':
13+
continue
14+
line = line.rstrip(' \r\n')
15+
k,v = line.split(' ', 1)
16+
if k == 'plugins' and 'PySAMP.so' not in v:
17+
added_plugins = True
18+
v += 'PySAMP.so'
19+
elif k == 'plugins' and 'PySAMP.so' in v:
20+
added_plugins = True
21+
if k == 'rcon_password' and v == 'changeme':
22+
print("Changed default password!")
23+
v = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(12))
24+
updated_config += '%s %s\n' % (k, v)
25+
26+
if not added_plugins:
27+
updated_config += 'plugins PySAMP.so\n'
28+
29+
with open(os.path.join(sys.argv[1], 'server.cfg'), 'w') as f:
30+
f.write(updated_config)
31+
32+

docker/scripts/start_server.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
./samp03svr 2>&1

docker/server.Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG BASE
2+
3+
FROM $BASE
4+
5+
# install dependencies
6+
RUN dpkg --add-architecture i386
7+
RUN apt-get update && apt-get install -y software-properties-common
8+
RUN add-apt-repository ppa:deadsnakes/ppa
9+
RUN apt-get update && apt-get install -y python3.8:i386 libpython3.8:i386
10+
RUN apt-get update && apt-get install -y libstdc++6:i386
11+
12+
WORKDIR /server
13+
14+
CMD "./start_server.sh"

docker/server.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# build PySAMP
4+
./make.sh
5+
6+
# create server dir if it doesn't exist
7+
if [[ ! -d ../server ]]; then
8+
mkdir ../server
9+
cd ../server
10+
wget http://files.sa-mp.com/samp037svr_R2-1.tar.gz
11+
tar xvf samp037svr_R2-1.tar.gz
12+
mv samp03/* ./
13+
rm -rf samp03
14+
cd ../docker
15+
fi
16+
17+
# create plugins folder
18+
if [[ ! -d ../server/plugins ]]; then
19+
mkdir ../server/plugins
20+
fi
21+
22+
# copy plugin to server
23+
cp ../target/PySAMP.so ../server/plugins/
24+
25+
# create python gamemode directory (if it doesn't exist)
26+
if [[ ! -d ../server/python ]]; then
27+
mkdir ../server/python
28+
cp -r ../gamemodes/empty/* ../server/python
29+
fi
30+
31+
# copy start script to server
32+
cp scripts/start_server.sh ../server
33+
chmod +x ../server/start_server.sh
34+
35+
# add plugin to server config and set password if it's still changeme
36+
python scripts/check_server_config.py ../server/
37+
38+
docker build -f ./server.Dockerfile -t pysamp/server --build-arg BASE=ubuntu:bionic ../
39+
docker run --name pysamp_server -v "$(cd ../ && pwd)"/server:/server -p 7777:7777 -p 7777:7777/udp --rm -it pysamp/server

src/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.7)
77
list(APPEND CMAKE_MODULE_PATH ${SAMPGDK_DIR}/cmake)
88

99
add_compile_options(-std=c++11)
10-
set(PYTHON_MIN_VERSION "3.5")
10+
set(PYTHON_MIN_VERSION 3.8)
1111

1212
find_package (PythonInterp ${PYTHON_MIN_VERSION} REQUIRED)
1313
find_package (PythonLibs ${PYTHON_MIN_VERSION} REQUIRED)
@@ -27,12 +27,12 @@ include_directories(
2727
${SAMPSDK_INCLUDE_DIR}
2828
${CMAKE_CURRENT_SOURCE_DIR}/bindings
2929
${CMAKE_CURRENT_SOURCE_DIR}/pysamp
30-
${PYTHON_INCLUDE_DIR}
30+
${PYTHON_INCLUDE_DIRS}
3131
)
3232

3333
message(STATUS "PYTHON_LIBRARY = ${PYTHON_LIBRARY}")
3434
message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
35-
message(STATUS "PYTHON_INCLUDE_DIR = ${PYTHON_INCLUDE_DIR}")
35+
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
3636
message(STATUS "SAMPGDK_LIBRARY = ${SAMPGDK_LIBRARY}")
3737

3838
add_definitions(-DSAMPGDK_AMALGAMATION)
@@ -54,8 +54,6 @@ add_samp_plugin(PySAMP
5454
bindings/samp.h
5555
bindings/const.h
5656
bindings/const.cpp
57-
test/callbackstest.h
58-
test/callbackstest.cpp
5957
)
6058

6159
target_link_libraries(PySAMP ${SAMPGDK_LIBRARY})

0 commit comments

Comments
 (0)