##// END OF EJS Templates
Update settings for postgres container and prerun.py file
eynilupu -
r376:cd7f82cbe0ca
parent child
Show More
@@ -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,24 +1,24
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=200
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=radarsys-postgres
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
12 12 DB_PASSWORD=docker
13 13 PGDATA=/var/lib/postgresql/data
14 14
15 15 #Volumes - path
16 16 EXPOSE_SIRM=./volumes/sirm
17 17 EXPOSE_PGDATA=/path/to/pg_data
18 18 EXPOSE_CERTS=/path/to/certs
19 19 EXPOSE_DHPARAM=/path/to/dhparam
20 20
21 21 #Superuser settings
22 22 SIRM_USER=admin
23 23 SIRM_PASSWORD=soporte
24 24 SIRM_EMAIL=admin@igp.gob.pe No newline at end of file
@@ -1,10 +1,8
1 1 volumes/pg_data
2 2 volumes/dhparam
3 3 volumes/certs
4 4 volumes/sirm/static_files/*
5 5 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
@@ -1,20 +1,20
1 1 FROM python:3.8-slim
2 2
3 3 # Create "sim" directory
4 4 RUN mkdir -p /workspace/sirm
5 5 WORKDIR /workspace
6 6
7 # Copy "start_realtime" file
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
13 13
14 14 # Install python dependences
15 15 ADD requirements.txt ./requirements.txt
16 16 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
@@ -1,48 +1,49
1 1 # Integrated Weather Radar System (SIRM)
2 2
3 3 The Integrated Weather Radar System (SIRM) is a web application which allows the configuration of SOPHy¹ radar devices as required by the experiment. This app allows the creation of Experiment and Device Configurations (Pedestal, Generator, USRP Rx and USRP Tx).
4 4
5 5 For more information visit: https://doi.org/10.5281/zenodo.5571130.
6 6
7 7 ¹Scanning-system for Observation of Peruvian Hydrometeorological-events
8 8
9 9 ## Installation
10 10
11 11 We recommend use docker/docker-compose for test/production but you can install the aplication as a normal django app.
12 12
13 13 ### 1. Download
14 14
15 15 Download the application *radarsys_met* to your workspace
16 16
17 17 $ cd /path/to/your/workspace
18 18 $ git clone http://intranet.igp.gob.pe:8082/radarsys_met
19 19
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=8080
26 SIRM_MAX_UPLOAD_SIZE_MB=200
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
30 31 DB_USER=docker
31 32 DB_PASSWORD=****
32 33
33 34 #Volumes - path
34 35 EXPOSE_PGDATA=/path/to/pg_data
35 36 EXPOSE_CERTS=/path/to/certs
36 37 EXPOSE_DHPARAM=/path/to/dhparam
37 38
38 39 #Superuser settings
39 40 SIRM_USER=admin123
40 41 SIRM_PASSWORD=admin123
41 42 SIRM_EMAIL=admin123@igp.gob.pe
42 43
43 44 ### 3. Create the folders declared in the variables <code>EXPOSE_PGDATA</code>, <code>EXPOSE_CERTS</code> and <code>EXPOSE_DHPARAM</code> in the <code>.env</code> file.
44 45
45 46 ### 4. Build and run containers
46 47 You should maybe run the command using <code>sudo</code>
47 48
48 49 $ docker-compose up -d --build No newline at end of file
@@ -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,27 +1,32
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 'collectstatic' were not exectued"
7 echo "The commands 'makemigrations', 'migrate' and '.gitkeep' were not exectued"
6 8 else
7 9 # Apply database makemigrations
8 10 echo "Apply makemigrations"
9 11 python manage.py makemigrations
10 12
11 13 # Apply database migrations
12 14 echo "Apply database migrations"
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 # Create superuser
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 # Runserver
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,29 +1,26
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
4 6 class Command(BaseCommand):
5 7 """
6 8 Create a superuser if none exist
7 9 Example:
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')
25 22 return
26 23
27 24 User.objects.create_superuser(username=username, password=password, email=email)
28 25
29 26 self.stdout.write(f'Local user "{username}" was created') No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now