Skip to content
Open
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
40 changes: 2 additions & 38 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: install-python
uses: actions/setup-python@v4
id: python
with:
python-version: "3.10"

- name: Build
run: make build.py_server
env:
python: ${{steps.python.outputs.python-path}}

- name: Test
run: make test.py_server
run: make test.docker.py_server

CPP:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- name: compiler-update
run: |
sudo apt update
sudo apt install -y g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 90
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 90
sudo apt install libzip-dev

- name: install-cpprest
run: sudo apt install libcpprest-dev

- name: install-boost
uses: MarkusJx/install-boost@v2.4.4
id: install-boost
with:
boost_version: 1.81.0
platform_version: 20.04

- name: Build
run: make build.server
env:
boost: ${{steps.install-boost.outputs.BOOST_ROOT}}

- name: Test
run: make test.server
env:
boost: ${{steps.install-boost.outputs.BOOST_ROOT}}
run: make test.docker.server
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
.PHONY: help build.% test.% clean
.PHONY: help docker build.% test.% clean
.DEFAULT_GOAL = help

targets = py_server server

export CONFIG_PATH = $(abspath config.json)

ifeq ($(shell which node),)
$(error 'node' not found, see README about node)
endif

clientPort = $(shell node -p "require('$(CONFIG_PATH)').client.PORT")
pythonPort = $(shell node -p "require('$(CONFIG_PATH)').py_server.PORT")
cppPort = $(shell node -p "require('$(CONFIG_PATH)').cpp_server.PORT")

MAKEFLAGS += -k
ifneq ($V,2)
# comment next line and Makefile will print what it's doing
Expand All @@ -20,6 +28,8 @@ Example (runs tests in py_server): make test.py_server V=2

Targets:
--------
docker: launches everything in 3 docker containers
test.docker: start docker containers, run tests in them and exit
run.client: starts the client
run.py_server: starts the py_server
run.server: starts the c++ server
Expand All @@ -46,6 +56,18 @@ help: export HELP := $(HELP)
help:
@echo "$$HELP"

docker: export WEBPORT=$(clientPort)
docker: export PYPORT=$(pythonPort)
docker: export CPORT=$(cppPort)
docker: compose.yml
docker compose up --build --remove-orphans

test.docker.py_server:
$(MAKE) docker -C py_server -e

test.docker.server:
$(MAKE) docker -C server -e

$(addprefix run.,py_server client): run.%:
$(MAKE) -C $* -e

Expand Down
3 changes: 3 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
package-lock.json
**/.DS_Store
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<script>
localStorage.clear()
// todo: Get it from json
localStorage.setItem("py_server_address", "localhost:3000")
localStorage.setItem("py_server_address", "0.0.0.0:3000")
window.location = "templates/authorization.html"
</script>
46 changes: 46 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: mlcraft

services:
web:
build:
context: client
dockerfile_inline: |
FROM node:21-alpine3.18
RUN apk add --update --no-cache make
WORKDIR /app
COPY . .
ports:
- ${WEBPORT}:${WEBPORT}
command: make
volumes:
- ${CONFIG_PATH}:/app/config.json
- ./client:/app
environment:
- CONFIG_PATH=/app/config.json
depends_on:
- pyServer

pyServer:
image: mlcraft/python
build: py_server
ports:
- ${PYPORT}:${PYPORT}
command: make
volumes:
- ${CONFIG_PATH}:/app/config.json
- ./py_server/instance/database.db:/app/instance/database.db
environment:
- CONFIG_PATH=/app/config.json
depends_on:
- cppServer

cppServer:
image: mlcraft/cpp
build: server
ports:
- ${CPORT}:${CPORT}
command: make serve V=2
volumes:
- ${CONFIG_PATH}:/app/config.json
environment:
- CONFIG_PATH=/app/config.json
6 changes: 3 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"client": {
"HOST": "localhost",
"HOST": "0.0.0.0",
"PORT": 2001
},

"py_server": {
"HOST": "localhost",
"HOST": "0.0.0.0",
"PORT": 3000,
"SECRET_KEY": "minecraft",
"SQLALCHEMY_DATABASE_URI": "sqlite:///database.db",
"SQLALCHEMY_TRACK_MODIFICATIONS": false
},

