Skip to content

Commit

Permalink
Removed requirements mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
sea5kg committed Nov 16, 2023
1 parent 245fbec commit c5d7f23
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 1,183 deletions.
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
.git
dckr_mysql
tmp
.wsjcpp
docs
misc
data_test
game-simulation
dockers
tests
ctf01d-store
.ctf01d
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [v0.5.1] - (2023 Nov ??)

* Added show time left in scoreboard in seconds #65
* Redesign database from mysql/mariadb to sqlite3 (build-in)
* Removed requirements by mysqlcient

## [v0.5.0] - (2023 Nov 12)

Expand Down
59 changes: 9 additions & 50 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ list (APPEND WSJCPP_INCLUDE_DIRS "src")
list (APPEND WSJCPP_INCLUDE_DIRS "src/argument_processors")
list (APPEND WSJCPP_INCLUDE_DIRS "src/checker")
list (APPEND WSJCPP_INCLUDE_DIRS "src/scoreboard")
list (APPEND WSJCPP_INCLUDE_DIRS "src/storages")
list (APPEND WSJCPP_INCLUDE_DIRS "src/storages/file")
list (APPEND WSJCPP_INCLUDE_DIRS "src/service_locator")
list (APPEND WSJCPP_INCLUDE_DIRS "src/employees")
list (APPEND WSJCPP_INCLUDE_DIRS "src/store")
list (APPEND WSJCPP_INCLUDE_DIRS "src/3rdparty/sqlite3/src")

# argument processors
list (APPEND WSJCPP_SOURCES "./src/argument_processors/argument_processor_check.cpp")
Expand Down Expand Up @@ -86,62 +85,22 @@ list (APPEND WSJCPP_SOURCES "src/ctf01d_http_server.cpp")
# scoreboard
list (APPEND WSJCPP_SOURCES "src/scoreboard/ctf01d_scoreboard.cpp")

# storages
list (APPEND WSJCPP_SOURCES "src/storages/storages.cpp")

# file storage
# list (APPEND WSJCPP_SOURCES "src/storages/file/file_storage.cpp")

# store
list (APPEND WSJCPP_SOURCES "src/store/ctf01d_store.cpp")
list (APPEND WSJCPP_SOURCES "src/store/http_downloader.cpp")

# main
list (APPEND WSJCPP_SOURCES "src/main.cpp")


############################
##### mysql storage
list (APPEND WSJCPP_INCLUDE_DIRS "src/storages/mysql")
list (APPEND WSJCPP_SOURCES "src/storages/mysql/mysql_storage.cpp")

# Find and make sure the system have the header file
find_path(MYSQL_HEADER mysql/mysql.h)
if(MYSQL_HEADER STREQUAL "MYSQL_HEADER-NOTFOUND")
message(FATAL_ERROR "Could not find the mysql/mysql.h header file: apt install libmysqlclient-dev")
endif()

include(FindPkgConfig)
pkg_check_modules(LIBMYSQLCLIENT REQUIRED mysqlclient)

foreach(FLAG ${LIBMYSQLCLIENT_CFLAGS_OTHER})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
endforeach()

list (APPEND WSJCPP_INCLUDE_DIRS ${LIBMYSQLCLIENT_LIBRARY_DIRS})
list (APPEND WSJCPP_LIBRARIES ${LIBMYSQLCLIENT_LIBRARIES})

#####
############################

