prod #123

Merged
finley merged 122 commits from prod into master 2025-11-22 17:52:40 -08:00
4 changed files with 61 additions and 10 deletions
Showing only changes of commit 5953bfa8d5 - Show all commits

12
Dockerfile.stg.go Normal file
View file

@ -0,0 +1,12 @@
# Staging/Production Dockerfile for Go server (no Air)
FROM golang:1.24.0 AS builder
WORKDIR /app
COPY go-app/ .
RUN go build -o server ./cmd
FROM debian:bullseye-slim
WORKDIR /app
COPY --from=builder /app/server ./server
COPY go-app/.env.example .env
EXPOSE 8082
CMD ["./server"]

26
conf/nginx-site.stg.conf Normal file
View file

@ -0,0 +1,26 @@
server {
server_name cmclocal;
auth_basic_user_file /etc/nginx/userpasswd;
auth_basic "Restricted";
location /go/ {
proxy_pass http://cmc-stg-go:8082;
proxy_read_timeout 300s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://cmc-stg-php:80;
proxy_read_timeout 300s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
listen 0.0.0.0:80;
# include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
# ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

View file

@ -1,8 +1,17 @@
#!/bin/bash
# Deploy staging environment for cmc-sales
# Usage: ./deploy-stg.sh [--no-cache]
USE_CACHE=true
if [[ "$1" == "--no-cache" ]]; then
USE_CACHE=false
echo "No cache flag detected: will rebuild images without cache."
else
echo "Using cached layers for docker build."
fi
echo "Starting staging deployment for cmc-sales..."
# Variables (edit these as needed)
echo "Setting variables..."
SERVER="cmc"
REPO="git@code.springupsoftware.com:cmc/cmc-sales.git"
@ -12,7 +21,7 @@ STAGING_DIR="cmc-sales-staging"
echo "Connecting to server $SERVER via SSH..."
# Pass variables into SSH session
ssh $SERVER \
"SERVER=$SERVER REPO='$REPO' BRANCH='$BRANCH' STAGING_DIR='$STAGING_DIR' bash -s" << 'ENDSSH'
"SERVER=$SERVER REPO='$REPO' BRANCH='$BRANCH' STAGING_DIR='$STAGING_DIR' USE_CACHE='$USE_CACHE' bash -s" << 'ENDSSH'
set -e
echo "Connected to $SERVER."
# Clone or update staging branch
@ -42,13 +51,19 @@ SMTP_FROM="CMC Sales <sales@cmctechnologies.com.au>"
ENVEOF
fi
echo "Starting docker compose for staging..."
# Start docker compose (edit file name if needed)
docker compose -f docker-compose.yml -f docker-compose.stg.yml up -d
if [[ "$USE_CACHE" == "false" ]]; then
echo "Building and starting docker compose for staging (no cache)..."
docker compose -f docker-compose.stg.yml build --no-cache
docker compose -f docker-compose.stg.yml up -d
else
echo "Building and starting docker compose for staging (using cache)..."
docker compose -f docker-compose.stg.yml build
docker compose -f docker-compose.stg.yml up -d
fi
echo "Checking running containers..."
# Check containers
docker compose ps
docker compose -f docker-compose.stg.yml ps
echo "Creating sync script for staging directories..."
# Create sync script for staging dirs

View file

@ -48,7 +48,7 @@ services:
cmc-stg-go:
build:
context: .
dockerfile: Dockerfile.go
dockerfile: Dockerfile.stg.go
container_name: cmc-stg-go
environment:
DB_HOST: db
@ -63,9 +63,7 @@ services:
ports:
- "8082:8082"
volumes:
- ./go-app:/app
- ./go-app/.air.toml:/root/.air.toml
- ./go-app/.env.example:/root/.env
- ./go-app/.env.example:/app/.env
networks:
- cmc-stg-network
restart: unless-stopped