@@ -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 | 1 | #General settings |
|
2 | 2 | LC_ALL=C.UTF-8 |
|
3 | SIRM_SITE=10.10.10.30 | |
|
4 | SIRM_PORT=8085 | |
|
5 |
SIRM_MAX_UPLOAD_SIZE_MB=20 |
|
|
3 | SIRM_SITE=<SIRM SITE> | |
|
4 | SIRM_PORT=<SIRM PORT> | |
|
5 | SIRM_MAX_UPLOAD_SIZE_MB=20 | |
|
6 | 6 | |
|
7 | 7 | #Postgres settings |
|
8 |
POSTGRES_PORT_5432_TCP_ADDR= |
|
|
8 | POSTGRES_PORT_5432_TCP_ADDR=sirm-postgres | |
|
9 | 9 | POSTGRES_PORT_5432_TCP_PORT=5432 |
|
10 | 10 | DB_NAME=radarsys |
|
11 | 11 | DB_USER=docker |
@@ -6,5 +6,3 migrations | |||
|
6 | 6 | *.pyc |
|
7 | 7 | *initial.py |
|
8 | 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 | 4 | RUN mkdir -p /workspace/sirm |
|
5 | 5 | WORKDIR /workspace |
|
6 | 6 | |
|
7 |
# Copy "s |
|
|
8 | ADD ./setup/start_realtime.sh ./start_realtime.sh | |
|
9 | RUN chmod +x ./start_realtime.sh | |
|
7 | # Copy "setup" files | |
|
8 | COPY ./setup/ ./setup/ | |
|
9 | RUN chmod +x ./setup/start_realtime.sh | |
|
10 | 10 | |
|
11 | 11 | # Set working directory |
|
12 | 12 | WORKDIR /workspace/sirm |
@@ -17,4 +17,4 RUN pip install -v --timeout 120 -r requirements.txt --no-cache-dir | |||
|
17 | 17 | |
|
18 | 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 | 20 | ### 2. Config <code>.env</code> file |
|
21 | 21 | |
|
22 | 22 | Update enviroment vars (/path/to/radarsys_met/.env) |
|
23 | ||
|
23 | 24 | #General settings |
|
24 | SIRM_SITE=localhost | |
|
25 |
SIRM_PORT= |
|
|
26 |
SIRM_MAX_UPLOAD_SIZE_MB=20 |
|
|
25 | SIRM_SITE=<SIRM SITE> | |
|
26 | SIRM_PORT=<SIRM PORT> | |
|
27 | SIRM_MAX_UPLOAD_SIZE_MB=20 | |
|
27 | 28 | |
|
28 | 29 | #Postgres settings |
|
29 | 30 | DB_NAME=radarsys |
@@ -1,7 +1,15 | |||
|
1 | Django | |
|
2 | django-bootstrap4 | |
|
3 | psycopg2-binary | |
|
4 | django-polymorphic | |
|
5 | gunicorn | |
|
6 | requests | |
|
7 | ||
|
1 | Django==4.0.3 | |
|
2 | django-bootstrap4==22.1 | |
|
3 | psycopg2-binary==2.9.3 | |
|
4 | django-polymorphic==3.1.0 | |
|
5 | gunicorn==20.1.0 | |
|
6 | requests==2.27.1 | |
|
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 | 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 | 6 | then |
|
5 |
echo "The commands 'makemigrations', 'migrate' and ' |
|
|
7 | echo "The commands 'makemigrations', 'migrate' and '.gitkeep' were not exectued" | |
|
6 | 8 | else |
|
7 | 9 | # Apply database makemigrations |
|
8 | 10 | echo "Apply makemigrations" |
@@ -13,15 +15,18 if [ -f /sirm/radarsys.sqlite ]; | |||
|
13 | 15 | python manage.py migrate |
|
14 | 16 | python manage.py loaddata main |
|
15 | 17 | python manage.py loaddata tx |
|
18 | ||
|
16 | 19 | # Collect static files |
|
17 | echo "Collect static files" | |
|
18 | python manage.py collectstatic --noinput | |
|
20 | #echo "Collect static files" | |
|
21 | #python manage.py collectstatic --noinput | |
|
19 | 22 | |
|
23 | # Create ".gitkeep" file in "setup" folder | |
|
24 | echo "Create .gitkeep" | |
|
25 | touch ../setup/.gitkeep | |
|
20 | 26 | fi |
|
21 | 27 | |
|
22 |
|
|
|
23 | python manage.py createsuperuser_if_none_exists --user=${SIRM_USER} --email=${SIRM_EMAIL} --password=${SIRM_PASSWORD} | |
|
28 | echo "Create Superuser" | |
|
29 | python manage.py createsuperuser_if_none_exists | |
|
24 | 30 | |
|
25 |
|
|
|
26 | echo "Collect static files" | |
|
31 | echo "Run server" | |
|
27 | 32 | python manage.py runserver 0.0.0.0:8080 No newline at end of file |
@@ -1,3 +1,5 | |||
|
1 | import os | |
|
2 | ||
|
1 | 3 | from django.core.management.base import BaseCommand |
|
2 | 4 | from django.contrib.auth import get_user_model |
|
3 | 5 | |
@@ -8,17 +10,12 class Command(BaseCommand): | |||
|
8 | 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 | 13 | def handle(self, *args, **options): |
|
17 | 14 | |
|
18 | 15 | User = get_user_model() |
|
19 | username = options["user"] | |
|
20 | password = options["password"] | |
|
21 | email = options["email"] | |
|
16 | username = os.environ.get('SIRM_USER', 'admin') | |
|
17 | password = os.environ.get('SIRM_PASSWORD', 'soporte') | |
|
18 | email = os.environ.get('SIRM_EMAIL', 'admin@igp.gob.pe') | |
|
22 | 19 | |
|
23 | 20 | if User.objects.exists(): |
|
24 | 21 | self.stdout.write(f'Local user "{username}" currently exists') |
General Comments 0
You need to be logged in to leave comments.
Login now