# ZLIB
find_package( ZLIB REQUIRED )
if ( ZLIB_FOUND )
list (APPEND WSJCPP_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
include_directories( ${ZLIB_INCLUDE_DIRS} )
list (APPEND WSJCPP_LIBRARIES ${ZLIB_LIBRARIES})
endif( ZLIB_FOUND )

# LIBPNG
find_package(PNG REQUIRED)
if (NOT PNG_FOUND)
message(FATAL_ERROR "You don't seem to have libpng development libraries installed (apt isntall libpng-dev)")
else ()
list (APPEND WSJCPP_INCLUDE_DIRS ${PNG_INCLUDE_DIR})
list (APPEND WSJCPP_LIBRARIES ${PNG_LIBRARY})
endif ()

# CURL
# find_package( ZLIB REQUIRED )
# if ( ZLIB_FOUND )
# list (APPEND WSJCPP_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
# include_directories( ${ZLIB_INCLUDE_DIRS} )
# list (APPEND WSJCPP_LIBRARIES ${ZLIB_LIBRARIES})
# endif( ZLIB_FOUND )

# # CURL
FIND_PACKAGE(CURL)
IF(CURL_FOUND)
list (APPEND WSJCPP_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# stage 0: build binary
FROM sea5kg/ctf01d-stage-build:v20231112
FROM sea5kg/ctf01d:stage-build-v20231116

COPY ./ /root/
WORKDIR /root/
RUN ./clean.sh && ./build_simple.sh

WORKDIR /root/unit-tests.wsjcpp
RUN ./build_simple.sh
RUN ./unit-tests
# WORKDIR /root/unit-tests.wsjcpp
# RUN ./build_simple.sh
# RUN ./unit-tests

# stage 1: release
FROM sea5kg/ctf01d-stage-release:v20231112
FROM sea5kg/ctf01d:stage-release-v20231116
LABEL "maintainer"="Evgenii Sopov <[email protected]>"
LABEL "repository"="https://github.com/sea-kg/ctf01d"

Expand Down
114 changes: 15 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ Create a `~/my-first-game/docker-compose.yml` file with the following content:
version: '3'

services:
ctf01d_db:
image: mysql:5.7
volumes:
- "./mysql_database:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: KzhyntJxwt
MYSQL_DATABASE: ctf01d
MYSQL_USER: ctf01d
MYSQL_PASSWORD: ctf01d
networks:
- ctf01d_net

ctf01d_jury:
depends_on:
- ctf01d_db
Expand All @@ -58,10 +45,6 @@ services:
- "./data_game:/usr/share/ctf01d"
environment:
CTF01D_WORKDIR: "/usr/share/ctf01d"
CTF01D_MYSQL_HOST: "ctf01d_db"
CTF01D_MYSQL_DATABASE: "ctf01d"
CTF01D_MYSQL_USER: "ctf01d"
CTF01D_MYSQL_PASSWORD: "ctf01d"
ports:
- "8080:8080"
restart: always
Expand Down Expand Up @@ -594,69 +577,14 @@ if command == "check":

## Ubuntu 20.04

Prepare database: mysql:

```
$ sudo apt install mysql-server mysql-common mysql-client
$ systemctl start mysql
```

Create database:
```
$ sudo mysql
...
mysql> CREATE DATABASE ctf01d CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.01 sec)
mysql> CREATE USER 'ctf01d'@'localhost' IDENTIFIED BY 'ctf01d';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON ctf01d.* TO 'ctf01d'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> exit;
Bye
```

or like a mariadb:
```
# mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.3.27-MariaDB-0+deb10u1 Debian 10
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE ctf01d CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> CREATE USER 'ctf01d'@'localhost' IDENTIFIED BY 'ctf01d';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON ctf01d.* TO 'ctf01d'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit;
Bye
```

Install package-requirements

```
sudo apt install git git-core\
make cmake g++ pkg-config \
libcurl4-openssl-dev \
zlibc zlib1g zlib1g-dev \
libpng-dev \
default-libmysqlclient-dev
libpng-dev
```

Clone source code of the project:
Expand All @@ -670,9 +598,6 @@ $ cd ~/ctf01d.git
$ ./build_simple.sh
```

*Maybe fix: `$ sudo ln -s /usr/lib/x86_64-linux-gnu/pkgconfig/mariadb.pc /usr/lib/x86_64-linux-gnu/pkgconfig/mysqlclient.pc`*
*More info: (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=878340)[https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=878340]*

Start:
```
$ cd ~/ctf01d.git
Expand All @@ -688,34 +613,18 @@ $ ./ctf01d -work-dir ./data_test -db-host localhost start
docker network create --driver=bridge ctf01d_net
```

2. Prepare mysql database:

In the next step we just start the container with mysql (like a daemon - in background)

```
docker run -d --rm \
--name ctf01d-mysql \
-e MYSQL_ROOT_PASSWORD=KzhyntJxwt \
-e MYSQL_DATABASE=ctf01d \
-e MYSQL_USER=ctf01d \
-e MYSQL_PASSWORD=ctf01d \
--network ctf01d_net \
mysql:8 \
mysqld --default-authentication-plugin=mysql_native_password
```

We can look for docker status: `docker ps -a`

3. Prepare docker for builds:
2. Prepare docker for builds:

*Notice: multistage build docker*

You need to download latest version of ctf01d-stage-build / ctf01d-stage-release or build it first
You need to download latest version of ctf01d:stage-build-latest / ctf01d:stage-release-latest or build it first

Download (docker pull):
```
$ docker pull sea5kg/ctf01d-stage-build
$ docker pull sea5kg/ctf01d-stage-release
$ docker pull sea5kg/ctf01d:stage-build-latest
$ docker pull sea5kg/ctf01d:stage-release-latest
```

Or build fresh images for stages:
Expand All @@ -737,7 +646,7 @@ $ docker build --rm=true -t "sea5kg/ctf01d:latest" .
$ docker tag "sea5kg/ctf01d:latest" "sea5kg/ctf01d:v0.4.x"
```

4. Run dev docker-container, build and start
3. Run dev docker-container, build and start

Run:
```
Expand All @@ -748,7 +657,7 @@ $ docker run -it --rm \
-w /root/ctf01d.dev \
--name "ctf01d.dev" \
--network ctf01d_net \
sea5kg/ctf01d-stage-build:latest \
sea5kg/ctf01d:stage-build-latest \
bash
root@604feda3c718:~/ctf01d.dev#
```
Expand All @@ -761,11 +670,18 @@ root@604feda3c718:~/ctf01d.dev# ./build_simple.sh

Start:
```
root@604feda3c718:~/ctf01d.dev# ./ctf01d -work-dir ./data_sample/ -db-host ctf01d-mysql start
root@604feda3c718:~/ctf01d.dev# ./ctf01d -work-dir ./data_sample/ start
```

Now you can see scoreboard on http://localhost:8081

## Build release docker

```
docker build . -t sea5kg/ctf01d:v0.5.1
docker tag sea5kg/ctf01d:v0.5.1 sea5kg/ctf01d:latest
```

# GAME SIMULATION

It's necessary for testing in conditions close to real game
Expand Down
7 changes: 1 addition & 6 deletions contrib/docker-build-stages/Dockerfile.ctf01d-stage-build
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ FROM debian:11
LABEL "maintainer"="Evgenii Sopov <[email protected]>"
LABEL "repository"="https://github.com/sea-kg/ctf01d"

RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y \
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y \
make cmake \
g++ \
pkg-config \
libcurl4-openssl-dev \
zlib1g zlib1g-dev \
libpng-dev \
default-libmysqlclient-dev \
python3 \
python3-pip \
&& pip3 install requests

# Old Fix for building on debian system (mysqlclient library)
# RUN ln -s /usr/lib/x86_64-linux-gnu/pkgconfig/mariadb.pc /usr/lib/x86_64-linux-gnu/pkgconfig/mysqlclient.pc
4 changes: 1 addition & 3 deletions contrib/docker-build-stages/Dockerfile.ctf01d-stage-release
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ FROM debian:11
LABEL "maintainer"="Evgenii Sopov <[email protected]>"
LABEL "repository"="https://github.com/sea-kg/ctf01d"

RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y \
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y \
libcurl4 \
zlib1g \
libpng16-16 \
libmariadb3 \
libpthread-stubs0-dev \
libssl-dev \
nano \
Expand Down
16 changes: 8 additions & 8 deletions contrib/docker-build-stages/build-stages-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ DT=$(date +"%Y%m%d")
TAG=$(echo "v$DT")
echo $TAG

docker rmi -f sea5kg/ctf01d-stage-build:$TAG
docker build -f Dockerfile.ctf01d-stage-build -t sea5kg/ctf01d-stage-build:$TAG .
docker rmi sea5kg/ctf01d-stage-build:latest
docker tag sea5kg/ctf01d-stage-build:$TAG sea5kg/ctf01d-stage-build:latest
docker rmi -f sea5kg/ctf01d:stage-build-$TAG
docker build -f Dockerfile.ctf01d-stage-build -t sea5kg/ctf01d:stage-build-$TAG .
docker rmi sea5kg/ctf01d:stage-build-latest
docker tag sea5kg/ctf01d:stage-build-$TAG sea5kg/ctf01d:stage-build-latest

docker rmi -f sea5kg/ctf01d-stage-release:$TAG
docker build -f Dockerfile.ctf01d-stage-release -t sea5kg/ctf01d-stage-release:$TAG .
docker rmi sea5kg/ctf01d-stage-release:latest
docker tag sea5kg/ctf01d-stage-release:$TAG sea5kg/ctf01d-stage-release:latest
docker rmi -f sea5kg/ctf01d:stage-release-$TAG
docker build -f Dockerfile.ctf01d-stage-release -t sea5kg/ctf01d:stage-release-$TAG .
docker rmi sea5kg/ctf01d:stage-release-latest
docker tag sea5kg/ctf01d:stage-release-$TAG sea5kg/ctf01d:stage-release-latest
15 changes: 0 additions & 15 deletions data_sample/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,11 @@ game:
basic_costs_stolen_flag_in_points: 1 # basic costs stolen (attack) flag in points for adaptive scoreboard
cost_defence_flag_in_points: 1.0 # cost defences flag in points

server:
# use storage which storage will be used, now possible values:
# mysql - use mysql database
# ram - (!not implemented yet) use just memory
# local - (!not implemented yet) use just memory
# postgres - (!not implemented yet) will be used postgre database
use_storage: mysql

scoreboard:
port: 8080 # http port for scoreboard
htmlfolder: "./html" # web page for scoreboard see index-template.html
random: no # If yes - will be random values in scoreboard

mysql_storage: # if server.use_storage is mysql
dbhost: "ctf01d_db"
dbport: 3306
dbname: "ctf01d"
dbuser: "ctf01d"
dbpass: "ctf01d"

checkers:
- id: "example_service1" # work directory will be checker_example_service4
service_name: "Service1"
Expand Down
Loading

0 comments on commit c5d7f23

Please sign in to comment.