forked from mtusi2026/mtusi2026lab4
Lab4
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
import time
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
|
||||
client = boto3.client(
|
||||
's3', endpoint_url=os.getenv('S3_ENDPOINT', 'http://s3:8333'),
|
||||
region_name='us-east-1',
|
||||
aws_access_key_id=os.environ['S3_ACCESS_KEY_ID'],
|
||||
aws_secret_access_key=os.environ['S3_SECRET_ACCESS_KEY'],
|
||||
config=Config(connect_timeout=3, read_timeout=5, retries={'max_attempts': 1}),
|
||||
)
|
||||
bucket = os.getenv('S3_BUCKET', 'messenger-attachments')
|
||||
for attempt in range(60):
|
||||
try:
|
||||
buckets = [x['Name'] for x in client.list_buckets().get('Buckets', [])]
|
||||
if bucket not in buckets:
|
||||
client.create_bucket(Bucket=bucket)
|
||||
print('Private S3 bucket ready:', bucket)
|
||||
break
|
||||
except Exception as exc:
|
||||
print('Waiting for S3:', str(exc), flush=True)
|
||||
if attempt == 59:
|
||||
raise
|
||||
time.sleep(2)
|
||||
@@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
cd /d "%~dp0.."
|
||||
|
||||
echo Restarting PostgreSQL and S3...
|
||||
docker compose --env-file .env restart postgres s3
|
||||
if errorlevel 1 exit /b 1
|
||||
|
||||
echo Waiting for storage...
|
||||
timeout /t 12 /nobreak >nul
|
||||
|
||||
echo Restarting API replicas and load balancer...
|
||||
docker compose --env-file .env restart api1 api2 lb
|
||||
if errorlevel 1 exit /b 1
|
||||
|
||||
echo Waiting for API...
|
||||
timeout /t 5 /nobreak >nul
|
||||
|
||||
exit /b 0
|
||||
@@ -0,0 +1,14 @@
|
||||
@echo off
|
||||
cd /d "%~dp0.."
|
||||
|
||||
if /I "%TARGET_INSTANCE_ID%"=="api1" (
|
||||
docker compose --env-file .env stop api1 >nul 2>&1
|
||||
exit /b %errorlevel%
|
||||
)
|
||||
|
||||
if /I "%TARGET_INSTANCE_ID%"=="api2" (
|
||||
docker compose --env-file .env stop api2 >nul 2>&1
|
||||
exit /b %errorlevel%
|
||||
)
|
||||
|
||||
exit /b 1
|
||||
Reference in New Issue
Block a user