delpoyment with fully dockerized project on wixur.ir, dyolink docker hub created beside backend and frontend image is uploaded.
This commit is contained in:
0
infrastructure/scripts/backup.sh
Normal file → Executable file
0
infrastructure/scripts/backup.sh
Normal file → Executable file
48
infrastructure/scripts/build-and-push-prod.sh
Executable file
48
infrastructure/scripts/build-and-push-prod.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
INFRA_DIR="$SCRIPT_DIR/.."
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
DOMAIN="${1:-wixur.ir}"
|
||||
TAG="${2:-latest}"
|
||||
DOCKER_USERNAME="${DOCKER_USERNAME:-dyolink}"
|
||||
PUBLIC_BASE="https://${DOMAIN}"
|
||||
|
||||
echo -e "${BLUE}Building Dyolink images for ${PUBLIC_BASE}${NC}"
|
||||
echo -e "${YELLOW}Docker Hub: ${DOCKER_USERNAME}/dyolink-*:${TAG}${NC}"
|
||||
|
||||
if ! docker info >/dev/null 2>&1; then
|
||||
echo "Docker is not running."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Ensure you are logged in: docker login${NC}"
|
||||
|
||||
docker build \
|
||||
-t "${DOCKER_USERNAME}/dyolink-backend:${TAG}" \
|
||||
-t "${DOCKER_USERNAME}/dyolink-backend:latest" \
|
||||
"${REPO_ROOT}/backend"
|
||||
|
||||
docker build \
|
||||
--build-arg "NEXT_PUBLIC_API_URL=${PUBLIC_BASE}/api" \
|
||||
--build-arg "NEXT_PUBLIC_APP_URL=${PUBLIC_BASE}" \
|
||||
--build-arg "NEXT_PUBLIC_APP_NAME=Dyolink" \
|
||||
-t "${DOCKER_USERNAME}/dyolink-frontend:${TAG}" \
|
||||
-t "${DOCKER_USERNAME}/dyolink-frontend:latest" \
|
||||
"${REPO_ROOT}/frontend"
|
||||
|
||||
docker push "${DOCKER_USERNAME}/dyolink-backend:${TAG}"
|
||||
docker push "${DOCKER_USERNAME}/dyolink-backend:latest"
|
||||
docker push "${DOCKER_USERNAME}/dyolink-frontend:${TAG}"
|
||||
docker push "${DOCKER_USERNAME}/dyolink-frontend:latest"
|
||||
|
||||
echo -e "${GREEN}Pushed:${NC}"
|
||||
echo " ${DOCKER_USERNAME}/dyolink-backend:${TAG}"
|
||||
echo " ${DOCKER_USERNAME}/dyolink-frontend:${TAG}"
|
||||
2
infrastructure/scripts/build-and-push.sh
Normal file → Executable file
2
infrastructure/scripts/build-and-push.sh
Normal file → Executable file
@@ -85,6 +85,8 @@ echo "JWT_SECRET=CHANGE_ME_32_CHARS_MINIMUM" >> $DEPLOY_DIR/backend.env.example
|
||||
echo "DATABASE_URL=postgresql://\${POSTGRES_USER}:\${POSTGRES_PASSWORD}@postgres:5432/\${POSTGRES_DB}" >> $DEPLOY_DIR/backend.env.example
|
||||
echo "CORS_ORIGIN=https://dyolink.com" >> $DEPLOY_DIR/backend.env.example
|
||||
echo "FRONTEND_URL=https://dyolink.com" >> $DEPLOY_DIR/backend.env.example
|
||||
echo "SMS_IR_API_KEY=CHANGE_ME_SMS_IR_API_KEY" >> $DEPLOY_DIR/backend.env.example
|
||||
echo "SMS_IR_TEMPLATE_ID=123456" >> $DEPLOY_DIR/backend.env.example
|
||||
|
||||
echo "# Frontend" > $DEPLOY_DIR/frontend.env.example
|
||||
echo "NEXT_PUBLIC_API_URL=/api" >> $DEPLOY_DIR/frontend.env.example
|
||||
|
||||
57
infrastructure/scripts/deploy-prod.sh
Executable file
57
infrastructure/scripts/deploy-prod.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
INFRA_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$INFRA_DIR"
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
|
||||
echo -e "${BLUE}║ Dyolink — Production Deploy ║${NC}"
|
||||
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
|
||||
|
||||
if [ ! -f .env ]; then
|
||||
echo -e "${RED}Missing .env — copy deploy.prod.env.example to .env${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source .env
|
||||
set +a
|
||||
|
||||
SECRETS_DIR="${DEPLOY_SECRETS_DIR:-./secrets}"
|
||||
if [ ! -f "${SECRETS_DIR}/database.env" ] || [ ! -f "${SECRETS_DIR}/backend.env" ]; then
|
||||
echo -e "${RED}Missing secrets in ${SECRETS_DIR}/${NC}"
|
||||
echo " Need: database.env and backend.env"
|
||||
echo " Copy from database.prod.env.example and backend.prod.env.example"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COMPOSE=(docker compose -f docker-compose.prod.yml --env-file .env)
|
||||
|
||||
if ! docker volume inspect dyolink_certbot_conf >/dev/null 2>&1 || \
|
||||
! docker run --rm -v dyolink_certbot_conf:/etc/letsencrypt:ro alpine \
|
||||
test -f "/etc/letsencrypt/live/${DOMAIN}/fullchain.pem" 2>/dev/null; then
|
||||
echo -e "${YELLOW}No SSL certificate yet — running init-letsencrypt.sh first...${NC}"
|
||||
./scripts/init-letsencrypt.sh
|
||||
else
|
||||
./scripts/render-nginx-ssl.sh
|
||||
echo -e "${YELLOW}Pulling images...${NC}"
|
||||
"${COMPOSE[@]}" pull backend frontend
|
||||
echo -e "${YELLOW}Starting stack...${NC}"
|
||||
"${COMPOSE[@]}" up -d --force-recreate nginx
|
||||
"${COMPOSE[@]}" up -d
|
||||
fi
|
||||
|
||||
sleep 8
|
||||
echo -e "\n${GREEN}=== Status ===${NC}"
|
||||
"${COMPOSE[@]}" ps
|
||||
|
||||
echo -e "\n${BLUE}App URL: https://${DOMAIN}${NC}"
|
||||
echo -e "${BLUE}API health: https://${DOMAIN}/api/health${NC}"
|
||||
0
infrastructure/scripts/deploy.sh
Normal file → Executable file
0
infrastructure/scripts/deploy.sh
Normal file → Executable file
76
infrastructure/scripts/init-letsencrypt.sh
Executable file
76
infrastructure/scripts/init-letsencrypt.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
INFRA_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$INFRA_DIR"
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
if [ ! -f .env ]; then
|
||||
echo -e "${RED}Missing .env — copy deploy.prod.env.example to .env${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source .env
|
||||
set +a
|
||||
|
||||
: "${DOMAIN:?Set DOMAIN in .env}"
|
||||
: "${LETSENCRYPT_EMAIL:?Set LETSENCRYPT_EMAIL in .env}"
|
||||
|
||||
COMPOSE=(docker compose -f docker-compose.prod.yml --env-file .env)
|
||||
|
||||
mkdir -p nginx/generated logs/nginx database/backups
|
||||
|
||||
CERT_PATH="certbot_conf/live/${DOMAIN}/fullchain.pem"
|
||||
if docker volume inspect dyolink_certbot_conf >/dev/null 2>&1; then
|
||||
if docker run --rm -v dyolink_certbot_conf:/etc/letsencrypt:ro alpine \
|
||||
test -f "/etc/letsencrypt/live/${DOMAIN}/fullchain.pem"; then
|
||||
echo -e "${GREEN}Certificate already exists for ${DOMAIN}${NC}"
|
||||
./scripts/render-nginx-ssl.sh
|
||||
"${COMPOSE[@]}" up -d --force-recreate nginx
|
||||
"${COMPOSE[@]}" up -d
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Phase 1: bootstrap nginx (HTTP) for ACME challenge...${NC}"
|
||||
cp nginx/nginx.bootstrap.conf nginx/generated/default.conf
|
||||
"${COMPOSE[@]}" up -d nginx
|
||||
|
||||
echo -e "${YELLOW}Phase 2: request Let's Encrypt certificate...${NC}"
|
||||
CERTBOT_ARGS=(
|
||||
certonly
|
||||
--webroot
|
||||
-w /var/www/certbot
|
||||
--email "$LETSENCRYPT_EMAIL"
|
||||
--agree-tos
|
||||
--no-eff-email
|
||||
-d "$DOMAIN"
|
||||
)
|
||||
|
||||
if [ -n "${CERTBOT_EXTRA_DOMAINS:-}" ]; then
|
||||
for extra in $CERTBOT_EXTRA_DOMAINS; do
|
||||
CERTBOT_ARGS+=(-d "$extra")
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "${LETSENCRYPT_STAGING:-0}" = "1" ]; then
|
||||
CERTBOT_ARGS+=(--staging)
|
||||
echo -e "${YELLOW}Using Let's Encrypt staging (test) certificates${NC}"
|
||||
fi
|
||||
|
||||
"${COMPOSE[@]}" run --rm --entrypoint certbot certbot "${CERTBOT_ARGS[@]}"
|
||||
|
||||
echo -e "${YELLOW}Phase 3: enable HTTPS nginx config...${NC}"
|
||||
./scripts/render-nginx-ssl.sh
|
||||
"${COMPOSE[@]}" up -d --force-recreate nginx
|
||||
"${COMPOSE[@]}" up -d
|
||||
|
||||
echo -e "${GREEN}SSL ready for https://${DOMAIN}${NC}"
|
||||
echo -e "${GREEN}Certbot renewal container is running (checks every 12h).${NC}"
|
||||
0
infrastructure/scripts/logs.sh
Normal file → Executable file
0
infrastructure/scripts/logs.sh
Normal file → Executable file
0
infrastructure/scripts/manage.sh
Normal file → Executable file
0
infrastructure/scripts/manage.sh
Normal file → Executable file
0
infrastructure/scripts/monitor.sh
Normal file → Executable file
0
infrastructure/scripts/monitor.sh
Normal file → Executable file
Reference in New Issue
Block a user