From bf65ef88e5aba1b24230e6fa42657a74eb9e41cd Mon Sep 17 00:00:00 2001 From: ldamasio Date: Sun, 20 Aug 2023 18:01:30 -0300 Subject: [PATCH] Test workflow --- .gitignore | 2 + README.md | 7 +- backends/monolith/.gitignore | 1 + .../{settings.py => settings/common.py} | 15 ++- .../monolith/backend/settings/development.py | 1 + .../monolith/backend/settings/production.py | 3 + backends/monolith/backend/wsgi.py | 2 +- backends/monolith/manage.py | 2 +- backends/monolith/requirements-dev.txt | 91 +++++++++++++++++++ backends/monolith/requirements.txt | 14 ++- docker-compose.yml | 42 +++++++-- dump/Dockerfile | 10 ++ dump/rocketry/backup.sh | 0 dump/rocketry/dump.sh | 3 + dump/rocketry/main.py | 30 ++++++ 15 files changed, 198 insertions(+), 25 deletions(-) create mode 100644 backends/monolith/.gitignore rename backends/monolith/backend/{settings.py => settings/common.py} (92%) create mode 100644 backends/monolith/backend/settings/development.py create mode 100644 backends/monolith/backend/settings/production.py create mode 100644 backends/monolith/requirements-dev.txt create mode 100644 dump/Dockerfile create mode 100644 dump/rocketry/backup.sh create mode 100644 dump/rocketry/dump.sh create mode 100644 dump/rocketry/main.py diff --git a/.gitignore b/.gitignore index cb10a497..58632152 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ **/.env **/node_modules/ **/__pycache__ +**/venv +**/.venv # Logs logs diff --git a/README.md b/README.md index c2661299..7b90e20c 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,9 @@ The command interface makes it possible to activate a Dashboard with its main in ## The Dashboard offers special string conversion calculators. -For example, if you need to withdraw an amount of BRL, but would like to convert your USDT to ADA before transferring, in addition to needing to anticipate spread values from other financial services. \ No newline at end of file +For example, if you need to withdraw an amount of BRL, but would like to convert your USDT to ADA before transferring, in addition to needing to anticipate spread values from other financial services. + +## Development Environment + +In wsgi.py and manage.py "backend.settings" was changed to "backend.settings.development" + diff --git a/backends/monolith/.gitignore b/backends/monolith/.gitignore new file mode 100644 index 00000000..b694934f --- /dev/null +++ b/backends/monolith/.gitignore @@ -0,0 +1 @@ +.venv \ No newline at end of file diff --git a/backends/monolith/backend/settings.py b/backends/monolith/backend/settings/common.py similarity index 92% rename from backends/monolith/backend/settings.py rename to backends/monolith/backend/settings/common.py index 2c13977c..4001ac99 100644 --- a/backends/monolith/backend/settings.py +++ b/backends/monolith/backend/settings/common.py @@ -8,7 +8,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent -SECRET_KEY = 'django-insecure-2mmpn-2t!ik^g__ixmq3jt0gbel26-faatssu2&9$4m)(xe77^' +SECRET_KEY = config("SECRET_KEY") DEBUG = True @@ -59,17 +59,16 @@ WSGI_APPLICATION = 'backend.wsgi.application' - # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'rbs', - 'USER': 'ldamasio', - 'PASSWORD': 'admin', - 'HOST': 'leandrodamasio.com.br', - 'PORT': 5432, + 'NAME': config("PG_DATABASE"), + 'USER': config("PG_USER"), + 'PASSWORD': config("PG_PASSWORD"), + 'HOST': config("PG_HOST"), + 'PORT': config("PG_PORT"), } } @@ -90,7 +89,6 @@ }, ] - # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ @@ -102,7 +100,6 @@ USE_TZ = True - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.1/howto/static-files/ diff --git a/backends/monolith/backend/settings/development.py b/backends/monolith/backend/settings/development.py new file mode 100644 index 00000000..590135ad --- /dev/null +++ b/backends/monolith/backend/settings/development.py @@ -0,0 +1 @@ +from backend.settings.common import * \ No newline at end of file diff --git a/backends/monolith/backend/settings/production.py b/backends/monolith/backend/settings/production.py new file mode 100644 index 00000000..092b444e --- /dev/null +++ b/backends/monolith/backend/settings/production.py @@ -0,0 +1,3 @@ +from backend.settings.common import * + +DEBUG = False diff --git a/backends/monolith/backend/wsgi.py b/backends/monolith/backend/wsgi.py index ee71d551..490f2069 100644 --- a/backends/monolith/backend/wsgi.py +++ b/backends/monolith/backend/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.development') application = get_wsgi_application() diff --git a/backends/monolith/manage.py b/backends/monolith/manage.py index 07338392..1ca034f6 100755 --- a/backends/monolith/manage.py +++ b/backends/monolith/manage.py @@ -5,7 +5,7 @@ def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.development') try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/backends/monolith/requirements-dev.txt b/backends/monolith/requirements-dev.txt new file mode 100644 index 00000000..26b349d5 --- /dev/null +++ b/backends/monolith/requirements-dev.txt @@ -0,0 +1,91 @@ +aiohttp==3.8.3 +aiosignal==1.2.0 +asgiref==3.5.2 +async-timeout==4.0.2 +attrs==19.3.0 +Automat==0.8.0 +blinker==1.4 +certifi==2019.11.28 +cffi==1.15.1 +chardet==3.0.4 +charset-normalizer==2.1.1 +Click==7.0 +colorama==0.4.3 +configobj==5.0.6 +constantly==15.1.0 +cryptography==2.8 +dateparser==1.1.1 +distro==1.4.0 +Django==4.1.10 +django-cors-headers==4.2.0 +django-multitenant==3.2.1 +djangorestframework==3.14.0 +djangorestframework-jwt==1.11.0 +djangorestframework-simplejwt==5.2.2 +entrypoints==0.3 +frozenlist==1.3.1 +gevent==22.10.1 +greenlet==1.1.3 +gunicorn==20.1.0 +httplib2==0.14.0 +hyperlink==19.0.0 +idna==2.8 +importlib-metadata==1.5.0 +incremental==16.10.1 +Jinja2==2.10.1 +jsonpatch==1.22 +jsonpointer==2.0 +jsonschema==3.2.0 +keyring==18.0.1 +launchpadlib==1.11.0 +lazr.restfulclient==0.14.2 +lazr.uri==1.0.3 +MarkupSafe==1.1.0 +more-itertools==4.2.0 +multidict==6.0.2 +netifaces==0.10.4 +numpy==1.23.3 +oauthlib==3.1.0 +pandas==1.5.0 +pbr==5.10.0 +pexpect==4.6.0 +psycopg2-binary==2.9.7 +ptyprocess==0.7.0 +pyasn1==0.4.2 +pyasn1-modules==0.2.1 +pycparser==2.21 +PyHamcrest==1.9.0 +pyinotify==0.9.6 +PyJWT==1.7.1 +pymacaroons==0.13.0 +PyNaCl==1.3.0 +pyOpenSSL==19.0.0 +pyrsistent==0.15.5 +pyserial==3.4 +python-binance==1.0.16 +python-dateutil==2.8.2 +python-decouple==3.6 +pytz==2022.4 +pytz-deprecation-shim==0.1.0.post0 +PyYAML==5.3.1 +regex==2022.3.2 +requests==2.22.0 +requests-unixsocket==0.2.0 +SecretStorage==2.3.1 +service-identity==18.1.0 +simplejson==3.16.0 +six==1.14.0 +sqlparse==0.4.2 +ssh-import-id==5.10 +testresources==2.0.1 +Twisted==21.2.0 +tzdata==2022.4 +tzlocal==4.2 +ujson==5.5.0 +urllib3==1.25.8 +wadllib==1.3.3 +websockets==10.3 +yarl==1.8.1 +zipp==1.0.0 +zope.event==4.5.0 +zope.interface==5.4.0 diff --git a/backends/monolith/requirements.txt b/backends/monolith/requirements.txt index e13c4f63..ed0f6bda 100644 --- a/backends/monolith/requirements.txt +++ b/backends/monolith/requirements.txt @@ -18,10 +18,14 @@ dateparser==1.1.1 distro==1.4.0 django django-cors-headers +djangorestframework +djangorestframework-jwt +djangorestframework-simplejwt +django-multitenant entrypoints==0.3 frozenlist==1.3.1 -gevent==21.12.0 -greenlet==1.1.2 +gevent +greenlet==1.1.3 gunicorn==20.1.0 httplib2==0.14.0 hyperlink==19.0.0 @@ -33,7 +37,7 @@ jsonpatch==1.22 jsonpointer==2.0 jsonschema==3.2.0 keyring==18.0.1 -launchpadlib==1.10.13 +launchpadlib lazr.restfulclient==0.14.2 lazr.uri==1.0.3 MarkupSafe==1.1.0 @@ -45,7 +49,7 @@ oauthlib==3.1.0 pandas==1.5.0 pbr==5.10.0 pexpect==4.6.0 -psycopg2-binary==2.9.4 +psycopg2-binary ptyprocess==0.7.0 pyasn1==0.4.2 pyasn1-modules==0.2.1 @@ -74,7 +78,7 @@ six==1.14.0 sqlparse==0.4.2 ssh-import-id==5.10 testresources==2.0.1 -Twisted==18.9.0 +Twisted tzdata==2022.4 tzlocal==4.2 ujson==5.5.0 diff --git a/docker-compose.yml b/docker-compose.yml index 226d399d..0684492e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,32 @@ version: "3" services: + robsondb: + container_name: robsonDatabase + image: citusdata/citus + environment: + POSTGRES_USER: 'postgres' + POSTGRES_PASSWORD: 'mypass' + POSTGRES_DB: 'postgres' + # volumes: + # - pgdata:${PG_DATA} + ports: + - 5450:5432 + restart: always + + # cronjob: + # container_name: dump + # build: ./dump + # environment: + # PG_HOST: ${PG_HOST} + # POSTGRES_USER: ${PG_USER} + # POSTGRES_PASSWORD: ${PG_PASSWORD} + # POSTGRES_DB: ${PG_DATABASE} + # PGDATA: ${PG_DATA} + # PGPORT: ${PG_PORT} + # restart: always + backend-monolith: - container_name: RbsBackendMonolith + container_name: backendMonolith image: backend-monolith build: ./backends/monolith volumes: @@ -9,24 +34,25 @@ services: restart: always frontend-web: - container_name: RbsFrontendWeb + container_name: frontendWeb image: frontend-web build: ./frontends/web - ports: - - 3403:3403 volumes: - ./frontends/web:/app-frontend + ports: + - 3403:3403 depends_on: - backend-monolith restart: always nginx_backend_server: - container_name: rbs_nginx_backend_server - image: rbs_nginx_backend_server_img + depends_on: + - backend-monolith + container_name: nginxMonolith build: ./backends/nginx_monolith ports: - 8403:8403 - depends_on: - - backend-monolith restart: always +volumes: + pgdata: \ No newline at end of file diff --git a/dump/Dockerfile b/dump/Dockerfile new file mode 100644 index 00000000..521ef1f2 --- /dev/null +++ b/dump/Dockerfile @@ -0,0 +1,10 @@ +FROM ubuntu:latest +RUN apt-get update; apt-get install -y postgresql-client python3 python3-pip +WORKDIR /app +ENV TZ=America/Sao_Paulo +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +RUN pip3 install rocketry +COPY ./rocketry/main.py /app/rocketry/main.py +COPY ./rocketry/dump.sh /app/rocketry/dump.sh +COPY ./rocketry/backup.sh /app/rocketry/backup.sh +CMD ["python3", "/app/rocketry/main.py"] diff --git a/dump/rocketry/backup.sh b/dump/rocketry/backup.sh new file mode 100644 index 00000000..e69de29b diff --git a/dump/rocketry/dump.sh b/dump/rocketry/dump.sh new file mode 100644 index 00000000..d878894c --- /dev/null +++ b/dump/rocketry/dump.sh @@ -0,0 +1,3 @@ +filepath=/app/$(date +%F_%H-%M-%S).sql +pg_dump -Fc --host=$PG_HOST --port=$PG_PORT --username=$PG_USER --password=$PG_PASSWORD --dbname=$PG_DBNAME -f filename +cp $filepath /app/pg-dump.sql diff --git a/dump/rocketry/main.py b/dump/rocketry/main.py new file mode 100644 index 00000000..6b8e38c8 --- /dev/null +++ b/dump/rocketry/main.py @@ -0,0 +1,30 @@ +from rocketry import Rocketry +from rocketry.conds import after_success, after_fail, after_finish +from rocketry.log import MinimalRecord +from redbird.repos import CSVFileRepo +import subprocess + +repo = CSVFileRepo(filename="tasks.csv", model=MinimalRecord) + +app = Rocketry(logger_repo=repo) + +@app.task('daily') +def job(): + print ("Running a cronjob...") + subprocess.call(['sh', '/app/rocketry/dump.sh']) + return(True) + +@app.task(after_success(job)) +def do_after_success(): + print ("Trying to backup...") + subprocess.call(['sh', '/app/rocketry/backup.sh']) + +@app.task(after_fail(job)) +def do_after_fail(): + print(False) + +@app.task(after_finish(job)) +def do_after_fail_or_success(): + print ("Backup done") + +app.run() \ No newline at end of file