Add docker and sockets
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/docker-existing-dockerfile
|
||||
{
|
||||
"name": "Existing Dockerfile",
|
||||
|
||||
// Sets the run context to one level up instead of the .devcontainer folder.
|
||||
"context": "..",
|
||||
|
||||
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
|
||||
"dockerFile": "../Dockerfile",
|
||||
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": []
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Uncomment the next line to run commands after the container is created - for example installing curl.
|
||||
// "postCreateCommand": "apt-get update && apt-get install -y curl",
|
||||
|
||||
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
|
||||
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
|
||||
|
||||
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
|
||||
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
|
||||
|
||||
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
|
||||
// "remoteUser": "vscode"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
FROM python:3.8-slim-buster
|
||||
|
||||
WORKDIR /app
|
||||
RUN python3 -m venv venv
|
||||
RUN . venv/bin/activate
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
# Debug image reusing the base
|
||||
# Install dev dependencies for debugging
|
||||
RUN pip install debugpy
|
||||
# Keeps Python from generating .pyc files in the container
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
# Turns off buffering for easier container logging
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
COPY . .
|
||||
ENV FLASK_ENV=development
|
||||
# ENTRYPOINT ["python3"]
|
||||
CMD ["python3", "-m", "app"]
|
||||
# For start Jakub version run script
|
||||
# CMD ["python3", "-m", "flask", "run", "-h", "0.0.0.0", "-p", "5000" ]
|
||||
|
||||
# , "-m", "debugpy", "--listen", "0.0.0.0:5678", "-m", "app", "--wait-for-client", "--multiprocess",
|
||||
+18
-16
@@ -1,23 +1,25 @@
|
||||
import json
|
||||
import socket
|
||||
import string
|
||||
from flask_socketio import SocketIO, emit, disconnect, join_room
|
||||
from flask import session, copy_current_request_context
|
||||
from api.utils import get_points_sums, sort_card_list
|
||||
from bridzik import Bridzik, BridzikException, Card, Card_colors, Card_values
|
||||
from flask import Flask
|
||||
import os
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from config import Config
|
||||
from flask import request
|
||||
|
||||
async_mode = None
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
app.debug = True
|
||||
|
||||
if not app.debug:
|
||||
if not os.path.exists('logs'):
|
||||
os.mkdir('logs')
|
||||
file_handler = RotatingFileHandler('logs/bridzik_api.log', maxBytes=10240, backupCount=10)
|
||||
file_handler.setFormatter(logging.Formatter(
|
||||
'%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
|
||||
))
|
||||
file_handler.setLevel(logging.INFO)
|
||||
app.logger.addHandler(file_handler)
|
||||
app.config['SECRET_KEY'] = 'secret!'
|
||||
socket_ = SocketIO(app, cors_allowed_origins="*", async_mode='eventlet', logger=True, engineio_logger=True)
|
||||
|
||||
app.logger.setLevel(logging.INFO)
|
||||
app.logger.info('Bridzik_API startup')
|
||||
bridzikInstance = Bridzik()
|
||||
|
||||
from api import routes
|
||||
players = ['', '', '', '']
|
||||
|
||||
|
||||
|
||||
socket_.run(app, debug=True, host="0.0.0.0", port="5000" )
|
||||
|
||||
+11
-13
@@ -1,12 +1,10 @@
|
||||
from api import app
|
||||
from bridzik import Bridzik, Card, Card_colors, Card_values, BridzikException
|
||||
from api import app, bridzikInstance
|
||||
from bridzik import Card, Card_colors, Card_values, BridzikException
|
||||
import json
|
||||
from flask import render_template, url_for, flash, redirect
|
||||
from api.forms import GuessForm, PlayForm, AdminForm
|
||||
from api.utils import get_points_sums, sort_card_list
|
||||
|
||||
b = Bridzik()
|
||||
|
||||
players = [
|
||||
'Jakub',
|
||||
'Timo',
|
||||
@@ -16,21 +14,21 @@ players = [
|
||||
|
||||
@app.route('/bridzik_api/get_status/<id>')
|
||||
def get_status(id: int):
|
||||
return json.dumps(b.get_status(int(id)), cls=Card.JSONEncoder)
|
||||
return json.dumps(bridzikInstance.get_status(int(id)), cls=Card.JSONEncoder)
|
||||
|
||||
@app.route('/bridzik/<player>/status')
|
||||
def status(player):
|
||||
player = int(player)
|
||||
game_status = b.get_status(player)
|
||||
game_status = bridzikInstance.get_status(player)
|
||||
action = None
|
||||
form = None
|
||||
player_cards = sort_card_list(b.series[-1].get_last_round().player_cards[player])
|
||||
player_cards = sort_card_list(bridzikInstance.series[-1].get_last_round().player_cards[player])
|
||||
game_status['player_cards'] = [str(c) for c in player_cards]
|
||||
points_sums = get_points_sums(game_status['standings'])
|
||||
if b.is_completed() or b.series[-1].get_last_round().get_active_player() != player:
|
||||
if bridzikInstance.is_completed() or bridzikInstance.series[-1].get_last_round().get_active_player() != player:
|
||||
pass
|
||||
elif not b.series[-1].get_last_round().is_guessing_completed():
|
||||
form = GuessForm(max_guess= 8 - b.series[-1].get_last_round().round_number)
|
||||
elif not bridzikInstance.series[-1].get_last_round().is_guessing_completed():
|
||||
form = GuessForm(max_guess= 8 - bridzikInstance.series[-1].get_last_round().round_number)
|
||||
action = 'guess'
|
||||
else:
|
||||
form = PlayForm()
|
||||
@@ -46,7 +44,7 @@ def guess(player):
|
||||
player = int(player)
|
||||
form = GuessForm()
|
||||
try:
|
||||
b.add_player_guess(player, int(form.guess.data))
|
||||
bridzikInstance.add_player_guess(player, int(form.guess.data))
|
||||
except BridzikException:
|
||||
flash('Nie je možné zadať tip.')
|
||||
return redirect(url_for('status', player=player))
|
||||
@@ -54,7 +52,7 @@ def guess(player):
|
||||
@app.route('/bridzik/<player>/play_card', methods=['POST'])
|
||||
def play_card(player):
|
||||
player = int(player)
|
||||
player_cards = b.series[-1].get_last_round().player_cards[player]
|
||||
player_cards = bridzikInstance.series[-1].get_last_round().player_cards[player]
|
||||
form = PlayForm()
|
||||
form.card.choices = [(str(c), str(c)) for c in player_cards]
|
||||
color, value = form.card.data.split('_')
|
||||
@@ -64,7 +62,7 @@ def play_card(player):
|
||||
flash('Chyba. Opakuj pokus znovu.')
|
||||
|
||||
try:
|
||||
b.play_card(player, card)
|
||||
bridzikInstance.play_card(player, card)
|
||||
except BridzikException:
|
||||
flash('Nie je možné zahrať kartu.')
|
||||
return redirect(url_for('status', player=player))
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
version: "3.0"
|
||||
services:
|
||||
api:
|
||||
build: .
|
||||
ports:
|
||||
- "5000:5000"
|
||||
- "5678:5678"
|
||||
volumes:
|
||||
- ./:/app
|
||||
+12
-17
@@ -1,18 +1,13 @@
|
||||
astroid==2.3.3
|
||||
click==7.1.1
|
||||
colorama==0.4.3
|
||||
Flask==1.1.1
|
||||
Flask-WTF==0.14.3
|
||||
isort==4.3.21
|
||||
Flask==1.0.2
|
||||
Flask-Login==0.4.1
|
||||
Flask-Session==0.3.1
|
||||
Flask_SocketIO==4.0.0
|
||||
itsdangerous==1.1.0
|
||||
Jinja2==2.11.1
|
||||
lazy-object-proxy==1.4.3
|
||||
MarkupSafe==1.1.1
|
||||
mccabe==0.6.1
|
||||
pylint==2.4.4
|
||||
python-dotenv==0.12.0
|
||||
six==1.14.0
|
||||
typed-ast==1.4.1
|
||||
Werkzeug==1.0.0
|
||||
wrapt==1.11.2
|
||||
WTForms==2.2.1
|
||||
Jinja2==2.10
|
||||
MarkupSafe==1.1.0
|
||||
python-engineio==3.14.1
|
||||
python-socketio==4.4.0
|
||||
six==1.11.0
|
||||
Werkzeug==0.14.1
|
||||
Flask-Cors==3.0.7
|
||||
eventlet==0.19.0
|
||||
|
||||
Reference in New Issue
Block a user