"cpp_server": {
"HOST": "localhost",
"HOST": "0.0.0.0",
"PORT": 2000,
"BOOST_ROOT": ""
}
Expand Down
34 changes: 34 additions & 0 deletions py_server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).

**/.DS_Store
**/__pycache__
**/.mypy_cache
**/.pytest_cache
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/install
LICENSE
README.md
18 changes: 18 additions & 0 deletions py_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1

FROM --platform=linux/amd64 node:21-alpine3.18

RUN apk add --update --no-cache make
RUN apk add --no-cache python3

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

EXPOSE ${PYPORT}

WORKDIR /app
COPY . .

ENV CONFIG_PATH=/app/config.json

CMD make build && make test
12 changes: 9 additions & 3 deletions py_server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ app = mlcraft
dirEnv = .venv
dirBin = $(dirEnv)/bin

.PHONY: help default build format test pytest typecheck formatcheck clean
.PHONY: help default docker build format test pytest typecheck formatcheck clean
.DEFAULT_GOAL = default

ifneq ($V,2)
Expand All @@ -22,7 +22,9 @@ $(error 'node' not found, see README about node)
endif

getField = $(shell node -p "require('$(CONFIG_PATH)').py_server.$1")
flags = -h $(call getField,HOST) -p $(call getField,PORT)
port = $(call getField,PORT)
host = $(call getField,HOST)
flags = -h $(host) -p $(port)

python = $(shell which 'python3.10' || which 'python3' || which 'python')
ifeq ("$(python)","")
Expand Down Expand Up @@ -57,6 +59,11 @@ default: install
@echo "---------------------------------------------------------------------------"
$(dirBin)/flask --app $(app) run --debug $(flags)

docker: export PYPORT := $(port)
docker: Dockerfile
docker build -t $(app)/python:test .
docker run -v $(CONFIG_PATH):/app/config.json $(app)/python:test

build: install

format: install
Expand All @@ -83,4 +90,3 @@ $(dirEnv):

clean:
$(RM) install
$(RM) -r instance
1 change: 1 addition & 0 deletions py_server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"black == 23.10.1",
"pytest == 7.4.2",
"mypy == 1.6.1",
"cython == 3.0.7",
"matplotlib == 3.8.2",
]

Expand Down
7 changes: 7 additions & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/.DS_Store
bin
Build
model_data
.cache
*.xcodeproj
*.entitlements
18 changes: 18 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1

FROM node:21-slim

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y build-essential
RUN apt install -y libboost-dev
RUN apt-get install -y libcpprest-dev
RUN apt-get install -y libx11-dev libpng-dev libzip-dev

EXPOSE ${CPORT}

WORKDIR /app
COPY . .

ENV CONFIG_PATH=/app/config.json

CMD make build && make test
12 changes: 11 additions & 1 deletion server/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
app = mlcraft
dirApi = api
dirCore = core
dirTests = tests
Expand Down Expand Up @@ -39,7 +40,7 @@ ifneq ($V,2)
.SILENT:
endif
.DEFAULT_GOAL = default
.PHONY: default serve test test.% clean checkboost
.PHONY: default docker serve test test.% clean checkboost

include $(wildcard $(dirBuild)/*.d)

Expand All @@ -60,6 +61,7 @@ help:
@echo
@echo "Available targets:"
@echo "default: builds and runs core/main.cpp file"
@echo "docker: tests application inside the docker container"
@echo "serve: builds and runs api/server.cpp file"
@echo "test: builds and runs all tests in the tests directory"
@echo "test.<object>: runs specific test, for example 'make test.Blob'"
Expand All @@ -80,6 +82,14 @@ help:
build: $(core) $(server) $(testTargets)


### DOCKER ###

docker: export CPORT := $(port)
docker: Dockerfile
docker build -t $(app)/cpp:test .
docker run -v $(CONFIG_PATH):/app/config.json $(app)/cpp:test


### CORE ###

coreFiles = $(wildcard $(dirCore)/*.cpp)
Expand Down