Skip to content

Commit da59a4a

Browse files
moves the control over docker compose into alfred
1 parent f730de9 commit da59a4a

File tree

10 files changed

+84
-95
lines changed

10 files changed

+84
-95
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ COPY requirements.txt .
77
RUN pip3 install -r requirements.txt
88

99
COPY / .
10-
11-
CMD [ "/usr/local/bin/uvicorn", "--host", "0.0.0.0", "--port", "80", "app:app" ]

app.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

dev.Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
docker
2-
fastapi
3-
uvicorn
2+
docker-compose

start

Lines changed: 0 additions & 24 deletions
This file was deleted.

start.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import subprocess
2+
import sys
3+
from util.alembic_fix import check_revision
4+
from util.constants import DOCKER_COMPOSE
5+
from util.docker_helper import (
6+
create_jwks_secret_if_not_existing,
7+
check_and_pull_exec_env_images,
8+
wait_until_refinery_is_ready,
9+
)
10+
from util.postgres_helper import wait_until_postgres_is_ready
11+
from util.template_processor import process_docker_compose_template
12+
13+
refinery_dir = sys.argv[1]
14+
15+
print("Creating docker-compose.yml file...", flush=True)
16+
minio_endpoint = process_docker_compose_template(refinery_dir)
17+
print("Creating jwks.json secret...", flush=True)
18+
create_jwks_secret_if_not_existing()
19+
print("Checking and pulling exec env images...", flush=True)
20+
check_and_pull_exec_env_images()
21+
22+
print("Starting postgres container...", flush=True)
23+
subprocess.call(
24+
["docker-compose", "-f", DOCKER_COMPOSE, "up", "-d", "graphql-postgres"]
25+
)
26+
print("Waiting for postgres to be ready...", flush=True)
27+
if wait_until_postgres_is_ready():
28+
check_revision()
29+
30+
print("Starting all containers...", flush=True)
31+
subprocess.call(["docker-compose", "-f", DOCKER_COMPOSE, "up", "-d"])
32+
33+
34+
print("Checking if all services are ready...", flush=True)
35+
if wait_until_refinery_is_ready():
36+
print("Refinery is ready!", flush=True)
37+
else:
38+
print("Refinery is not ready!", flush=True)
39+
40+
print("UI: http://localhost:4455/app/")
41+
print(f"Minio: {minio_endpoint}")
42+
print("MailHog: http://localhost:4436/")

templates/docker-compose.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@ services:
66
environment:
77
- DSN=sqlite:///var/lib/sqlite/db.sqlite?_fk=true&mode=rwc
88
volumes:
9-
- type: volume
10-
source: kratos-sqlite
11-
target: /var/lib/sqlite
12-
read_only: false
13-
- type: bind
14-
source: ./kratos/kratos.yml
15-
target: /home/.kratos.yaml
9+
- {LOCAL_VOLUME_KRATOS_SQLITE}:/var/lib/sqlite
10+
- {LOCAL_VOLUME_KRATOS}/kratos.yml:/home/.kratos.yaml
1611
command: migrate sql -e --yes
1712
restart: on-failure
1813
networks:
@@ -29,8 +24,8 @@ services:
2924
- SERVE_PUBLIC_BASE_URL=http://localhost:4455/.ory/kratos/public/
3025
command: serve -c /etc/config/kratos/kratos.yml --dev --watch-courier
3126
volumes:
32-
- ./kratos:/etc/config/kratos:Z
33-
- kratos-sqlite:/var/lib/sqlite
27+
- {LOCAL_VOLUME_KRATOS}:/etc/config/kratos:Z
28+
- {LOCAL_VOLUME_KRATOS_SQLITE}:/var/lib/sqlite
3429
networks:
3530
- default
3631

@@ -47,7 +42,7 @@ services:
4742
networks:
4843
- default
4944
volumes:
50-
- ./oathkeeper:/etc/config/oathkeeper:Z
45+
- {LOCAL_VOLUME_OATHKEEPER}:/etc/config/oathkeeper:Z
5146

5247
refinery-authorizer:
5348
image: kernai/refinery-authorizer:{AUTHORIZER}
@@ -106,7 +101,7 @@ services:
106101
- 80
107102
volumes:
108103
- /var/run/docker.sock:/var/run/docker.sock:Z
109-
- graphql-sqlite:/sqlite
104+
- {LOCAL_VOLUME_GRAPHQL_SQLITE}:/sqlite
110105
environment:
111106
- AC_EXEC_ENV_IMAGE=kernai/refinery-ac-exec-env:{AC_EXEC_ENV}
112107
- LF_EXEC_ENV_IMAGE=kernai/refinery-lf-exec-env:{LF_EXEC_ENV}
@@ -326,6 +321,3 @@ services:
326321
networks:
327322
default:
328323

329-
volumes:
330-
kratos-sqlite:
331-
graphql-sqlite:

update.py

Whitespace-only changes.

util/docker_helper.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import socket
5+
import time
56
from typing import Any, Tuple
67

78
from util.constants import EXEC_ENVS, SERVICE_VERSIONS, JWKS_PATH
@@ -69,10 +70,37 @@ def is_container_running(container_name: str) -> bool:
6970

7071
def is_image_present(image_name: str, image_tag: str) -> bool:
7172
try:
72-
image = client.images.get(image_name)
73+
client.images.get(f"{image_name}:{image_tag}")
7374
except docker.errors.ImageNotFound:
7475
return False
76+
return True
7577

76-
if image_tag in image.tags:
77-
return True
78+
79+
def is_uvicorn_application_started(container_name: str) -> bool:
80+
try:
81+
container = client.containers.list(filters={"name": container_name})[0]
82+
return "Application startup complete." in container.logs().decode("utf-8")
83+
except docker.errors.ImageNotFound:
84+
return False
85+
86+
87+
def is_ui_service_ready(container_name: str) -> bool:
88+
try:
89+
container = client.containers.list(filters={"name": container_name})[0]
90+
return "Configuration complete; ready for start up" in container.logs().decode(
91+
"utf-8"
92+
)
93+
except docker.errors.ImageNotFound:
94+
return False
95+
96+
97+
def wait_until_refinery_is_ready(timeout: int = 60) -> None:
98+
start_time = time.time()
99+
100+
while start_time + timeout > time.time():
101+
gateway_ready = is_uvicorn_application_started("refinery-gateway")
102+
ui_ready = is_ui_service_ready("refinery-ui")
103+
if gateway_ready and ui_ready:
104+
return True
105+
time.sleep(1)
78106
return False

util/template_processor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23

34
from util.constants import (
45
DOCKER_COMPOSE,
@@ -9,7 +10,7 @@
910
from util.docker_helper import get_credential_ip, get_host_ip
1011

1112

12-
def process_docker_compose_template():
13+
def process_docker_compose_template(refinery_dir: str) -> str:
1314
credential_ip = get_credential_ip()
1415
host_ip = get_host_ip()
1516

@@ -24,6 +25,8 @@ def process_docker_compose_template():
2425

2526
with open(SETTINGS, "r") as f:
2627
settings = json.load(f)
28+
for volume, rel_path in settings.items():
29+
settings[volume] = os.path.normpath(os.path.join(refinery_dir, rel_path))
2730

2831
docker_compose = template.format(
2932
**versions,

0 commit comments

Comments
 (0)