Skip to content

Commit 5678645

Browse files
committed
move startup sequence around
1 parent d965f43 commit 5678645

File tree

5 files changed

+45
-42
lines changed

5 files changed

+45
-42
lines changed

backend/deploy_tmp/.env

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
DB_HOST="127.0.0.1"
2-
DB_PORT="3141"
3-
KV_HOST="127.0.0.1"
4-
KV_PORT="6379"
5-
MAIL_ENABLED ="True"
6-
SMTP_SERVER ="mail.dsavdodeka.nl"
7-
SMTP_PORT ="465"
8-
RECREATE="yes"
1+
export DB_HOST="127.0.0.1"
2+
export DB_PORT="3141"
3+
export KV_HOST="127.0.0.1"
4+
export KV_PORT="6379"
5+
export MAIL_ENABLED ="True"
6+
export SMTP_SERVER ="mail.dsavdodeka.nl"
7+
export SMTP_PORT ="465"
8+
export RECREATE="yes"

backend/deploy_tmp/prepare.sh

100644100755
+6-19
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,11 @@ set -a
66

77
cd ../../authpage
88
echo "VITE_AUTHPAGE_AUTH_URL=https://api.dsavdodeka.nl" > .env.production
9-
echo "VITE_AUTHPAGE_CLIENT_URL=https://dsavdodeka.nl" >> .env.production
10-
npm ci
11-
npm run build -- --mode production
9+
echo "VITE_AUTHPAGE_CLIENT_URL=https://demo.tipten.nl" >> .env.production
10+
npm ci --force
11+
npm run build -- --mode production --emptyOutDir
1212

13-
cd ../../deploy_tmp
13+
cd ../backend/deploy_tmp
1414

15-
mv -f ./define.toml ../src/apiserver/resources/define.toml
16-
mv -f ./env.toml ../src/apiserver/resources/env.toml
17-
18-
# Define the names of the environment variables
19-
ENV_VARS=("DB_PASS" "KV_PASS" "MAIL_PASS", "KEY_PASS")
20-
21-
echo "Please enter values for the following environment variables:"
22-
for VAR in "${ENV_VARS[@]}"; do
23-
read -p "Enter value for $VAR: " VALUE
24-
export "$VAR=$VALUE"
25-
done
26-
27-
source .env
28-
29-
echo "Environment variables have been set in your current shell."
15+
cp -f ./define.toml ../src/apiserver/resources/define.toml
16+
cp -f ./env.toml ../src/apiserver/resources/env.toml

backend/deploy_tmp/set_envs.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Define the names of the environment variables
4+
ENV_VARS=("DB_PASS" "KV_PASS" "MAIL_PASS" "KEY_PASS")
5+
6+
echo "Please enter values for the following environment variables:"
7+
for VAR in "${ENV_VARS[@]}"; do
8+
read -p "Enter value for $VAR: " VALUE
9+
export "$VAR=$VALUE"
10+
done
11+
12+
. ./.env
13+
14+
echo "Environment variables have been set in your current shell."

backend/src/apiserver/app/ops/startup.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from apiserver.data.api.classifications import insert_classification
3030
from apiserver.data.source import KeyState
3131
from apiserver import data
32-
from apiserver.data import Source
32+
from apiserver.data import Source, get_kv
3333
from apiserver.data.admin import drop_recreate_database
3434

3535

@@ -39,18 +39,9 @@ async def startup(dsrc: Source, config: Config, recreate: bool = False) -> None:
3939
attempting this, it uses a simple lock mechanism by letting the first process set a value in the KV.
4040
"""
4141

42-
try:
43-
# Store startup (tests connection)
44-
await dsrc.store.startup()
45-
except StoreObjectError as e:
46-
raise AppError(
47-
ErrorKeys.STARTUP,
48-
"<magenta>Failed to start store! Did you start the databases?</magenta>",
49-
"startup_store_failure",
50-
) from e
51-
5242
# Checks lock: returns True if it is the first lock since at least 25 seconds (lock expire time)
5343
is_first_process = await wait_for_lock_is_first(dsrc)
44+
5445
logger.debug(f"Unlocked startup, first={is_first_process}")
5546
# Only recreates if it is also the first lock since at least 25 seconds (lock expire time)
5647
logger.debug(f"Startup with recreate={recreate and is_first_process}")
@@ -71,6 +62,17 @@ async def startup(dsrc: Source, config: Config, recreate: bool = False) -> None:
7162
logger.warning("Initial population...")
7263
await initial_population(dsrc, config)
7364

65+
# We do this after to ensure the main database exists
66+
try:
67+
# Store startup (tests connection)
68+
await dsrc.store.startup()
69+
except StoreObjectError as e:
70+
raise AppError(
71+
ErrorKeys.STARTUP,
72+
"<magenta>Failed to start store! Did you start the databases?</magenta>",
73+
"startup_store_failure",
74+
) from e
75+
7476
# Load keys
7577
logger.debug("Loading keys.")
7678
key_state = await load_keys(dsrc, config)
@@ -88,8 +90,8 @@ async def wait_for_lock_is_first(dsrc: Source) -> bool:
8890
true if it is the first lock since at least 25 seconds (lock expire time)."""
8991
# We sleep for a shor time to increase the distribution in startup times, hopefully reducing race conditions
9092
await sleep(random() + 0.1)
91-
# was_locked = await data.trs.startup.startup_is_locked(dsrc)
92-
was_locked = None
93+
was_locked = await data.trs.startup.startup_is_locked(dsrc)
94+
9395
if was_locked is None:
9496
lock_msg = "First process."
9597
return_val = True

deploy/deploy_tmp/docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
# <volume name in volumes below>:<container destination directory>
1010
# This means the volume will be accessible from the container in the dest. directory in the container
1111
- dodeka-db-volume:/dodeka-db
12-
command: -c config_file=/dodeka-conf/postgresql.conf
12+
command: -c config_file=/dodeka_conf/postgresql.conf
1313
# Some environment variables depend on deployment variables, so we load those in manually
1414
environment:
1515
- PGDATA=/dodeka-db
@@ -30,7 +30,7 @@ services:
3030
timeout: 10s
3131
kv:
3232
container_name: "dodeka-kv-production"
33-
image: "ghcr.io/dsav-dodeka/kv:v3.0.0"
33+
image: "ghcr.io/dsav-dodeka/redis:v3.0.0"
3434
environment:
3535
- REDIS_PASSWORD
3636
ports:

0 commit comments

Comments
 (0)