Skip to content

Commit

Permalink
use postgresql as database for gateway and repository-server (#508)
Browse files Browse the repository at this point in the history
use SQLite for unit test

Signed-off-by: Akihiko Kuroda <[email protected]>
  • Loading branch information
akihikokuroda authored May 12, 2023
1 parent 98b88f1 commit 0a6a04f
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 2 deletions.
13 changes: 13 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ services:
- SITE_HOST=http://gateway:8000
# - SETTINGS_AUTH_MECHANISM=default #custom_token
# - SETTINGS_TOKEN_AUTH_URL=<URL_FOR_TOKEN_VERIFICATION>
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_NAME=testkeycloakdb
- DATABASE_USER=testkeycloakuser
- DATABASE_PASSWORD=testkeycloakpassword
networks:
- safe-tier
depends_on:
- keycloak
- postgres
repository-server:
container_name: repository-server
build:
Expand All @@ -101,6 +107,13 @@ services:
- DJANGO_SUPERUSER_USERNAME=admin
- DJANGO_SUPERUSER_PASSWORD=123
- [email protected]
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_NAME=testkeycloakdb
- DATABASE_USER=testkeycloakuser
- DATABASE_PASSWORD=testkeycloakpassword
depends_on:
- postgres
networks:
- safe-tier
prometheus:
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ services:
- SITE_HOST=http://gateway:8000
# - SETTINGS_AUTH_MECHANISM=default #custom_token
# - SETTINGS_TOKEN_AUTH_URL=<URL_FOR_TOKEN_VERIFICATION>
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_NAME=testkeycloakdb
- DATABASE_USER=testkeycloakuser
- DATABASE_PASSWORD=testkeycloakpassword
networks:
- safe-tier
depends_on:
- keycloak
- postgres
repository-server:
container_name: repository-server
image: docker.io/qiskit/quantum-repository-server:${VERSION:-0.0.8}
Expand All @@ -93,6 +99,13 @@ services:
- DJANGO_SUPERUSER_USERNAME=admin
- DJANGO_SUPERUSER_PASSWORD=123
- [email protected]
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_NAME=testkeycloakdb
- DATABASE_USER=testkeycloakuser
- DATABASE_PASSWORD=testkeycloakpassword
depends_on:
- postgres
networks:
- safe-tier
prometheus:
Expand Down
28 changes: 27 additions & 1 deletion gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
import os.path
import sys
from datetime import timedelta
from pathlib import Path

Expand Down Expand Up @@ -54,6 +56,7 @@
"dj_rest_auth",
"dj_rest_auth.registration",
"api",
"psycopg2",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -89,17 +92,40 @@

WSGI_APPLICATION = "main.wsgi.application"

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"root": {
"handlers": ["console"],
"level": "DEBUG",
},
}

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DATABASE_NAME", "bitnami_keycloak"),
"USER": os.environ.get("DATABASE_USER", "bn_keycloak"),
"PASSWORD": os.environ.get("DATABASE_PASSWORD", "wHXJPZSOGV"),
"HOST": os.environ.get("DATABASE_HOST", "postgresql"),
"PORT": os.environ.get("DATABASE_PORT", "5432"),
},
"test": {
"ENGINE": "django_prometheus.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
},
}

if "test" in sys.argv:
DATABASES["default"] = DATABASES["test"]

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
Expand Down
1 change: 1 addition & 0 deletions gateway/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ ray[default]>=2.3.0
Django>=4.2.1
gunicorn>=20.1.0
requests>=2.28.2
psycopg2-binary>=2.9.6
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
serviceAccountName: {{ include "gateway.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: waitpostresql
image: actions/pg_isready
command: ['sh', '-c', 'until pg_isready -U {{ .Values.database.user | quote }} -d "dbname={{ .Values.database.name }}" -h {{ .Values.database.host }} -p {{ .Values.database.port | quote }}; do echo waiting for myservice; sleep 2; done']
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down Expand Up @@ -69,6 +73,19 @@ spec:
value: {{ .Values.application.superuser.password | quote }}
- name: DJANGO_SUPERUSER_EMAIL
value: {{ .Values.application.superuser.email | quote }}
- name: DATABASE_HOST
value: {{ .Values.database.host }}
- name: DATABASE_PORT
value: {{ .Values.database.port | quote }}
- name: DATABASE_NAME
value: {{ .Values.database.name | quote }}
- name: DATABASE_USER
value: {{ .Values.database.user | quote }}
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: postgresql
key: password
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ application:
password: "passw0rd"
email: "[email protected]"

database:
host: postgresql
port: 5432
user: bn_keycloak
name: bitnami_keycloak

image:
repository: qiskit/quantum-serverless-gateway
pullPolicy: IfNotPresent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
serviceAccountName: {{ include "repository.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: waitpostresql
image: actions/pg_isready
command: ['sh', '-c', 'until pg_isready -U {{ .Values.database.user | quote }} -d "dbname={{ .Values.database.name }}" -h {{ .Values.database.host }} -p {{ .Values.database.port | quote }}; do echo waiting for myservice; sleep 2; done']
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down Expand Up @@ -57,6 +61,19 @@ spec:
value: {{ .Values.application.superuser.password | quote }}
- name: DJANGO_SUPERUSER_EMAIL
value: {{ .Values.application.superuser.email | quote }}
- name: DATABASE_HOST
value: {{ .Values.database.host }}
- name: DATABASE_PORT
value: {{ .Values.database.port | quote }}
- name: DATABASE_NAME
value: {{ .Values.database.name | quote }}
- name: DATABASE_USER
value: {{ .Values.database.user | quote }}
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: postgresql
key: password
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

replicaCount: 1

database:
host: postgresql
port: 5432
user: bn_keycloak
name: bitnami_keycloak

image:
repository: qiskit/quantum-repository-server
pullPolicy: IfNotPresent
Expand Down
14 changes: 13 additions & 1 deletion repository/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
import sys
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -45,6 +46,7 @@
"rest_framework",
"drf_yasg",
"api",
"psycopg2",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -86,11 +88,21 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DATABASE_NAME", "bitnami_keycloak"),
"USER": os.environ.get("DATABASE_USER", "bn_keycloak"),
"PASSWORD": os.environ.get("DATABASE_PASSWORD", "wHXJPZSOGV"),
"HOST": os.environ.get("DATABASE_HOST", "postgresql"),
"PORT": os.environ.get("DATABASE_PORT", "5432"),
},
"test": {
"ENGINE": "django_prometheus.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
},
}

if "test" in sys.argv:
DATABASES["default"] = DATABASES["test"]

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
Expand Down
1 change: 1 addition & 0 deletions repository/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ sqlparse>=0.4.4
zipp>=3.15.0
drf-yasg>=1.21.5
gunicorn>=20.1.0
psycopg2-binary>=2.9.6

0 comments on commit 0a6a04f

Please sign in to comment.