Trying to improve stg

This commit is contained in:
Finley Ghosh 2025-07-29 22:12:04 +10:00
parent e1a3d20332
commit 9e20068f8c
6 changed files with 29 additions and 45 deletions

View file

@ -1,4 +1,3 @@
# Staging/Production Dockerfile for Go server (no Air)
FROM golang:1.24-alpine AS builder
RUN apk add --no-cache git

View file

@ -73,26 +73,26 @@ ENVEOF
# Check containers
docker compose -f docker-compose.stg.yml ps
echo "Creating restore script for database from backups..."
# echo "Creating restore script for database from backups..."
# Create restore script for database from backups
cat > /home/cmc/restore_db_from_backup.sh <<'EOF'
# cat > /home/cmc/restore_db_from_backup.sh <<'EOF'
#!/bin/bash
LATEST_BACKUP=$(ls -t /backups/backup_*.sql.gz | head -n1)
echo "Restoring database from latest backup: $LATEST_BACKUP"
if [ -f "$LATEST_BACKUP" ]; then
gunzip < "$LATEST_BACKUP" | mariadb -h 127.0.0.1 -u cmc -p"xVRQI&cA?7AU=hqJ!%au" cmc
echo "Database restore complete."
else
echo "No backup file found in /backups. Skipping database restore."
fi
EOF
chmod +x /home/cmc/restore_db_from_backup.sh
# LATEST_BACKUP=$(ls -t /backups/backup_*.sql.gz | head -n1)
# echo "Restoring database from latest backup: $LATEST_BACKUP"
# if [ -f "$LATEST_BACKUP" ]; then
# gunzip < "$LATEST_BACKUP" | mariadb -h 127.0.0.1 -u cmc -p"xVRQI&cA?7AU=hqJ!%au" cmc
# echo "Database restore complete."
# else
# echo "No backup file found in /backups. Skipping database restore."
# fi
# EOF
# chmod +x /home/cmc/restore_db_from_backup.sh
echo "Creating sync script for staging directories..."
# Create sync script for staging dirs
cat > /home/cmc/sync_prod_to_staging.sh <<'EOF'
#!/bin/bash
/home/cmc/restore_db_from_backup.sh
# /home/cmc/restore_db_from_backup.sh
# echo "Syncing PDF files..."
# rsync -av --delete --omit-dir-times --no-perms --progress /mnt/vault/pdf/ /home/cmc/cmc-sales-staging/app/webroot/pdf/
@ -111,10 +111,10 @@ EOF
(crontab -l 2>/dev/null | grep -q '/home/cmc/sync_prod_to_staging.sh') || \
(crontab -l 2>/dev/null; echo '0 3 * * * /home/cmc/sync_prod_to_staging.sh') | crontab -
if [[ "$RUN_SYNC" == "true" ]]; then
echo "Running sync_prod_to_staging.sh now..."
/home/cmc/sync_prod_to_staging.sh
fi
# if [[ "$RUN_SYNC" == "true" ]]; then
# echo "Running sync_prod_to_staging.sh now..."
# /home/cmc/sync_prod_to_staging.sh
# fi
echo "Deployment complete."
ENDSSH

View file

@ -18,11 +18,14 @@ services:
context: .
dockerfile: Dockerfile_stg
container_name: cmc-stg-php
depends_on:
- db
environment:
MAIL_HOST: mailpit
MAIL_PORT: 1025
DB_HOST: "172.17.0.1" # Updated to prod DB host
DB_PORT: 3306
DB_USER: cmc
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
DB_NAME: cmc
volumes:
- /var/www/cmc-sales/app/webroot:/var/www/cmc-sales/app/webroot:ro
- ./userpasswd:/etc/nginx/userpasswd:ro
@ -30,36 +33,18 @@ services:
- cmc-stg-network
restart: unless-stopped
db:
image: mariadb:latest
container_name: db
environment:
MYSQL_ROOT_PASSWORD: secureRootPassword
MYSQL_DATABASE: cmc
MYSQL_USER: cmc
MYSQL_PASSWORD: xVRQI&cA?7AU=hqJ!%au
volumes:
- stg_db_data:/var/lib/mysql
ports:
- "3307:3306" # Staging DB on different port
networks:
- cmc-stg-network
cmc-stg-go:
build:
context: .
dockerfile: Dockerfile.stg.go
container_name: cmc-stg-go
environment:
DB_HOST: db
DB_HOST: "172.17.0.1" # Updated to prod DB host
DB_PORT: 3306
DB_USER: cmc
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
DB_NAME: cmc
PORT: 8082
depends_on:
db:
condition: service_started
ports:
- "8082:8082"
volumes:
@ -78,8 +63,5 @@ services:
- cmc-stg-network
restart: unless-stopped
volumes:
stg_db_data:
networks:
cmc-stg-network:

View file

@ -266,6 +266,10 @@ func main() {
// Checks quotes for reminders and expiry notices
quoteHandler.DailyQuoteExpirationCheck()
})
s.Every(1).Minute().Do(func() {
// Checks quotes for reminders and expiry notices
quoteHandler.DailyQuoteExpirationCheck()
})
s.StartAsync()
}()

View file

@ -294,7 +294,6 @@ func (h *QuotesHandler) DailyQuoteExpirationCheck() {
reminderJobs := []quoteReminderJob{
{7, FirstReminder, "Reminder: Quote %s Expires Soon", "quotes/first_reminder.html"},
{-7, SecondReminder, "Follow-Up: Quote %s Expired", "quotes/second_reminder.html"},
{-44, ThirdReminder, "Final Reminder: Quote %s Closed", "quotes/final_reminder.html"}, // TODO: remove this its a tester
{-60, ThirdReminder, "Final Reminder: Quote %s Closed", "quotes/final_reminder.html"},
}

Binary file not shown.