Adding stg deploy script
This commit is contained in:
parent
eb10de500c
commit
fac6d0254a
56
deploy/deploy-stg.sh
Normal file
56
deploy/deploy-stg.sh
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#!/bin/bash
|
||||
# Deploy staging environment for cmc-sales
|
||||
|
||||
# Variables (edit these as needed)
|
||||
SERVER="cmc"
|
||||
REPO="code.springupsoftware.com/cmc/cmc-sales.git"
|
||||
BRANCH="stg"
|
||||
STAGING_DIR="cmc-sales-staging"
|
||||
|
||||
# SSH and deploy
|
||||
ssh $SERVER << 'ENDSSH'
|
||||
set -e
|
||||
# Clone or update staging branch
|
||||
if [ -d "$STAGING_DIR" ]; then
|
||||
cd "$STAGING_DIR"
|
||||
git fetch origin
|
||||
git checkout $BRANCH
|
||||
git pull origin $BRANCH
|
||||
else
|
||||
git clone -b $BRANCH $REPO $STAGING_DIR
|
||||
cd "$STAGING_DIR"
|
||||
fi
|
||||
|
||||
# Create .env file for go-app if it doesn't exist
|
||||
ENV_PATH="/home/cmc/$STAGING_DIR/go-app/.env"
|
||||
if [ ! -f "$ENV_PATH" ]; then
|
||||
cat > "$ENV_PATH" <<'ENVEOF'
|
||||
# Environment variables for Go app mail configuration
|
||||
SMTP_HOST="host.docker.internal"
|
||||
SMTP_PORT=1025
|
||||
SMTP_USER=""
|
||||
SMTP_PASS=""
|
||||
SMTP_FROM="CMC Sales <sales@cmctechnologies.com.au>"
|
||||
ENVEOF
|
||||
fi
|
||||
|
||||
# Start docker compose (edit file name if needed)
|
||||
docker compose -f docker-compose.yml -f docker-compose.stg.yml up -d
|
||||
|
||||
# Check containers
|
||||
docker compose ps
|
||||
|
||||
# Create sync script for staging dirs
|
||||
cat > /home/cmc/sync_prod_to_staging.sh <<'EOF'
|
||||
#!/bin/bash
|
||||
rsync -a --delete /mnt/vault/pdf/ /home/cmc/cmc-sales-staging/app/webroot/pdf/
|
||||
rsync -a --delete /mnt/vault/attachments_files/ /home/cmc/cmc-sales-staging/app/webroot/attachments_files/
|
||||
rsync -a --delete /mnt/vault/emails/ /home/cmc/cmc-sales-staging/vault/emails/
|
||||
rsync -a --delete /mnt/vault/vaultmsgs/ /home/cmc/cmc-sales-staging/vault/vaultmsgs/
|
||||
EOF
|
||||
chmod +x /home/cmc/sync_prod_to_staging.sh
|
||||
|
||||
# Add cron job if not present
|
||||
(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 -
|
||||
ENDSSH
|
||||
88
docker-compose.stg.yml
Normal file
88
docker-compose.stg.yml
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
services:
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
hostname: nginx-stg
|
||||
ports:
|
||||
- "8081:80" # Staging nginx on different port
|
||||
volumes:
|
||||
- ./conf/nginx-site.conf:/etc/nginx/conf.d/cmc.conf
|
||||
- ./userpasswd:/etc/nginx/userpasswd:ro
|
||||
depends_on:
|
||||
- cmc-stg-php
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- cmc-stg-network
|
||||
|
||||
cmc-stg-php:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile_stg
|
||||
platform: linux/amd64
|
||||
container_name: cmc-stg-php
|
||||
depends_on:
|
||||
- cmc-stg-db
|
||||
environment:
|
||||
MAIL_HOST: mailpit
|
||||
MAIL_PORT: 1025
|
||||
volumes:
|
||||
- ./app/webroot/pdf:/var/www/cmc-sales/app/webroot/pdf
|
||||
- ./app/webroot/attachments_files:/var/www/cmc-sales/app/webroot/attachments_files
|
||||
networks:
|
||||
- cmc-stg-network
|
||||
restart: unless-stopped
|
||||
|
||||
cmc-stg-db:
|
||||
image: mariadb:latest
|
||||
container_name: cmc-stg-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.go
|
||||
container_name: cmc-stg-go
|
||||
environment:
|
||||
DB_HOST: db
|
||||
DB_PORT: 3306
|
||||
DB_USER: cmc
|
||||
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
|
||||
DB_NAME: cmc
|
||||
PORT: 8082
|
||||
depends_on:
|
||||
cmc-stg-db:
|
||||
condition: service_started
|
||||
ports:
|
||||
- "8082:8082"
|
||||
volumes:
|
||||
- ./go-app:/app
|
||||
- ./go-app/.air.toml:/root/.air.toml
|
||||
- ./go-app/.env.example:/root/.env
|
||||
networks:
|
||||
- cmc-stg-network
|
||||
restart: unless-stopped
|
||||
|
||||
mailpit:
|
||||
image: axllent/mailpit:latest
|
||||
container_name: mailpit
|
||||
ports:
|
||||
- "8025:8025" # Mailpit web UI
|
||||
- "1025:1025" # SMTP
|
||||
networks:
|
||||
- cmc-stg-network
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
stg_db_data:
|
||||
|
||||
networks:
|
||||
cmc-stg-network:
|
||||
Loading…
Reference in a new issue