diff --git a/Dockerfile b/Dockerfile index 1f98816..d1812bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM python:3 ARG OPERATION -RUN useradd -d /code xf RUN mkdir -p /code +RUN useradd -d /code xf RUN chown -R xf:xf /code RUN mkdir -p /conf/static @@ -16,7 +16,7 @@ USER xf ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 WORKDIR /code -COPY requirements.txt /code/ +COPY --chown=xf:xf requirements.txt /code/ RUN python -m venv /venv RUN . /venv/bin/activate && pip install -r requirements.txt @@ -25,4 +25,4 @@ RUN . /venv/bin/activate && pip install -r requirements.txt CMD if [ "$OPERATION" = "uwsgi" ] ; then . /venv/bin/activate && uwsgi --ini /conf/uwsgi.ini ; else . /venv/bin/activate && exec python manage.py runserver 0.0.0.0:8000; fi # CMD . /venv/bin/activate && uvicorn --reload --reload-include *.html --workers 2 --uds /var/run/socks/app.sock app.asgi:application -# CMD . /venv/bin/activate && gunicorn -b 0.0.0.0:8000 --reload app.asgi:application -k uvicorn.workers.UvicornWorker \ No newline at end of file +# CMD . /venv/bin/activate && gunicorn -b 0.0.0.0:8000 --reload app.asgi:application -k uvicorn.workers.UvicornWorker diff --git a/Makefile b/Makefile index 934ed54..731e83d 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,26 @@ run: - docker-compose --env-file=stack.env up -d + podman-compose --env-file=stack.env up -d build: - docker-compose --env-file=stack.env build + podman-compose --env-file=stack.env build stop: - docker-compose --env-file=stack.env down + podman-compose --env-file=stack.env down log: - docker-compose --env-file=stack.env logs -f + podman-compose --env-file=stack.env logs -f test: - docker-compose --env-file=stack.env run -e LIVE=$(LIVE) --rm app sh -c ". /venv/bin/activate && python manage.py test $(MODULES) -v 2" + podman-compose --env-file=stack.env run -e LIVE=$(LIVE) --rm app sh -c ". /venv/bin/activate && python manage.py test $(MODULES) -v 2" migrate: - docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py migrate" + podman-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py migrate" makemigrations: - docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py makemigrations" + podman-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py makemigrations" auth: - docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py createsuperuser" + podman-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py createsuperuser" token: - docker-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py addstatictoken m" + podman-compose --env-file=stack.env run --rm app sh -c ". /venv/bin/activate && python manage.py addstatictoken m" diff --git a/app/settings.py b/app/settings.py index efc08e0..dc5a49f 100644 --- a/app/settings.py +++ b/app/settings.py @@ -57,18 +57,20 @@ INSTALLED_APPS = [ ] -# Performance optimisations -CACHES = { - "default": { - "BACKEND": "django.core.cache.backends.redis.RedisCache", - "LOCATION": "unix:///var/run/socks/redis.sock", - "OPTIONS": { - "db": "10", - "parser_class": "redis.connection.HiredisParser", - "pool_class": "redis.BlockingConnectionPool", - }, - } -} +# Performance optimisations # COMMENTED DUE TO PODMAN ISSUE +# CACHES = { +# "default": { +# "BACKEND": "django.core.cache.backends.redis.RedisCache", +# "LOCATION": "unix:///var/run/socks/redis.sock", +# "OPTIONS": { +# "db": "10", +# "parser_class": "redis.connection.HiredisParser", +# "pool_class": "redis.BlockingConnectionPool", +# }, +# } +# } +# END PODMAN ISSUE + # CACHE_MIDDLEWARE_ALIAS = 'default' # CACHE_MIDDLEWARE_SECONDS = '600' # CACHE_MIDDLEWARE_KEY_PREFIX = '' diff --git a/core/__init__.py b/core/__init__.py index d1d0e50..32f77b6 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,14 +1,6 @@ import os -import stripe -from django.conf import settings - os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" # from redis import StrictRedis # r = StrictRedis(unix_socket_path="/var/run/redis/redis.sock", db=0) - -if settings.STRIPE_TEST: - stripe.api_key = settings.STRIPE_API_KEY_TEST -else: - stripe.api_key = settings.STRIPE_API_KEY_PROD diff --git a/core/lib/billing.py b/core/lib/billing.py index 282e65d..811a096 100644 --- a/core/lib/billing.py +++ b/core/lib/billing.py @@ -1,10 +1,16 @@ import stripe from django.conf import settings -from lago_python_client import Client -from lago_python_client.clients.base_client import LagoApiError + +# from lago_python_client import Client +from lago_python_client.client import Client +from lago_python_client.exceptions import LagoApiError from lago_python_client.models import Customer, CustomerBillingConfiguration client = Client(api_key=settings.LAGO_API_KEY, api_url=settings.LAGO_URL) +if settings.STRIPE_TEST: + stripe.api_key = settings.STRIPE_API_KEY_TEST +else: + stripe.api_key = settings.STRIPE_API_KEY_PROD def expand_name(first_name, last_name): diff --git a/core/trading/market.py b/core/trading/market.py index 2420edc..0282fd8 100644 --- a/core/trading/market.py +++ b/core/trading/market.py @@ -412,6 +412,7 @@ def execute_strategy(callback, strategy, func): direction=direction, **protection, ) + log.debug(f"Created Trade: {new_trade}") new_trade.save() if strategy.risk_model is not None: diff --git a/docker-compose.yml b/docker-compose.yml index e146517..f952f93 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,8 +17,8 @@ services: # - "8000:8000" # uwsgi socket env_file: - stack.env - volumes_from: - - tmp + # volumes_from: + # - tmp depends_on: # redis: # condition: service_healthy @@ -46,11 +46,11 @@ services: - fisk_static:${STATIC_ROOT} env_file: - stack.env - volumes_from: - - tmp + # volumes_from: + # - tmp depends_on: - redis: - condition: service_healthy + # redis: + # condition: service_healthy migration: condition: service_started collectstatic: @@ -72,8 +72,8 @@ services: - ${PORTAINER_GIT_DIR}:/code - ${APP_DATABASE_FILE}:/conf/db.sqlite3 - fisk_static:${STATIC_ROOT} - volumes_from: - - tmp + # volumes_from: + # - tmp env_file: - stack.env @@ -89,27 +89,27 @@ services: - ${PORTAINER_GIT_DIR}:/code - ${APP_DATABASE_FILE}:/conf/db.sqlite3 - fisk_static:${STATIC_ROOT} - volumes_from: - - tmp + # volumes_from: + # - tmp env_file: - stack.env nginx: - image: nginx:latest + image: nginxinc/nginx-unprivileged:latest container_name: nginx_fisk ports: - ${APP_PORT}:9999 - ulimits: - nproc: 65535 - nofile: - soft: 65535 - hard: 65535 + # ulimits: + # nproc: 65535 + # nofile: + # soft: 65535 + # hard: 65535 volumes: - ${PORTAINER_GIT_DIR}:/code - ${PORTAINER_GIT_DIR}/docker/nginx/conf.d/${OPERATION}.conf:/etc/nginx/conf.d/default.conf - fisk_static:${STATIC_ROOT} - volumes_from: - - tmp + # volumes_from: + # - tmp networks: - default - xf @@ -124,33 +124,36 @@ services: # redis: # condition: service_healthy - tmp: - image: busybox - container_name: tmp_fisk - command: chmod -R 777 /var/run/socks - volumes: - - /var/run/socks + # tmp: + # image: busybox + # container_name: tmp_fisk + # command: chmod -R 777 /var/run/socks + # volumes: + # - /var/run/socks - # For caching - redis: - image: redis - container_name: redis_fisk - command: redis-server /etc/redis.conf - ulimits: - nproc: 65535 - nofile: - soft: 65535 - hard: 65535 - volumes: - - ${PORTAINER_GIT_DIR}/docker/redis.conf:/etc/redis.conf - - fisk_redis_data:/data - volumes_from: - - tmp - healthcheck: - test: "redis-cli -s /var/run/socks/redis.sock ping" - interval: 2s - timeout: 2s - retries: 15 + # # For caching + # redis: + # image: redis + # container_name: redis_fisk + # command: redis-server /etc/redis.conf + # #ulimits: + # # nproc: 65535 + # # nofile: + # # soft: 65535 + # # hard: 65535 + # volumes: + # - ${PORTAINER_GIT_DIR}/docker/redis.conf:/etc/redis.conf + # - fisk_redis_data:/data + # volumes_from: + # - tmp + # healthcheck: + # test: "redis-cli -s /var/run/socks/redis.sock ping" + # interval: 2s + # timeout: 2s + # retries: 15 + # depends_on: + # tmp: + # condition: service_started # pyroscope: # image: "pyroscope/pyroscope:latest"