forked from mtusi2026/mtusi2026lab4
Реализовать лабораторную работу 4
This commit is contained in:
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
root="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
|
||||
exec docker compose --project-name mtusi2026lab4 --project-directory "$root" "$@"
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
import secrets,json,os
|
||||
os.umask(0o077)
|
||||
p=Path(__file__).resolve().parents[1]/'secrets';p.mkdir(exist_ok=True)
|
||||
def secret(name,size=24):
|
||||
f=p/name
|
||||
if not f.exists(): f.write_text(secrets.token_hex(size))
|
||||
return f.read_text().strip()
|
||||
pw=secret('postgres_password')
|
||||
f=p/'database_url'
|
||||
if not f.exists(): f.write_text('Host=postgres;Port=5432;Database=messenger;Username=messenger;Password='+pw)
|
||||
admin=secret('s3_admin_access',12); admin_secret=secret('s3_admin_secret')
|
||||
access=secret('s3_access',12); key=secret('s3_secret')
|
||||
config={'identities':[
|
||||
{'name':'bootstrap','credentials':[{'accessKey':admin,'secretKey':admin_secret}],'actions':['Admin','Read','Write','List','Tagging']},
|
||||
{'name':'messenger','credentials':[{'accessKey':access,'secretKey':key}],'actions':['Read:messenger','Write:messenger','List:messenger']}]}
|
||||
(p/'s3_config').write_text(json.dumps(config))
|
||||
print('Local secrets ready')
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
exec python3 "$(dirname "$0")/init-secrets.py"
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
./scripts/compose.sh restart postgres redis s3
|
||||
./scripts/compose.sh up -d --wait --wait-timeout 60 postgres redis s3
|
||||
./scripts/compose.sh restart api lb
|
||||
./scripts/compose.sh up -d --wait --wait-timeout 60 api lb
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
test -n "${TARGET_INSTANCE_ID:-}" || { echo "TARGET_INSTANCE_ID is required" >&2; exit 1; }
|
||||
for id in $(./scripts/compose.sh ps -q api); do
|
||||
instance="$(docker exec "$id" curl -fsS -D - -o /dev/null http://127.0.0.1:8080/health/live | tr -d '\r' | awk 'tolower($1) == "x-instance-id:" { print $2 }')"
|
||||
if [ "$instance" = "$TARGET_INSTANCE_ID" ]; then
|
||||
docker stop --time 8 "$id" >/dev/null
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
echo "Requested API instance was not found" >&2
|
||||
exit 1
|
||||
Reference in New Issue
Block a user