Initial commit: Full project structure

- Backend: NestJS with Docker
- Frontend: Next.js with Docker
- Nginx configuration for reverse proxy
- PostgreSQL setup
- Docker compose for orchestration
- Development environment configuration
This commit is contained in:
2026-04-23 15:33:11 +03:30
commit 26bd35ae3c
94 changed files with 5627 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
#!/bin/bash
set -e
BACKUP_DIR="/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="dyolink_backup_$TIMESTAMP"
BACKUP_FILE="$BACKUP_DIR/$BACKUP_NAME.sql.gz"
echo "[$(date)] Starting database backup: $BACKUP_NAME"
# Perform backup
pg_dumpall -U $POSTGRES_USER | gzip > $BACKUP_FILE
if [ $? -eq 0 ]; then
BACKUP_SIZE=$(du -h $BACKUP_FILE | cut -f1)
echo "[$(date)] ✅ Backup completed: $BACKUP_NAME ($BACKUP_SIZE)"
# Keep only last 7 days of backups
find $BACKUP_DIR -name "dyolink_backup_*.sql.gz" -mtime +7 -delete
echo "[$(date)] Cleaned up backups older than 7 days"
else
echo "[$(date)] ❌ Backup failed!"
exit 1
fi

View File

@@ -0,0 +1,105 @@
#!/bin/bash
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Dyolink - Build & Push ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
# Load environment
if [ -f .env ]; then
source .env
echo -e "${GREEN}✓ Loaded .env${NC}"
fi
# Get version
read -p "Enter version tag (e.g., v1.0.0, default: latest): " TAG
TAG=${TAG:-latest}
echo -e "${YELLOW}Using tag: ${TAG}${NC}"
# Get Docker Hub username
read -p "Docker Hub username [${DOCKER_USERNAME:-yourdockerhub}]: " USERNAME
USERNAME=${USERNAME:-${DOCKER_USERNAME:-yourdockerhub}}
# Check Docker
if ! docker info > /dev/null 2>&1; then
echo -e "${RED}✗ Docker is not running!${NC}"
exit 1
fi
# Login
echo -e "${YELLOW}Logging into Docker Hub...${NC}"
docker login --username $USERNAME
echo -e "\n${GREEN}=== Building Images ===${NC}"
# Build backend
echo -e "${YELLOW}Building backend...${NC}"
docker build -t $USERNAME/dyolink-backend:$TAG -t $USERNAME/dyolink-backend:latest ../backend
echo -e "${GREEN}✓ Backend built${NC}"
# Build frontend
echo -e "${YELLOW}Building frontend...${NC}"
docker build -t $USERNAME/dyolink-frontend:$TAG -t $USERNAME/dyolink-frontend:latest ../frontend
echo -e "${GREEN}✓ Frontend built${NC}"
echo -e "\n${GREEN}=== Pushing to Docker Hub ===${NC}"
# Push backend
echo -e "${YELLOW}Pushing backend...${NC}"
docker push $USERNAME/dyolink-backend:$TAG
docker push $USERNAME/dyolink-backend:latest
echo -e "${GREEN}✓ Backend pushed${NC}"
# Push frontend
echo -e "${YELLOW}Pushing frontend...${NC}"
docker push $USERNAME/dyolink-frontend:$TAG
docker push $USERNAME/dyolink-frontend:latest
echo -e "${GREEN}✓ Frontend pushed${NC}"
# Create deployment package
echo -e "\n${YELLOW}Creating deployment package...${NC}"
DEPLOY_DIR="dyolink-deploy-$TAG"
mkdir -p $DEPLOY_DIR
cp docker-compose.prod.yml $DEPLOY_DIR/
cp -r nginx/nginx.conf $DEPLOY_DIR/
cp database/init.sql $DEPLOY_DIR/
cp scripts/deploy.sh $DEPLOY_DIR/
cp .env.example $DEPLOY_DIR/
# Create env templates
echo "# Database" > $DEPLOY_DIR/database.env.example
echo "POSTGRES_USER=dyolink_user" >> $DEPLOY_DIR/database.env.example
echo "POSTGRES_PASSWORD=CHANGE_ME" >> $DEPLOY_DIR/database.env.example
echo "POSTGRES_DB=dyolink_db" >> $DEPLOY_DIR/database.env.example
echo "# Backend" > $DEPLOY_DIR/backend.env.example
echo "NODE_ENV=production" >> $DEPLOY_DIR/backend.env.example
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 "# Frontend" > $DEPLOY_DIR/frontend.env.example
echo "NEXT_PUBLIC_API_URL=/api" >> $DEPLOY_DIR/frontend.env.example
echo "NEXT_PUBLIC_APP_NAME=Dyolink" >> $DEPLOY_DIR/frontend.env.example
echo "NEXT_PUBLIC_APP_URL=https://dyolink.com" >> $DEPLOY_DIR/frontend.env.example
# Package
tar -czf $DEPLOY_DIR.tar.gz $DEPLOY_DIR/
rm -rf $DEPLOY_DIR
echo -e "${GREEN}✓ Created: ${DEPLOY_DIR}.tar.gz${NC}"
echo -e "\n${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Build Complete! ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
echo -e "${GREEN}Pushed:${NC}"
echo -e "${USERNAME}/dyolink-backend:${TAG}"
echo -e "${USERNAME}/dyolink-frontend:${TAG}"
echo -e "\n${YELLOW}Next: scp ${DEPLOY_DIR}.tar.gz user@server:/tmp/${NC}"

