Compare commits
10 Commits
v0.1.25020
...
v0.3.25020
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e0af277fe | |||
| 6795697dea | |||
| 0397465ec3 | |||
| c7ca9f9442 | |||
| 9c6db02e57 | |||
| d6cd731a2a | |||
| ed4d845b12 | |||
| 96afac4789 | |||
| 50690f01cf | |||
| 64d0105d4a |
@@ -40,26 +40,16 @@ jobs:
|
|||||||
"email": "'$USERNAME'",
|
"email": "'$USERNAME'",
|
||||||
"password": "'$PASSWORD'"
|
"password": "'$PASSWORD'"
|
||||||
}' | jq -r '.token')
|
}' | jq -r '.token')
|
||||||
# curl --location --silent 'https://deployer.makecodes.dev/deploy' \
|
curl --location --silent 'https://deployer.makecodes.dev/deploy' \
|
||||||
# --header 'Content-Type: application/json' \
|
--header 'Content-Type: application/json' \
|
||||||
# --header "Authorization: Bearer $TOKEN" \
|
--header "Authorization: Bearer $TOKEN" \
|
||||||
# --data '{
|
--data '{
|
||||||
# "image": "docker.nexus.makecodes.dev/makecodes/nfe-vision",
|
"image": "docker.nexus.makecodes.dev/mines/backend",
|
||||||
# "service": "nfe-vision_app",
|
"service": "mines_backend",
|
||||||
# "version": "${{ github.ref_name }}",
|
"version": "${{ github.ref_name }}",
|
||||||
# "pipeline": "${{ github.run_number }}",
|
"pipeline": "${{ github.run_number }}",
|
||||||
# "repository": "makecodes/nfe-vision"
|
"repository": "mines/backend"
|
||||||
# }'
|
}'
|
||||||
# curl --location --silent 'https://deployer.makecodes.dev/deploy' \
|
|
||||||
# --header 'Content-Type: application/json' \
|
|
||||||
# --header "Authorization: Bearer $TOKEN" \
|
|
||||||
# --data '{
|
|
||||||
# "image": "docker.nexus.makecodes.dev/makecodes/nfe-vision",
|
|
||||||
# "service": "nfe-vision_worker",
|
|
||||||
# "version": "${{ github.ref_name }}",
|
|
||||||
# "pipeline": "${{ github.run_number }}",
|
|
||||||
# "repository": "makecodes/nfe-vision"
|
|
||||||
# }'
|
|
||||||
env:
|
env:
|
||||||
USERNAME: ${{ secrets.SERVER_AUTH_USERNAME }}
|
USERNAME: ${{ secrets.SERVER_AUTH_USERNAME }}
|
||||||
PASSWORD: ${{ secrets.SERVER_AUTH_PASSWORD }}
|
PASSWORD: ${{ secrets.SERVER_AUTH_PASSWORD }}
|
||||||
|
|||||||
84
Dockerfile
84
Dockerfile
@@ -1,52 +1,72 @@
|
|||||||
FROM python:3.8-slim-buster
|
FROM python:3.12.6-bullseye AS base
|
||||||
|
|
||||||
ARG SCOPE
|
ARG APP_USER \
|
||||||
|
APP_GROUP \
|
||||||
|
UID \
|
||||||
|
GID \
|
||||||
|
NEXUS_USERNAME \
|
||||||
|
NEXUS_PASSWORD
|
||||||
|
|
||||||
# Setup env
|
ENV APP_USER=${APP_USER:-mines} \
|
||||||
ENV SCOPE=${SCOPE} \
|
APP_GROUP=${APP_GROUP:-mines} \
|
||||||
# python
|
UID=${UID:-1000} \
|
||||||
PYTHONDONTWRITEBYTECODE=1 \
|
GID=${GID:-1000} \
|
||||||
PYTHONFAULTHANDLER=1 \
|
PYTHONFAULTHANDLER=1 \
|
||||||
PYTHONUNBUFFERED=1 \
|
PYTHONUNBUFFERED=1 \
|
||||||
PYTHONHASHSEED=random \
|
PYTHONHASHSEED=random \
|
||||||
|
PYTHONDONTWRITEBYTECODE=1 \
|
||||||
LC_ALL=C.UTF-8 \
|
LC_ALL=C.UTF-8 \
|
||||||
LANG=C.UTF-8 \
|
LANG=C.UTF-8 \
|
||||||
# pip
|
|
||||||
PIP_NO_CACHE_DIR=off \
|
PIP_NO_CACHE_DIR=off \
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
||||||
PIP_DEFAULT_TIMEOUT=100 \
|
PIP_DEFAULT_TIMEOUT=100 \
|
||||||
# poetry:
|
UV_LINK_MODE=copy \
|
||||||
POETRY_VERSION=1.1.13 \
|
UV_PROJECT_ENVIRONMENT=/.venv \
|
||||||
POETRY_NO_INTERACTION=1 \
|
VIRTUAL_ENV=/.venv \
|
||||||
POETRY_VIRTUALENVS_CREATE=false \
|
PATH="/.venv/bin:$PATH"
|
||||||
POETRY_CACHE_DIR='/var/cache/pypoetry' \
|
|
||||||
POETRY_HOME='/usr/local'
|
|
||||||
|
|
||||||
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
||||||
|
|
||||||
RUN apt-get update && apt-get upgrade -y \
|
WORKDIR /app
|
||||||
&& apt-get install --no-install-recommends -y \
|
|
||||||
|
COPY uv.lock pyproject.toml ./
|
||||||
|
|
||||||
|
# Dependências
|
||||||
|
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
|
||||||
|
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y \
|
||||||
bash \
|
bash \
|
||||||
curl \
|
clang \
|
||||||
build-essential \
|
build-essential \
|
||||||
|
curl \
|
||||||
default-libmysqlclient-dev \
|
default-libmysqlclient-dev \
|
||||||
|
gnupg \
|
||||||
|
jq \
|
||||||
|
libc6 \
|
||||||
|
libffi-dev \
|
||||||
|
libjpeg-dev \
|
||||||
|
libmariadb-dev \
|
||||||
libpq-dev \
|
libpq-dev \
|
||||||
# Installing `poetry` package manager:
|
libpthread-stubs0-dev \
|
||||||
# https://github.com/python-poetry/poetry
|
libxml2-dev \
|
||||||
&& curl -sSL 'https://install.python-poetry.org' | python - \
|
libxslt-dev \
|
||||||
&& poetry --version \
|
mariadb-client \
|
||||||
# Cleaning cache:
|
zlib1g-dev && \
|
||||||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
apt-get install -y --no-install-recommends gcc && \
|
||||||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
|
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
|
||||||
|
apt-get clean -y && rm -rf /var/lib/apt/lists/* && \
|
||||||
|
uv sync --dev && \
|
||||||
|
uv cache clean && \
|
||||||
|
. $VIRTUAL_ENV/bin/activate
|
||||||
|
|
||||||
# Copy only requirements to cache them in docker layer
|
|
||||||
WORKDIR /code
|
|
||||||
COPY poetry.lock pyproject.toml /code/
|
|
||||||
|
|
||||||
RUN poetry config virtualenvs.create false \
|
# Copia o restante do código da aplicação
|
||||||
&& poetry install $(test "$SCOPE" == production && echo "--no-dev") --no-interaction --no-ansi
|
COPY . /app
|
||||||
|
|
||||||
# Creating folders, and files for a project:
|
RUN groupadd -r $APP_GROUP -g $GID && \
|
||||||
COPY . /code
|
useradd -r -g $APP_GROUP -u $UID $APP_USER --shell /bin/bash --home /app
|
||||||
|
|
||||||
CMD ["/code/commands/run-prod.sh"]
|
USER $APP_USER
|
||||||
|
|
||||||
|
CMD ["/app/commands/run-prod.sh"]
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ class GameEventResource(APIView):
|
|||||||
|
|
||||||
def post(self, request, game_id):
|
def post(self, request, game_id):
|
||||||
"""Creates a new event"""
|
"""Creates a new event"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
game = Game.objects.get(pk=game_id)
|
game = Game.objects.get(pk=game_id)
|
||||||
except Game.DoesNotExist:
|
except Game.DoesNotExist:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ OP_ITEM_TITLE = os.environ.get('OP_ITEM_TITLE', 'mines')
|
|||||||
op_env = OnePassword(SCOPE, OP_ITEM_TITLE)
|
op_env = OnePassword(SCOPE, OP_ITEM_TITLE)
|
||||||
|
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
dsn=op_env.get('settings.SENTRY_DSN'),
|
dsn=op_env.get('SENTRY_DSN'),
|
||||||
integrations=[DjangoIntegration()],
|
integrations=[DjangoIntegration()],
|
||||||
environment=SCOPE,
|
environment=SCOPE,
|
||||||
send_default_pii=False,
|
send_default_pii=False,
|
||||||
@@ -23,12 +23,12 @@ sentry_sdk.init(
|
|||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = op_env.get('settings.SECRET_KEY')
|
SECRET_KEY = op_env.get('SECRET_KEY')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = op_env.get('settings.DEBUG', '0') in ['1', 'true']
|
DEBUG = op_env.get('DEBUG', '0') in ['1', 'true']
|
||||||
|
|
||||||
ALLOWED_HOSTS = op_env.get('settings.ALLOWED_HOSTS', '127.0.0.1,localhost').split(',')
|
ALLOWED_HOSTS = op_env.get('ALLOWED_HOSTS', '127.0.0.1,localhost').split(',')
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
@@ -131,8 +131,7 @@ REST_FRAMEWORK = {
|
|||||||
'DEFAULT_RENDERER_CLASSES': ('rest_framework.renderers.JSONRenderer',),
|
'DEFAULT_RENDERER_CLASSES': ('rest_framework.renderers.JSONRenderer',),
|
||||||
}
|
}
|
||||||
|
|
||||||
if DEBUG is True:
|
CORS_ALLOW_ALL_ORIGINS = True
|
||||||
CORS_ALLOW_ALL_ORIGINS = True
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
from django.conf import settings
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('api.urls')),
|
path('', include('api.urls')),
|
||||||
]
|
|
||||||
|
|
||||||
# We need this only for development purpose
|
|
||||||
if settings.DEBUG is True:
|
|
||||||
urlpatterns += [
|
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|||||||
25
app/utils.py
25
app/utils.py
@@ -1,25 +0,0 @@
|
|||||||
import onepasswordconnectsdk
|
|
||||||
from onepasswordconnectsdk.client import Client, new_client_from_environment
|
|
||||||
|
|
||||||
|
|
||||||
def get_op_config():
|
|
||||||
op_client: Client = new_client_from_environment()
|
|
||||||
|
|
||||||
OP_DJANGO_SETTINGS_VARS = [
|
|
||||||
'database.host',
|
|
||||||
'database.port',
|
|
||||||
'database.name',
|
|
||||||
'database.user',
|
|
||||||
'database.password',
|
|
||||||
'settings.ALLOWED_HOSTS',
|
|
||||||
'settings.DEBUG',
|
|
||||||
'settings.SCOPE',
|
|
||||||
'settings.SENTRY_DSN',
|
|
||||||
'settings.SECRET_KEY',
|
|
||||||
]
|
|
||||||
|
|
||||||
op_config_get = {}
|
|
||||||
for var in OP_DJANGO_SETTINGS_VARS:
|
|
||||||
op_config_get[var] = {'opitem': 'mines', 'opfield': var}
|
|
||||||
|
|
||||||
return onepasswordconnectsdk.load_dict(op_client, op_config_get)
|
|
||||||
@@ -7,4 +7,4 @@ class GameConfig(AppConfig):
|
|||||||
verbose_name_plural = 'Games'
|
verbose_name_plural = 'Games'
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
pass
|
from game import signals # noqa
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from .models import EventTypes, Game, GameEvent, GameStatuses
|
|||||||
@receiver(post_save, sender=Game)
|
@receiver(post_save, sender=Game)
|
||||||
def game_start(sender, signal, instance, **kwargs):
|
def game_start(sender, signal, instance, **kwargs):
|
||||||
"""If the game was just created, insert the first event START_GAME"""
|
"""If the game was just created, insert the first event START_GAME"""
|
||||||
if not instance.status == GameStatuses.NOT_PLAYED:
|
if instance.status != GameStatuses.NOT_PLAYED:
|
||||||
return
|
return
|
||||||
GameEvent.objects.get_or_create(game=instance, type=EventTypes.START_GAME)
|
GameEvent.objects.get_or_create(game=instance, type=EventTypes.START_GAME)
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ def game_start(sender, signal, instance, **kwargs):
|
|||||||
@receiver(pre_save, sender=GameEvent)
|
@receiver(pre_save, sender=GameEvent)
|
||||||
def identify_click_event(sender, signal, instance, **kwargs):
|
def identify_click_event(sender, signal, instance, **kwargs):
|
||||||
"""Verify what is on the naive click: mine, point or empty"""
|
"""Verify what is on the naive click: mine, point or empty"""
|
||||||
if not instance.type == EventTypes.CLICK_NAIVE:
|
if instance.type != EventTypes.CLICK_NAIVE:
|
||||||
return
|
return
|
||||||
|
|
||||||
if instance.row is None and instance.col is None:
|
if instance.row is None and instance.col is None:
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ lint.ignore = [
|
|||||||
"RUF012",
|
"RUF012",
|
||||||
"N806",
|
"N806",
|
||||||
"ARG002",
|
"ARG002",
|
||||||
|
"PGH004",
|
||||||
"N805", # Missing type annotation for self in method (Pydantic don't like this)
|
"N805", # Missing type annotation for self in method (Pydantic don't like this)
|
||||||
"SIM108", # Use ternary operator {contents} instead of if-else-block
|
"SIM108", # Use ternary operator {contents} instead of if-else-block
|
||||||
"RUF009", # Missing dataclass field.
|
"RUF009", # Missing dataclass field.
|
||||||
|
|||||||
Reference in New Issue
Block a user