@@ -0,0 +1,34 | |||||
|
1 | import psycopg2 | |||
|
2 | import sys | |||
|
3 | import os | |||
|
4 | ||||
|
5 | RETRY = 5 | |||
|
6 | ||||
|
7 | def check_db_connection(retry=None): | |||
|
8 | ||||
|
9 | print('[prerun] Start check_db_connection...') | |||
|
10 | ||||
|
11 | if retry is None: | |||
|
12 | retry = RETRY | |||
|
13 | elif retry == 0: | |||
|
14 | print('[prerun] Giving up after 5 tries...') | |||
|
15 | sys.exit(1) | |||
|
16 | ||||
|
17 | try: | |||
|
18 | connection = psycopg2.connect(user=os.environ.get('DB_USER', 'localhost'), | |||
|
19 | host=os.environ.get('POSTGRES_PORT_5432_TCP_ADDR', '5432'), | |||
|
20 | password=os.environ.get('DB_PASSWORD', 'docker'), | |||
|
21 | database=os.environ.get('DB_NAME', 'radarsys')) | |||
|
22 | print('[prerun] Database is ready to accept connections') | |||
|
23 | ||||
|
24 | except psycopg2.Error as e: | |||
|
25 | print((str(e))) | |||
|
26 | print('[prerun] Unable to connect to the database...try again in a while.') | |||
|
27 | import time | |||
|
28 | time.sleep(10) | |||
|
29 | check_db_connection(retry = retry - 1) | |||
|
30 | else: | |||
|
31 | connection.close() | |||
|
32 | ||||
|
33 | if __name__ == '__main__': | |||
|
34 | check_db_connection() No newline at end of file |
@@ -1,11 +1,11 | |||||
1 | #General settings |
|
1 | #General settings | |
2 | LC_ALL=C.UTF-8 |
|
2 | LC_ALL=C.UTF-8 | |
3 | SIRM_SITE=10.10.10.30 |
|
3 | SIRM_SITE=<SIRM SITE> | |
4 | SIRM_PORT=8085 |
|
4 | SIRM_PORT=<SIRM PORT> | |
5 |
SIRM_MAX_UPLOAD_SIZE_MB=20 |
|
5 | SIRM_MAX_UPLOAD_SIZE_MB=20 | |
6 |
|
6 | |||
7 | #Postgres settings |
|
7 | #Postgres settings | |
8 |
POSTGRES_PORT_5432_TCP_ADDR= |
|
8 | POSTGRES_PORT_5432_TCP_ADDR=sirm-postgres | |
9 | POSTGRES_PORT_5432_TCP_PORT=5432 |
|
9 | POSTGRES_PORT_5432_TCP_PORT=5432 | |
10 | DB_NAME=radarsys |
|
10 | DB_NAME=radarsys | |
11 | DB_USER=docker |
|
11 | DB_USER=docker |
@@ -5,6 +5,4 volumes/sirm/static_files/* | |||||
5 | migrations |
|
5 | migrations | |
6 | *.pyc |
|
6 | *.pyc | |
7 | *initial.py |
|
7 | *initial.py | |
8 | .DS_Store |
|
8 | .DS_Store No newline at end of file | |
9 | *.sqlite |
|
|||
10 | .env No newline at end of file |
|
@@ -4,9 +4,9 FROM python:3.8-slim | |||||
4 | RUN mkdir -p /workspace/sirm |
|
4 | RUN mkdir -p /workspace/sirm | |
5 | WORKDIR /workspace |
|
5 | WORKDIR /workspace | |
6 |
|
6 | |||
7 |
# Copy "s |
|
7 | # Copy "setup" files | |
8 | ADD ./setup/start_realtime.sh ./start_realtime.sh |
|
8 | COPY ./setup/ ./setup/ | |
9 | RUN chmod +x ./start_realtime.sh |
|
9 | RUN chmod +x ./setup/start_realtime.sh | |
10 |
|
10 | |||
11 | # Set working directory |
|
11 | # Set working directory | |
12 | WORKDIR /workspace/sirm |
|
12 | WORKDIR /workspace/sirm | |
@@ -17,4 +17,4 RUN pip install -v --timeout 120 -r requirements.txt --no-cache-dir | |||||
17 |
|
17 | |||
18 | EXPOSE 8080 |
|
18 | EXPOSE 8080 | |
19 |
|
19 | |||
20 | ENTRYPOINT ["/workspace/start_realtime.sh"] No newline at end of file |
|
20 | ENTRYPOINT ["/workspace/setup/start_realtime.sh"] No newline at end of file |
@@ -20,10 +20,11 Download the application *radarsys_met* to your workspace | |||||
20 | ### 2. Config <code>.env</code> file |
|
20 | ### 2. Config <code>.env</code> file | |
21 |
|
21 | |||
22 | Update enviroment vars (/path/to/radarsys_met/.env) |
|
22 | Update enviroment vars (/path/to/radarsys_met/.env) | |
|
23 | ||||
23 | #General settings |
|
24 | #General settings | |
24 | SIRM_SITE=localhost |
|
25 | SIRM_SITE=<SIRM SITE> | |
25 |
SIRM_PORT= |
|
26 | SIRM_PORT=<SIRM PORT> | |
26 |
SIRM_MAX_UPLOAD_SIZE_MB=20 |
|
27 | SIRM_MAX_UPLOAD_SIZE_MB=20 | |
27 |
|
28 | |||
28 | #Postgres settings |
|
29 | #Postgres settings | |
29 | DB_NAME=radarsys |
|
30 | DB_NAME=radarsys |
@@ -1,7 +1,15 | |||||
1 | Django |
|
1 | Django==4.0.3 | |
2 | django-bootstrap4 |
|
2 | django-bootstrap4==22.1 | |
3 | psycopg2-binary |
|
3 | psycopg2-binary==2.9.3 | |
4 | django-polymorphic |
|
4 | django-polymorphic==3.1.0 | |
5 | gunicorn |
|
5 | gunicorn==20.1.0 | |
6 | requests |
|
6 | requests==2.27.1 | |
7 |
|
7 | backports.zoneinfo==0.2.1 | ||
|
8 | asgiref==3.5.0 | |||
|
9 | sqlparse==0.4.2 | |||
|
10 | beautifulsoup4==4.10.0 | |||
|
11 | idna==3.3 | |||
|
12 | urllib3==1.26.9 | |||
|
13 | charset-normalizer==2.0.12 | |||
|
14 | certifi==2021.10.8 | |||
|
15 | soupsieve==2.3.1 No newline at end of file |
@@ -1,8 +1,10 | |||||
1 | #!/bin/bash |
|
1 | #!/bin/bash | |
2 |
|
2 | |||
3 | if [ -f /sirm/radarsys.sqlite ]; |
|
3 | python ../setup/prerun.py || { echo '[DJANGO prerun] FAILED. Exiting...' ; exit 1; } | |
|
4 | ||||
|
5 | if [ -f ../setup/.gitkeep ]; | |||
4 | then |
|
6 | then | |
5 |
echo "The commands 'makemigrations', 'migrate' and ' |
|
7 | echo "The commands 'makemigrations', 'migrate' and '.gitkeep' were not exectued" | |
6 | else |
|
8 | else | |
7 | # Apply database makemigrations |
|
9 | # Apply database makemigrations | |
8 | echo "Apply makemigrations" |
|
10 | echo "Apply makemigrations" | |
@@ -13,15 +15,18 if [ -f /sirm/radarsys.sqlite ]; | |||||
13 | python manage.py migrate |
|
15 | python manage.py migrate | |
14 | python manage.py loaddata main |
|
16 | python manage.py loaddata main | |
15 | python manage.py loaddata tx |
|
17 | python manage.py loaddata tx | |
|
18 | ||||
16 | # Collect static files |
|
19 | # Collect static files | |
17 | echo "Collect static files" |
|
20 | #echo "Collect static files" | |
18 | python manage.py collectstatic --noinput |
|
21 | #python manage.py collectstatic --noinput | |
19 |
|
22 | |||
|
23 | # Create ".gitkeep" file in "setup" folder | |||
|
24 | echo "Create .gitkeep" | |||
|
25 | touch ../setup/.gitkeep | |||
20 | fi |
|
26 | fi | |
21 |
|
27 | |||
22 |
|
|
28 | echo "Create Superuser" | |
23 | python manage.py createsuperuser_if_none_exists --user=${SIRM_USER} --email=${SIRM_EMAIL} --password=${SIRM_PASSWORD} |
|
29 | python manage.py createsuperuser_if_none_exists | |
24 |
|
30 | |||
25 |
|
|
31 | echo "Run server" | |
26 | echo "Collect static files" |
|
|||
27 | python manage.py runserver 0.0.0.0:8080 No newline at end of file |
|
32 | python manage.py runserver 0.0.0.0:8080 |
@@ -1,3 +1,5 | |||||
|
1 | import os | |||
|
2 | ||||
1 | from django.core.management.base import BaseCommand |
|
3 | from django.core.management.base import BaseCommand | |
2 | from django.contrib.auth import get_user_model |
|
4 | from django.contrib.auth import get_user_model | |
3 |
|
5 | |||
@@ -8,17 +10,12 class Command(BaseCommand): | |||||
8 | manage.py createsuperuser_if_none_exists --user=admin123 --password=admin123 --email=admin123@igp.gob.pe |
|
10 | manage.py createsuperuser_if_none_exists --user=admin123 --password=admin123 --email=admin123@igp.gob.pe | |
9 | """ |
|
11 | """ | |
10 |
|
12 | |||
11 | def add_arguments(self, parser): |
|
|||
12 | parser.add_argument("--user", required=True) |
|
|||
13 | parser.add_argument("--password", required=True) |
|
|||
14 | parser.add_argument("--email", default="admin123@igp.gob.pe") |
|
|||
15 |
|
||||
16 | def handle(self, *args, **options): |
|
13 | def handle(self, *args, **options): | |
17 |
|
14 | |||
18 | User = get_user_model() |
|
15 | User = get_user_model() | |
19 | username = options["user"] |
|
16 | username = os.environ.get('SIRM_USER', 'admin') | |
20 | password = options["password"] |
|
17 | password = os.environ.get('SIRM_PASSWORD', 'soporte') | |
21 | email = options["email"] |
|
18 | email = os.environ.get('SIRM_EMAIL', 'admin@igp.gob.pe') | |
22 |
|
19 | |||
23 | if User.objects.exists(): |
|
20 | if User.objects.exists(): | |
24 | self.stdout.write(f'Local user "{username}" currently exists') |
|
21 | self.stdout.write(f'Local user "{username}" currently exists') |
General Comments 0
You need to be logged in to leave comments.
Login now