Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Portal API Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kontr 2.0
Portal API Backend
Commits
59977386
There was an error fetching the commit references. Please try again later.
Unverified
Commit
59977386
authored
6 years ago
by
Peter Stanko
Browse files
Options
Downloads
Patches
Plain Diff
Portal config loading refactor and DB init in docker-compose
parent
e7702942
No related branches found
No related tags found
1 merge request
!18
Minor fixes
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app.py
+7
-8
7 additions, 8 deletions
app.py
docker-compose.yml
+17
-25
17 additions, 25 deletions
docker-compose.yml
docker_run.sh
+17
-0
17 additions, 0 deletions
docker_run.sh
portal/__init__.py
+18
-6
18 additions, 6 deletions
portal/__init__.py
with
59 additions
and
39 deletions
app.py
+
7
−
8
View file @
59977386
...
...
@@ -9,8 +9,8 @@ import click
from
flask
import
Flask
from
flask.cli
import
AppGroup
,
run_command
import
portal.logging
as
logging_config
import
portal
import
portal.logging
as
logging_config
from
management.data
import
DataManagement
from
portal
import
create_app
,
db
...
...
@@ -66,20 +66,20 @@ def cli_init_data(env):
@users_cli.command
(
'
create
'
,
help
=
'
Create admin user
'
)
@click.argument
(
'
name
'
)
def
cli_users_create
(
name
):
@click.option
(
'
-p
'
,
'
--password
'
,
help
=
'
Users password
'
,
prompt
=
True
,
hide_input
=
True
,
confirmation_prompt
=
True
)
def
cli_users_create
(
name
,
password
):
log
.
info
(
f
"
[CMD] Create User:
{
name
}
"
)
password
=
click
.
prompt
(
'
Password
'
,
hide_input
=
True
,
confirmation_prompt
=
True
)
user
=
manager
.
create_admin_user
(
name
,
password
)
log
.
info
(
f
"
[CMD] Created User:
{
user
}
"
)
@users_cli.command
(
'
set-password
'
,
help
=
'
Sets password for the user
'
)
@click.argument
(
'
name
'
)
def
cli_users_set_password
(
name
):
@click.option
(
'
-p
'
,
'
--password
'
,
help
=
'
Users password
'
,
prompt
=
True
,
hide_input
=
True
,
confirmation_prompt
=
True
)
def
cli_users_set_password
(
name
,
password
):
log
.
info
(
f
"
[CMD] Update password for user:
{
name
}
"
)
password
=
click
.
prompt
(
'
Password
'
,
hide_input
=
True
,
confirmation_prompt
=
True
)
user
=
manager
.
update_users_password
(
name
,
password
)
log
.
info
(
f
"
[CMD] Updated password for user:
{
user
}
"
)
...
...
@@ -171,6 +171,5 @@ def cli_submissions_list_all():
manager
.
clean_all_submissions
()
if
__name__
==
'
__main__
'
:
cli_run_devel
()
This diff is collapsed.
Click to expand it.
docker-compose.yml
+
17
−
25
View file @
59977386
...
...
@@ -3,12 +3,7 @@ services:
portal
:
build
:
.
image
:
'
kontr2/portal'
command
:
>
gunicorn -b 0.0.0.0:8000
--access-logfile -
--reload
"app:app"
command
:
bash docker_run.sh
ports
:
-
"
8000:8000"
environment
:
...
...
@@ -21,32 +16,13 @@ services:
-
db
-
redis
redis
:
image
:
"
redis:alpine"
networks
:
-
async_nw
db
:
image
:
'
postgres'
ports
:
-
"
5432:5432"
networks
:
-
db_nw
environment
:
POSTGRES_USER
:
${DB_USER}
POSTGRES_PASSWORD
:
${DB_PASSWORD}
POSTGRES_DB
:
${DB_DB}
celery
:
build
:
.
image
:
'
kontr2/portal'
privileged
:
true
container_name
:
'
kontr-portal-async-celery'
command
:
"
celery
worker
-l
info
-A
app.celery"
environment
:
CELERY_BROKER_URL
:
'
redis://redis:6379/0'
SQLALCHEMY_DATABASE_URI
:
"
postgresql://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_DB}"
depends_on
:
-
redis
-
portal
...
...
@@ -55,6 +31,22 @@ services:
-
async_nw
-
db_nw
redis
:
image
:
"
redis:alpine"
networks
:
-
async_nw
db
:
image
:
'
postgres'
ports
:
-
"
5432:5432"
networks
:
-
db_nw
environment
:
POSTGRES_USER
:
${DB_USER}
POSTGRES_PASSWORD
:
${DB_PASSWORD}
POSTGRES_DB
:
${DB_DB}
networks
:
db_nw
:
driver
:
bridge
...
...
This diff is collapsed.
Click to expand it.
docker_run.sh
0 → 100644
+
17
−
0
View file @
59977386
#!/bin/bash
ENVIRONMENT
=
"
${
ENVIRONMENT
:-
dev
}
"
ADMIN_USER
=
"
${
ADMIN_USER
:-
admin
}
"
ADMIN_PASSWORD
=
"
${
ADMIN_PASSWORD
:-
789789
}
"
# INIT
echo
"[INIT] Initializing the database"
flask db upgrade
echo
"[INIT] Initializing data for env:
$ENVIRONMENT
"
flask data init
${
ENVIRONMENT
}
echo
"[INIT] Initializing admin user:
${
ADMIN_USER
}
"
flask
users
create
${
ADMIN_USER
}
--password
${
ADMIN_PASSWORD
}
# RUN THE SERVER
gunicorn
-b
0.0.0.0:8000
--access-logfile
-
--reload
"app:app"
This diff is collapsed.
Click to expand it.
portal/__init__.py
+
18
−
6
View file @
59977386
...
...
@@ -42,17 +42,29 @@ def configure_app(app: Flask, env: str = None,
ignore_local(bool): Whether to ignore portal.local.cfg
"""
config_type
=
env
or
os
.
environ
.
get
(
'
PORTAL_CONFIG_TYPE
'
,
'
dev
'
)
log
.
debug
(
f
"
[INIT] Portal Config Type:
{
config_type
}
"
)
config_object
=
CONFIGURATIONS
[
config_type
]
if
config_object
is
None
:
raise
RuntimeError
(
f
"
There is no config object for:
{
config_type
}
"
)
config_object
=
_get_config_object
(
config_type
)
app
.
config
.
from_object
(
config_object
)
_load_portal_local
(
app
,
env
,
ignore_local
)
app
.
config
[
'
PORTAL_ENV
'
]
=
config_type
log
.
debug
(
"
[INIT] Loaded config:
"
)
for
(
key
,
val
)
in
app
.
config
.
items
():
log
.
debug
(
f
"
[CONFIG]
{
key
}
=
{
val
}
"
)
return
app
def
_load_portal_local
(
app
,
env
,
ignore_local
):
ignore_local
=
ignore_local
or
env
==
'
test
'
if
not
ignore_local
:
app
.
config
.
from_pyfile
(
ROOT_DIR
/
'
portal.local.cfg
'
,
silent
=
True
)
app
.
config
.
from_envvar
(
'
PORTAL_CONFIG
'
,
silent
=
True
)
app
.
config
[
'
PORTAL_ENV
'
]
=
config_type
return
app
def
_get_config_object
(
config_type
):
log
.
debug
(
f
"
[INIT] Portal Config Type:
{
config_type
}
"
)
config_object
=
CONFIGURATIONS
[
config_type
]
if
config_object
is
None
:
raise
RuntimeError
(
f
"
There is no config object for:
{
config_type
}
"
)
return
config_object
def
configure_storage
(
app
:
Flask
)
->
Flask
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment