##// 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 #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=200
5 SIRM_MAX_UPLOAD_SIZE_MB=20
6
6
7 #Postgres settings
7 #Postgres settings
8 POSTGRES_PORT_5432_TCP_ADDR=radarsys-postgres
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
12 DB_PASSWORD=docker
12 DB_PASSWORD=docker
13 PGDATA=/var/lib/postgresql/data
13 PGDATA=/var/lib/postgresql/data
14
14
15 #Volumes - path
15 #Volumes - path
16 EXPOSE_SIRM=./volumes/sirm
16 EXPOSE_SIRM=./volumes/sirm
17 EXPOSE_PGDATA=/path/to/pg_data
17 EXPOSE_PGDATA=/path/to/pg_data
18 EXPOSE_CERTS=/path/to/certs
18 EXPOSE_CERTS=/path/to/certs
19 EXPOSE_DHPARAM=/path/to/dhparam
19 EXPOSE_DHPARAM=/path/to/dhparam
20
20
21 #Superuser settings
21 #Superuser settings
22 SIRM_USER=admin
22 SIRM_USER=admin
23 SIRM_PASSWORD=soporte
23 SIRM_PASSWORD=soporte
24 SIRM_EMAIL=admin@igp.gob.pe No newline at end of file
24 SIRM_EMAIL=admin@igp.gob.pe
@@ -1,10 +1,8
1 volumes/pg_data
1 volumes/pg_data
2 volumes/dhparam
2 volumes/dhparam
3 volumes/certs
3 volumes/certs
4 volumes/sirm/static_files/*
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
@@ -1,20 +1,20
1 FROM python:3.8-slim
1 FROM python:3.8-slim
2
2
3 # Create "sim" directory
3 # Create "sim" directory
4 RUN mkdir -p /workspace/sirm
4 RUN mkdir -p /workspace/sirm
5 WORKDIR /workspace
5 WORKDIR /workspace
6
6
7 # Copy "start_realtime" file
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
13
13
14 # Install python dependences
14 # Install python dependences
15 ADD requirements.txt ./requirements.txt
15 ADD requirements.txt ./requirements.txt
16 RUN pip install -v --timeout 120 -r requirements.txt --no-cache-dir
16 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
@@ -1,48 +1,49
1 # Integrated Weather Radar System (SIRM)
1 # Integrated Weather Radar System (SIRM)
2
2
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).
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 For more information visit: https://doi.org/10.5281/zenodo.5571130.
5 For more information visit: https://doi.org/10.5281/zenodo.5571130.
6
6
7 ΒΉScanning-system for Observation of Peruvian Hydrometeorological-events
7 ΒΉScanning-system for Observation of Peruvian Hydrometeorological-events
8
8
9 ## Installation
9 ## Installation
10
10
11 We recommend use docker/docker-compose for test/production but you can install the aplication as a normal django app.
11 We recommend use docker/docker-compose for test/production but you can install the aplication as a normal django app.
12
12
13 ### 1. Download
13 ### 1. Download
14
14
15 Download the application *radarsys_met* to your workspace
15 Download the application *radarsys_met* to your workspace
16
16
17 $ cd /path/to/your/workspace
17 $ cd /path/to/your/workspace
18 $ git clone http://intranet.igp.gob.pe:8082/radarsys_met
18 $ git clone http://intranet.igp.gob.pe:8082/radarsys_met
19
19
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=8080
26 SIRM_PORT=<SIRM PORT>
26 SIRM_MAX_UPLOAD_SIZE_MB=200
27 SIRM_MAX_UPLOAD_SIZE_MB=20
27
28
28 #Postgres settings
29 #Postgres settings
29 DB_NAME=radarsys
30 DB_NAME=radarsys
30 DB_USER=docker
31 DB_USER=docker
31 DB_PASSWORD=****
32 DB_PASSWORD=****
32
33
33 #Volumes - path
34 #Volumes - path
34 EXPOSE_PGDATA=/path/to/pg_data
35 EXPOSE_PGDATA=/path/to/pg_data
35 EXPOSE_CERTS=/path/to/certs
36 EXPOSE_CERTS=/path/to/certs
36 EXPOSE_DHPARAM=/path/to/dhparam
37 EXPOSE_DHPARAM=/path/to/dhparam
37
38
38 #Superuser settings
39 #Superuser settings
39 SIRM_USER=admin123
40 SIRM_USER=admin123
40 SIRM_PASSWORD=admin123
41 SIRM_PASSWORD=admin123
41 SIRM_EMAIL=admin123@igp.gob.pe
42 SIRM_EMAIL=admin123@igp.gob.pe
42
43
43 ### 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 ### 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 ### 4. Build and run containers
46 ### 4. Build and run containers
46 You should maybe run the command using <code>sudo</code>
47 You should maybe run the command using <code>sudo</code>
47
48
48 $ docker-compose up -d --build No newline at end of file
49 $ docker-compose up -d --build
@@ -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,27 +1,32
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 'collectstatic' were not exectued"
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"
9 python manage.py makemigrations
11 python manage.py makemigrations
10
12
11 # Apply database migrations
13 # Apply database migrations
12 echo "Apply database migrations"
14 echo "Apply database migrations"
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 # Create superuser
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 # Runserver
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,29 +1,26
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
4 class Command(BaseCommand):
6 class Command(BaseCommand):
5 """
7 """
6 Create a superuser if none exist
8 Create a superuser if none exist
7 Example:
9 Example:
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')
25 return
22 return
26
23
27 User.objects.create_superuser(username=username, password=password, email=email)
24 User.objects.create_superuser(username=username, password=password, email=email)
28
25
29 self.stdout.write(f'Local user "{username}" was created') No newline at end of file
26 self.stdout.write(f'Local user "{username}" was created')
General Comments 0
You need to be logged in to leave comments. Login now