Minor fixes"
This commit is contained in:
parent
fac6d0254a
commit
0d440132ca
21
deploy/deploy-stg.sh
Normal file → Executable file
21
deploy/deploy-stg.sh
Normal file → Executable file
|
|
@ -1,22 +1,29 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Deploy staging environment for cmc-sales
|
# Deploy staging environment for cmc-sales
|
||||||
|
|
||||||
|
echo "Starting staging deployment for cmc-sales..."
|
||||||
# Variables (edit these as needed)
|
# Variables (edit these as needed)
|
||||||
|
echo "Setting variables..."
|
||||||
SERVER="cmc"
|
SERVER="cmc"
|
||||||
REPO="code.springupsoftware.com/cmc/cmc-sales.git"
|
REPO="git@code.springupsoftware.com:cmc/cmc-sales.git"
|
||||||
BRANCH="stg"
|
BRANCH="stg"
|
||||||
STAGING_DIR="cmc-sales-staging"
|
STAGING_DIR="cmc-sales-staging"
|
||||||
|
|
||||||
# SSH and deploy
|
echo "Connecting to server $SERVER via SSH..."
|
||||||
ssh $SERVER << 'ENDSSH'
|
# Pass variables into SSH session
|
||||||
|
ssh $SERVER \
|
||||||
|
"SERVER=$SERVER REPO='$REPO' BRANCH='$BRANCH' STAGING_DIR='$STAGING_DIR' bash -s" << 'ENDSSH'
|
||||||
set -e
|
set -e
|
||||||
|
echo "Connected to $SERVER."
|
||||||
# Clone or update staging branch
|
# Clone or update staging branch
|
||||||
if [ -d "$STAGING_DIR" ]; then
|
if [ -d "$STAGING_DIR" ]; then
|
||||||
|
echo "Updating existing staging directory $STAGING_DIR..."
|
||||||
cd "$STAGING_DIR"
|
cd "$STAGING_DIR"
|
||||||
git fetch origin
|
git fetch origin
|
||||||
git checkout $BRANCH
|
git checkout $BRANCH
|
||||||
git pull origin $BRANCH
|
git pull origin $BRANCH
|
||||||
else
|
else
|
||||||
|
echo "Cloning repository $REPO to $STAGING_DIR..."
|
||||||
git clone -b $BRANCH $REPO $STAGING_DIR
|
git clone -b $BRANCH $REPO $STAGING_DIR
|
||||||
cd "$STAGING_DIR"
|
cd "$STAGING_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
@ -24,6 +31,7 @@ ssh $SERVER << 'ENDSSH'
|
||||||
# Create .env file for go-app if it doesn't exist
|
# Create .env file for go-app if it doesn't exist
|
||||||
ENV_PATH="/home/cmc/$STAGING_DIR/go-app/.env"
|
ENV_PATH="/home/cmc/$STAGING_DIR/go-app/.env"
|
||||||
if [ ! -f "$ENV_PATH" ]; then
|
if [ ! -f "$ENV_PATH" ]; then
|
||||||
|
echo "Creating .env file for go-app..."
|
||||||
cat > "$ENV_PATH" <<'ENVEOF'
|
cat > "$ENV_PATH" <<'ENVEOF'
|
||||||
# Environment variables for Go app mail configuration
|
# Environment variables for Go app mail configuration
|
||||||
SMTP_HOST="host.docker.internal"
|
SMTP_HOST="host.docker.internal"
|
||||||
|
|
@ -34,12 +42,15 @@ SMTP_FROM="CMC Sales <sales@cmctechnologies.com.au>"
|
||||||
ENVEOF
|
ENVEOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Starting docker compose for staging..."
|
||||||
# Start docker compose (edit file name if needed)
|
# Start docker compose (edit file name if needed)
|
||||||
docker compose -f docker-compose.yml -f docker-compose.stg.yml up -d
|
docker compose -f docker-compose.yml -f docker-compose.stg.yml up -d
|
||||||
|
|
||||||
|
echo "Checking running containers..."
|
||||||
# Check containers
|
# Check containers
|
||||||
docker compose ps
|
docker compose ps
|
||||||
|
|
||||||
|
echo "Creating sync script for staging directories..."
|
||||||
# Create sync script for staging dirs
|
# Create sync script for staging dirs
|
||||||
cat > /home/cmc/sync_prod_to_staging.sh <<'EOF'
|
cat > /home/cmc/sync_prod_to_staging.sh <<'EOF'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
@ -50,7 +61,9 @@ rsync -a --delete /mnt/vault/vaultmsgs/ /home/cmc/cmc-sales-staging/vault/vaultm
|
||||||
EOF
|
EOF
|
||||||
chmod +x /home/cmc/sync_prod_to_staging.sh
|
chmod +x /home/cmc/sync_prod_to_staging.sh
|
||||||
|
|
||||||
|
echo "Ensuring cron job for sync script is present..."
|
||||||
# Add cron job if not present
|
# 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 | 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 -
|
(crontab -l 2>/dev/null; echo '0 3 * * * /home/cmc/sync_prod_to_staging.sh') | crontab -
|
||||||
|
echo "Deployment complete."
|
||||||
ENDSSH
|
ENDSSH
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ services:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile_stg
|
dockerfile: Dockerfile_stg
|
||||||
platform: linux/amd64
|
|
||||||
container_name: cmc-stg-php
|
container_name: cmc-stg-php
|
||||||
depends_on:
|
depends_on:
|
||||||
- cmc-stg-db
|
- cmc-stg-db
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue