Skip to content

Commit

Permalink
use a docker volume for state
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed Aug 21, 2024
1 parent 02c6425 commit 3af5647
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions base/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@
import petname
from flask import Flask, jsonify

state_base = "/var/lib/private/orijen-udf-base/"
state_base = "/var/lib/state/"

def run_flask(app):
"""Function to run the Flask app on a separate thread."""
app.run(host='0.0.0.0', port=5123)

def save_state(file, state):
"""Save state to a file."""
os.makedirs(os.path.dirname(state_base + file), exist_ok=True)
with open(state_base + file, 'w') as f:
with open(state_base + file, 'w', encoding="utf-8") as f:
f.write(state)

def load_state(file):
"""Load state from a file."""
try:
with open(state_base + file, 'r') as f:
with open(state_base + file, 'r', encoding="utf-8") as f:
return json.load(f)
except FileNotFoundError:
return {}
Expand Down
2 changes: 1 addition & 1 deletion orijen-udf-base-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Restart=always
ExecStartPre=-/usr/bin/docker stop $CONTAINER
ExecStartPre=-/usr/bin/docker rm $CONTAINER
ExecStartPre=/usr/bin/docker pull $IMAGE
ExecStart=/usr/bin/docker run -p 5123:5123 --rm --name $CONTAINER $IMAGE
ExecStart=/usr/bin/docker run -p 5123:5123 -v $CONTAINER:/var/lib/state --rm --name $CONTAINER $IMAGE
ExecStop=/usr/bin/docker stop $CONTAINER
StateDirectory=$CONTAINER
Expand Down

0 comments on commit 3af5647

Please sign in to comment.