View File

@@ -0,0 +1,68 @@
#!/bin/bash
set -e
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 - Deploy Tool ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
# Load environment
if [ -f .env ]; then
source .env
echo -e "${GREEN}✓ Loaded .env${NC}"
fi
# Check for env files
ENV_FILES=("database.env" "backend.env" "frontend.env")
for env_file in "${ENV_FILES[@]}"; do
if [ ! -f "$env_file" ]; then
echo -e "${YELLOW}$env_file not found, creating from example${NC}"
if [ -f "${env_file}.example" ]; then
cp "${env_file}.example" "$env_file"
echo -e "${RED}❕ Edit $env_file with production values!${NC}"
read -p "Continue? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
fi
done
# Create directories
mkdir -p logs/nginx database/backups ssl
# Get version
read -p "Enter version to deploy (default: ${TAG:-latest}): " DEPLOY_TAG
DEPLOY_TAG=${DEPLOY_TAG:-${TAG:-latest}}
export TAG=$DEPLOY_TAG
export DOCKER_USERNAME=${DOCKER_USERNAME:-yourdockerhub}
# Pull images
echo -e "${YELLOW}Pulling images from Docker Hub...${NC}"
docker-compose -f docker-compose.prod.yml pull
# Stop old
echo -e "${YELLOW}Stopping old containers...${NC}"
docker-compose -f docker-compose.prod.yml down
# Start new
echo -e "${YELLOW}Starting containers...${NC}"
docker-compose -f docker-compose.prod.yml up -d
# Wait for health
echo -e "${YELLOW}Waiting for services...${NC}"
sleep 10
# Show status
echo -e "\n${GREEN}=== Status ===${NC}"
docker-compose -f docker-compose.prod.yml ps
echo -e "\n${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Deployment Complete! ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo "=== Dyolink Health Monitor ==="
echo "Time: $(date)"
echo ""
# Check containers
echo "Container Status:"
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Health}}" | grep dyolink
# Check resources
echo -e "\nResource Usage:"
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" | grep dyolink
# Check disk
DISK=$(df -h / | awk 'NR==2 {print $5}' | tr -d '%')
if [ $DISK -gt 80 ]; then
echo -e "\n${RED}⚠ WARNING: Disk usage at ${DISK}%${NC}"
else
echo -e "\n${GREEN}✓ Disk usage: ${DISK}%${NC}"
fi
# Check API
echo -e "\nAPI Health:"
curl -s -o /dev/null -w "Backend API: %{http_code}\n" http://localhost:3001/api/health || echo "Backend API: DOWN"
curl -s -o /dev/null -w "Frontend: %{http_code}\n" http://localhost:3002 || echo "Frontend: DOWN"

View File

