Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ippidb-web
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
iPPIDB
ippidb-web
Commits
a63645d4
Commit
a63645d4
authored
2 years ago
by
Bryan BRANCOTTE
Browse files
Options
Downloads
Patches
Plain Diff
for dev purpose, ability to use dockerized pg instance running
parent
4c19f646
No related branches found
Branches containing commit
No related tags found
2 merge requests
!45
Async near cavities
,
!43
K8S deployments of release branche, and other updates
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ippisite/ippisite/db_finder.py
+59
-0
59 additions, 0 deletions
ippisite/ippisite/db_finder.py
ippisite/ippisite/settings.py
+6
-1
6 additions, 1 deletion
ippisite/ippisite/settings.py
with
65 additions
and
1 deletion
ippisite/ippisite/db_finder.py
0 → 100644
+
59
−
0
View file @
a63645d4
import
os
import
subprocess
def
get_db_ip
():
result
=
subprocess
.
run
(
[
"
docker
"
,
"
ps
"
,
"
-f
"
,
"
name=%s
"
%
get_guessed_container_name
(),
"
-q
"
,
],
stdout
=
subprocess
.
PIPE
,
)
ids
=
result
.
stdout
.
decode
(
"
utf-8
"
).
strip
().
split
(
"
\n
"
)
if
len
(
ids
)
>
1
:
raise
Exception
(
"
Can
'
t find the DB, too much match
"
)
if
len
(
ids
)
==
0
or
len
(
ids
[
0
])
==
0
:
result
=
subprocess
.
run
(
[
"
docker
"
,
"
ps
"
,
"
-f
"
,
"
name=_db
"
,
"
-q
"
,
],
stdout
=
subprocess
.
PIPE
,
)
ids
=
result
.
stdout
.
decode
(
"
utf-8
"
).
strip
().
split
(
"
\n
"
)
if
len
(
ids
)
>
1
:
raise
Exception
(
"
Can
'
t find the DB, couldn
'
t guess container name (tried
'
%s
'
),
"
"
and too much match with
'
_db
'"
%
get_guessed_container_name
()
)
if
len
(
ids
)
==
0
or
len
(
ids
[
0
])
==
0
:
raise
Exception
(
"
Can
'
t find the DB
"
)
result
=
subprocess
.
run
(
[
"
docker
"
,
"
inspect
"
,
"
-f
"
,
"'
{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}
'"
,
ids
[
0
],
],
stdout
=
subprocess
.
PIPE
,
)
return
result
.
stdout
.
decode
(
"
utf-8
"
).
strip
().
replace
(
"'"
,
""
)
def
get_guessed_container_name
():
return
(
str
(
os
.
path
.
dirname
(
__file__
).
split
(
os
.
path
.
sep
)[
-
2
]).
lower
().
replace
(
"
-
"
,
""
)
+
"
_db
"
)
if
__name__
==
"
__main__
"
:
print
(
get_db_ip
())
This diff is collapsed.
Click to expand it.
ippisite/ippisite/settings.py
+
6
−
1
View file @
a63645d4
...
@@ -17,6 +17,8 @@ from decouple import config
...
@@ -17,6 +17,8 @@ from decouple import config
from
django.utils.translation
import
gettext_lazy
from
django.utils.translation
import
gettext_lazy
from
socket
import
gethostname
,
gethostbyname
from
socket
import
gethostname
,
gethostbyname
from
ippisite
import
db_finder
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
PERSISTENT_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'
persistent
'
)
PERSISTENT_DIR
=
os
.
path
.
join
(
BASE_DIR
,
'
persistent
'
)
...
@@ -122,13 +124,16 @@ if config("USE_SQLITE_AS_DB", default="False").upper() == "TRUE":
...
@@ -122,13 +124,16 @@ if config("USE_SQLITE_AS_DB", default="False").upper() == "TRUE":
}
}
}
}
else
:
else
:
POSTGRES_HOST
=
config
(
"
POSTGRES_HOST
"
,
''
)
if
not
POSTGRES_HOST
:
POSTGRES_HOST
=
db_finder
.
get_db_ip
()
DATABASES
=
{
DATABASES
=
{
"
default
"
:
{
"
default
"
:
{
"
ENGINE
"
:
"
django.db.backends.postgresql
"
,
"
ENGINE
"
:
"
django.db.backends.postgresql
"
,
"
NAME
"
:
config
(
"
POSTGRES_DB
"
),
"
NAME
"
:
config
(
"
POSTGRES_DB
"
),
"
USER
"
:
config
(
"
POSTGRES_USER
"
),
"
USER
"
:
config
(
"
POSTGRES_USER
"
),
"
PASSWORD
"
:
config
(
"
POSTGRES_PASSWORD
"
),
"
PASSWORD
"
:
config
(
"
POSTGRES_PASSWORD
"
),
"
HOST
"
:
config
(
"
POSTGRES_HOST
"
)
,
"
HOST
"
:
POSTGRES_HOST
,
"
PORT
"
:
5432
,
"
PORT
"
:
5432
,
}
}
}
}
...
...
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