diff --git a/Dockerfile.stg.go b/Dockerfile.stg.go new file mode 100644 index 00000000..203de053 --- /dev/null +++ b/Dockerfile.stg.go @@ -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"] diff --git a/conf/nginx-site.stg.conf b/conf/nginx-site.stg.conf new file mode 100644 index 00000000..52f0d990 --- /dev/null +++ b/conf/nginx-site.stg.conf @@ -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 + +} diff --git a/deploy/deploy-stg.sh b/deploy/deploy-stg.sh index 35a7476b..6b235f87 100755 --- a/deploy/deploy-stg.sh +++ b/deploy/deploy-stg.sh @@ -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 " 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 diff --git a/docker-compose.stg.yml b/docker-compose.stg.yml index d8724e65..bca186bf 100644 --- a/docker-compose.stg.yml +++ b/docker-compose.stg.yml @@ -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