@@ -0,0 +1,127 @@
#!/bin/bash
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
COMPOSE_FILE="docker-compose.prod.yml"
show_help() {
echo -e "${BLUE}Dyolink Management Tool${NC}"
echo ""
echo "Usage: $0 {start|stop|restart|logs|status|backup|update|cleanup|monitor}"
echo ""
echo "Commands:"
echo " start - Start all services"
echo " stop - Stop all services"
echo " restart - Restart all services"
echo " logs - Show logs (add -f to follow)"
echo " status - Show container status"
echo " backup - Backup database"
echo " update - Pull and restart with latest images"
echo " cleanup - Clean old containers/images"
echo " monitor - Show health status"
}
check_compose() {
if [ ! -f "$COMPOSE_FILE" ]; then
echo -e "${RED}Error: $COMPOSE_FILE not found${NC}"
exit 1
fi
}
case "$1" in
start)
check_compose
echo -e "${GREEN}Starting services...${NC}"
docker-compose -f $COMPOSE_FILE up -d
;;
stop)
check_compose
echo -e "${YELLOW}Stopping services...${NC}"
docker-compose -f $COMPOSE_FILE down
;;
restart)
check_compose
echo -e "${YELLOW}Restarting services...${NC}"
docker-compose -f $COMPOSE_FILE restart
;;
logs)
check_compose
echo -e "${GREEN}Showing logs...${NC}"
docker-compose -f $COMPOSE_FILE logs ${@:2}
;;
status)
check_compose
echo -e "${GREEN}Container Status:${NC}"
docker-compose -f $COMPOSE_FILE ps
echo -e "\n${GREEN}Running Containers:${NC}"
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep dyolink
;;
backup)
check_compose
echo -e "${GREEN}Backing up database...${NC}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="dyolink_backup_$TIMESTAMP.sql.gz"
docker-compose -f $COMPOSE_FILE exec -T postgres pg_dumpall -U postgres | gzip > $BACKUP_FILE
if [ $? -eq 0 ]; then
SIZE=$(du -h $BACKUP_FILE | cut -f1)
echo -e "${GREEN}✓ Backup saved: $BACKUP_FILE ($SIZE)${NC}"
else
echo -e "${RED}✗ Backup failed${NC}"
fi
;;
update)
check_compose
echo -e "${GREEN}Pulling latest images...${NC}"
docker-compose -f $COMPOSE_FILE pull
docker-compose -f $COMPOSE_FILE up -d
echo -e "${GREEN}✓ Update complete!${NC}"
;;
cleanup)
echo -e "${YELLOW}Cleaning up Docker resources...${NC}"
docker container prune -f
docker image prune -f
docker volume prune -f
docker network prune -f
echo -e "${GREEN}✓ Cleanup complete!${NC}"
;;
monitor)
check_compose
echo -e "${GREEN}Health Monitoring:${NC}\n"
SERVICES=("postgres" "backend" "frontend" "nginx")
ALL_HEALTHY=true
for SERVICE in "${SERVICES[@]}"; do
STATUS=$(docker-compose -f $COMPOSE_FILE ps $SERVICE 2>/dev/null | tail -1)
if echo "$STATUS" | grep -q "Up"; then
echo -e " ${GREEN}${NC} $SERVICE: Running"
else
echo -e " ${RED}${NC} $SERVICE: Not running"
ALL_HEALTHY=false
fi
done
echo ""
DISK=$(df -h / | awk 'NR==2 {print $5}' | tr -d '%')
if [ $DISK -gt 80 ]; then
echo -e "${RED}⚠ Disk usage: ${DISK}%${NC}"
ALL_HEALTHY=false
else
echo -e "${GREEN}✓ Disk usage: ${DISK}%${NC}"
fi
if [ "$ALL_HEALTHY" = true ]; then
echo -e "\n${GREEN}✅ All systems operational${NC}"
else
echo -e "\n${YELLOW}⚠ Issues detected${NC}"
fi
;;
*)
show_help
exit 1
;;
esac

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo "=== Dyolink Health Monitor ==="
echo "Time: $(date)"
echo ""
# Check containers
echo "Container Status:"
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Health}}" | grep dyolink
# Check resources
echo -e "\nResource Usage:"
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" | grep dyolink
# Check disk
DISK=$(df -h / | awk 'NR==2 {print $5}' | tr -d '%')
if [ $DISK -gt 80 ]; then
echo -e "\n${RED}⚠ WARNING: Disk usage at ${DISK}%${NC}"
else
echo -e "\n${GREEN}✓ Disk usage: ${DISK}%${NC}"
fi
# Check API
echo -e "\nAPI Health:"
curl -s -o /dev/null -w "Backend API: %{http_code}\n" http://localhost:3001/api/health || echo "Backend API: DOWN"
curl -s -o /dev/null -w "Frontend: %{http_code}\n" http://localhost:3002 || echo "Frontend: DOWN"