vps setup
Some checks failed
Deploy to Railway / deploy (push) Has been cancelled
Network Test / test_network (push) Has been cancelled

This commit is contained in:
Mykhailo Svishchov
2026-03-07 14:36:06 +02:00
parent dafbc677d0
commit 7cbb43dcfa
3 changed files with 548 additions and 22 deletions

View File

@@ -49,8 +49,8 @@ if [ -z "$NGINX_CONF" ]; then
elif [ -f "/etc/nginx/sites-enabled/win-spin.live.conf" ]; then
NGINX_CONF="/etc/nginx/sites-enabled/win-spin.live.conf"
log "Using Nginx config: $NGINX_CONF (sites-enabled - active config)"
elif [ -f "/etc/nginx/conf.d/lottery.conf" ]; then
NGINX_CONF="/etc/nginx/conf.d/lottery.conf"
elif [ -f "/etc/nginx/conf.d/honey.conf" ]; then
NGINX_CONF="/etc/nginx/conf.d/honey.conf"
log "Using Nginx config: $NGINX_CONF (conf.d)"
elif [ -f "/opt/app/nginx/win-spin.live.conf" ]; then
warn "Found config at /opt/app/nginx/win-spin.live.conf"
@@ -74,7 +74,7 @@ if [ -z "$NGINX_CONF" ]; then
error "Searched:"
error " - /etc/nginx/sites-enabled/win-spin.live"
error " - /etc/nginx/sites-enabled/win-spin.live.conf"
error " - /etc/nginx/conf.d/lottery.conf"
error " - /etc/nginx/conf.d/honey.conf"
error " - /opt/app/nginx/win-spin.live.conf"
error ""
error "Please set NGINX_CONF environment variable with the correct path."
@@ -101,15 +101,15 @@ detect_active_backend() {
# Port 8082 is active (not backup)
ACTIVE_PORT=8082
STANDBY_PORT=8080
ACTIVE_CONTAINER="lottery-backend-new"
STANDBY_CONTAINER="lottery-backend"
ACTIVE_CONTAINER="honey-backend-new"
STANDBY_CONTAINER="honey-backend"
log "Detected: Port 8082 is currently active"
else
# Port 8080 is active (default or only one present)
ACTIVE_PORT=8080
STANDBY_PORT=8082
ACTIVE_CONTAINER="lottery-backend"
STANDBY_CONTAINER="lottery-backend-new"
ACTIVE_CONTAINER="honey-backend"
STANDBY_CONTAINER="honey-backend-new"
log "Detected: Port 8080 is currently active"
fi
@@ -230,10 +230,10 @@ start_new_container() {
# Determine which service to start based on standby port
if [ "$STANDBY_PORT" = "8082" ]; then
SERVICE_NAME="backend-new"
CONTAINER_NAME="lottery-backend-new"
CONTAINER_NAME="honey-backend-new"
else
SERVICE_NAME="backend"
CONTAINER_NAME="lottery-backend"
CONTAINER_NAME="honey-backend"
fi
# Check if standby container exists (running or stopped)
@@ -288,9 +288,9 @@ health_check_new_container() {
# First, check if container is still running
if [ "$STANDBY_PORT" = "8082" ]; then
local container_name="lottery-backend-new"
local container_name="honey-backend-new"
else
local container_name="lottery-backend"
local container_name="honey-backend"
fi
if ! docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then
@@ -486,7 +486,7 @@ stop_old_container() {
cd "$PROJECT_DIR"
if [ "$ACTIVE_CONTAINER" = "lottery-backend-new" ]; then
if [ "$ACTIVE_CONTAINER" = "honey-backend-new" ]; then
if $DOCKER_COMPOSE_CMD -f "$COMPOSE_FILE" --profile rolling-update stop backend-new; then
log "✅ Old backend container stopped"
else
@@ -501,7 +501,7 @@ stop_old_container() {
fi
# Optionally remove the old container (comment out if you want to keep it for rollback)
# if [ "$ACTIVE_CONTAINER" = "lottery-backend-new" ]; then
# if [ "$ACTIVE_CONTAINER" = "honey-backend-new" ]; then
# docker-compose -f "$COMPOSE_FILE" --profile rolling-update rm -f backend-new
# else
# docker-compose -f "$COMPOSE_FILE" rm -f backend
@@ -535,22 +535,22 @@ rollback() {
if [ "$STANDBY_PORT" = "8082" ]; then
$DOCKER_COMPOSE_CMD -f "$COMPOSE_FILE" --profile rolling-update stop backend-new || true
warn ""
warn "Container 'lottery-backend-new' is STOPPED but NOT REMOVED"
warn "Container 'honey-backend-new' is STOPPED but NOT REMOVED"
warn ""
warn "To check logs:"
warn " docker logs lottery-backend-new"
warn " docker logs --tail 100 lottery-backend-new"
warn " docker logs honey-backend-new"
warn " docker logs --tail 100 honey-backend-new"
warn ""
warn "To remove manually:"
warn " $DOCKER_COMPOSE_CMD -f $COMPOSE_FILE --profile rolling-update rm -f backend-new"
else
$DOCKER_COMPOSE_CMD -f "$COMPOSE_FILE" stop backend || true
warn ""
warn "Container 'lottery-backend' is STOPPED but NOT REMOVED"
warn "Container 'honey-backend' is STOPPED but NOT REMOVED"
warn ""
warn "To check logs:"
warn " docker logs lottery-backend"
warn " docker logs --tail 100 lottery-backend"
warn " docker logs honey-backend"
warn " docker logs --tail 100 honey-backend"
warn ""
warn "To remove manually:"
warn " $DOCKER_COMPOSE_CMD -f $COMPOSE_FILE rm -f backend"
@@ -568,7 +568,7 @@ rollback() {
# Start old container if it was stopped
if ! docker ps --format '{{.Names}}' | grep -q "^${ACTIVE_CONTAINER}$"; then
if [ "$ACTIVE_CONTAINER" = "lottery-backend-new" ]; then
if [ "$ACTIVE_CONTAINER" = "honey-backend-new" ]; then
$DOCKER_COMPOSE_CMD -f "$COMPOSE_FILE" --profile rolling-update start backend-new || \
$DOCKER_COMPOSE_CMD -f "$COMPOSE_FILE" --profile rolling-update up -d backend-new
else
@@ -614,7 +614,7 @@ main() {
log "To rollback (if needed):"
log " 1. Restore Nginx config: cp $NGINX_CONF_BACKUP $NGINX_CONF"
log " 2. Reload Nginx: systemctl reload nginx"
if [ "$ACTIVE_CONTAINER" = "lottery-backend-new" ]; then
if [ "$ACTIVE_CONTAINER" = "honey-backend-new" ]; then
log " 3. Start old backend: docker-compose -f $COMPOSE_FILE --profile rolling-update start backend-new"
log " 4. Stop new backend: docker-compose -f $COMPOSE_FILE stop backend"
else