Adding sync script to the deploy, changing go dockerfile to multi stage
This commit is contained in:
parent
87caa649ed
commit
049256025a
|
|
@ -1,15 +1,21 @@
|
||||||
# Staging/Production Dockerfile for Go server (no Air)
|
# Staging/Production Dockerfile for Go server (no Air)
|
||||||
FROM golang:1.24.0 AS builder
|
FROM golang:1.24-alpine AS builder
|
||||||
|
|
||||||
|
RUN apk add --no-cache git
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
COPY go-app/go.mod go-app/go.sum ./
|
||||||
|
RUN go mod download
|
||||||
COPY go-app/ .
|
COPY go-app/ .
|
||||||
|
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
||||||
|
RUN sqlc generate
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server cmd/server/main.go
|
||||||
|
|
||||||
|
FROM alpine:latest
|
||||||
|
RUN apk --no-cache add ca-certificates
|
||||||
|
WORKDIR /root/
|
||||||
|
COPY --from=builder /app/server .
|
||||||
COPY go-app/templates ./templates
|
COPY go-app/templates ./templates
|
||||||
COPY go-app/static ./static
|
COPY go-app/static ./static
|
||||||
COPY go-app/.env.example .env
|
COPY go-app/.env.example .env
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server ./cmd/server/main.go
|
|
||||||
|
|
||||||
FROM debian:bullseye-slim
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=builder /app/server ./server
|
|
||||||
COPY go-app/.env.example .env
|
|
||||||
EXPOSE 8082
|
EXPOSE 8082
|
||||||
CMD ["./server"]
|
CMD ["./server"]
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,21 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Deploy staging environment for cmc-sales
|
# Deploy staging environment for cmc-sales
|
||||||
|
|
||||||
# Usage: ./deploy-stg.sh [--no-cache]
|
# Usage: ./deploy-stg.sh [--no-cache] [--no-sync]
|
||||||
|
|
||||||
USE_CACHE=true
|
USE_CACHE=true
|
||||||
if [[ "$1" == "--no-cache" ]]; then
|
RUN_SYNC=true
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [[ "$arg" == "--no-cache" ]]; then
|
||||||
USE_CACHE=false
|
USE_CACHE=false
|
||||||
echo "No cache flag detected: will rebuild images without cache."
|
echo "No cache flag detected: will rebuild images without cache."
|
||||||
else
|
fi
|
||||||
|
if [[ "$arg" == "--no-sync" ]]; then
|
||||||
|
RUN_SYNC=false
|
||||||
|
echo "No-sync flag detected: will NOT run sync_prod_to_staging.sh after deployment."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ "$USE_CACHE" == "true" ]]; then
|
||||||
echo "Using cached layers for docker build."
|
echo "Using cached layers for docker build."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -21,7 +29,7 @@ STAGING_DIR="cmc-sales-staging"
|
||||||
echo "Connecting to server $SERVER via SSH..."
|
echo "Connecting to server $SERVER via SSH..."
|
||||||
# Pass variables into SSH session
|
# Pass variables into SSH session
|
||||||
ssh $SERVER \
|
ssh $SERVER \
|
||||||
"SERVER=$SERVER REPO='$REPO' BRANCH='$BRANCH' STAGING_DIR='$STAGING_DIR' USE_CACHE='$USE_CACHE' bash -s" << 'ENDSSH'
|
"SERVER=$SERVER REPO='$REPO' BRANCH='$BRANCH' STAGING_DIR='$STAGING_DIR' USE_CACHE='$USE_CACHE' RUN_SYNC='$RUN_SYNC' bash -s" << 'ENDSSH'
|
||||||
set -e
|
set -e
|
||||||
echo "Connected to $SERVER."
|
echo "Connected to $SERVER."
|
||||||
# Clone or update staging branch
|
# Clone or update staging branch
|
||||||
|
|
@ -80,5 +88,11 @@ EOF
|
||||||
# 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 -
|
||||||
|
|
||||||
|
if [[ "$RUN_SYNC" == "true" ]]; then
|
||||||
|
echo "Running sync_prod_to_staging.sh now..."
|
||||||
|
/home/cmc/sync_prod_to_staging.sh
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Deployment complete."
|
echo "Deployment complete."
|
||||||
ENDSSH
|
ENDSSH
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue