Skip to content

Commit

Permalink
Merge pull request #58 from nipreps/enh/dev-server
Browse files Browse the repository at this point in the history
ENH: Minor improvements
  • Loading branch information
mgxd authored Dec 6, 2022
2 parents ad7a63d + 1e1a51f commit 1efd7a4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
- name: Start all the things
run: docker compose up -d
- name: Test the things
run: docker exec migas_server bash -c "pytest --pyargs migas_server"
run: docker exec migas-server bash -c "pytest --pyargs migas_server"
- name: Stop all the things
run: docker compose down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
# Migas API server
server:
build: .
container_name: "migas_server"
container_name: "migas-server"
ports:
- "8000:8000"
depends_on:
Expand Down Expand Up @@ -59,3 +59,4 @@ services:
# Network to link all services
networks:
migas:
name: migas
1 change: 1 addition & 0 deletions migas_server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def _fmt_kv_pairs(value):
"--headers",
nargs='*',
type=_fmt_kv_pairs,
default=[['X-Backend-Server', 'migas']],
help="Custom HTTP response headers as 'Name:Value' pairs",
)
return parser
Expand Down
12 changes: 9 additions & 3 deletions migas_server/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ async def get_db_engine() -> AsyncEngine:
from sqlalchemy.engine import URL

db_url = URL.create(
drivername="postgresql+asyncpg",
username=os.getenv("DATABASE_USER"),
password=os.getenv("DATABASE_PASSWORD"),
database=os.getenv("DATABASE_NAME"),
)
if gcp_conn := os.getenv("GCP_SQL_CONNECTION"):
# db_url.set(query={"unix_sock": f"/cloudsql/{gcp_conn}/.s.PGSQL.5432"})

else:
# Convert string to sqlalchemy URL
from sqlalchemy.engine import make_url

db_url = make_url(db_url)

db_url = db_url.set(drivername="postgresql+asyncpg")
if gcp_conn := os.getenv("GCP_SQL_CONNECTION"):
db_url = db_url.set(query={"host": f"/cloudsql/{gcp_conn}/.s.PGSQL.5432"})

DB_ENGINE = create_async_engine(
Expand Down
2 changes: 1 addition & 1 deletion migas_server/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_parser_defaults():
@pytest.mark.parametrize(
'input,output',
[
([], None),
([], [['X-Backend-Server', 'migas']]),
(['Hello:There'], [['Hello', 'There']]),
(['X-Backend-Server:migas', 'X-Test:1'], [['X-Backend-Server', 'migas'], ['X-Test', '1']]),
],
Expand Down

0 comments on commit 1efd7a4

Please sign in to comment.