feat: add Docker deployment configuration
This commit is contained in:
25
.dockerignore
Normal file
25
.dockerignore
Normal file
@@ -0,0 +1,25 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.git
|
||||
.gitignore
|
||||
*.md
|
||||
.vscode
|
||||
.idea
|
||||
*.log
|
||||
dist
|
||||
build
|
||||
coverage
|
||||
.nyc_output
|
||||
playwright-report
|
||||
test-results
|
||||
e2e
|
||||
*.test.ts
|
||||
*.test.tsx
|
||||
*.spec.ts
|
||||
*.spec.tsx
|
||||
vitest.config.ts
|
||||
playwright.config.ts
|
||||
eslint.config.js
|
||||
.qwen
|
||||
*.ico
|
||||
cgg-ico\ copy.png
|
||||
317
DEPLOYMENT.md
Normal file
317
DEPLOYMENT.md
Normal file
@@ -0,0 +1,317 @@
|
||||
# Configucci Docker Deployment Guide
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Local Deployment (Windows/Linux/Mac)
|
||||
|
||||
```bash
|
||||
# Make script executable (Linux/Mac only)
|
||||
chmod +x deploy-docker.sh
|
||||
|
||||
# Deploy locally
|
||||
./deploy-docker.sh
|
||||
|
||||
# Or on Windows (PowerShell)
|
||||
bash deploy-docker.sh
|
||||
```
|
||||
|
||||
### Remote Deployment (Linux Server)
|
||||
|
||||
```bash
|
||||
# Deploy to remote server
|
||||
./deploy-docker.sh user@your-server.com
|
||||
|
||||
# Example
|
||||
./deploy-docker.sh root@192.168.1.100
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Manual Deployment
|
||||
|
||||
### 1. Build and Run Locally
|
||||
|
||||
```bash
|
||||
# Build image
|
||||
docker-compose build
|
||||
|
||||
# Start container
|
||||
docker-compose up -d
|
||||
|
||||
# View logs
|
||||
docker-compose logs -f
|
||||
|
||||
# Stop
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
### 2. Deploy to Linux Server
|
||||
|
||||
#### Option A: Using Deployment Script (Recommended)
|
||||
|
||||
```bash
|
||||
# From your local machine
|
||||
./deploy-docker.sh user@your-server.com
|
||||
```
|
||||
|
||||
#### Option B: Manual Steps on Server
|
||||
|
||||
```bash
|
||||
# SSH to server
|
||||
ssh user@your-server.com
|
||||
|
||||
# Install Docker (if not installed)
|
||||
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||
sudo sh get-docker.sh
|
||||
sudo usermod -aG docker $USER
|
||||
exit
|
||||
|
||||
# SSH again (to apply group changes)
|
||||
ssh user@your-server.com
|
||||
|
||||
# Clone repository
|
||||
git clone https://git.six83.ru/ssa/configucci.git
|
||||
cd configucci
|
||||
|
||||
# Build and run
|
||||
docker-compose build
|
||||
docker-compose up -d
|
||||
|
||||
# View logs
|
||||
docker-compose logs -f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Accessing the Application
|
||||
|
||||
After deployment, access the app at:
|
||||
|
||||
- **Local:** http://localhost
|
||||
- **Server:** http://your-server-ip
|
||||
|
||||
---
|
||||
|
||||
## Useful Docker Commands
|
||||
|
||||
```bash
|
||||
# View running containers
|
||||
docker-compose ps
|
||||
|
||||
# View logs
|
||||
docker-compose logs -f
|
||||
|
||||
# Restart application
|
||||
docker-compose restart
|
||||
|
||||
# Stop application
|
||||
docker-compose down
|
||||
|
||||
# Rebuild and restart
|
||||
docker-compose build --no-cache
|
||||
docker-compose up -d
|
||||
|
||||
# View resource usage
|
||||
docker stats configucci-app
|
||||
|
||||
# Execute command in container
|
||||
docker exec -it configucci-app sh
|
||||
|
||||
# Remove everything (container + image)
|
||||
docker-compose down --rmi all
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Production Setup with SSL
|
||||
|
||||
### 1. Install Nginx Proxy Manager (Recommended)
|
||||
|
||||
```yaml
|
||||
# Add to docker-compose.yml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
proxy:
|
||||
image: jc21/nginx-proxy-manager:latest
|
||||
ports:
|
||||
- "80:80"
|
||||
- "81:81"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- ./data:/data
|
||||
- ./letsencrypt:/etc/letsencrypt
|
||||
restart: unless-stopped
|
||||
|
||||
configucci:
|
||||
# ... existing configucci config
|
||||
```
|
||||
|
||||
Then access `http://your-server:81` to configure SSL via web UI.
|
||||
|
||||
### 2. Or Use Certbot Directly
|
||||
|
||||
```bash
|
||||
# On host server (not in Docker)
|
||||
sudo apt install certbot -y
|
||||
|
||||
# Get certificate
|
||||
sudo certbot certonly --standalone -d your-domain.com
|
||||
|
||||
# Mount certificates in docker-compose.yml
|
||||
volumes:
|
||||
- /etc/letsencrypt:/etc/letsencrypt:ro
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Environment Variables
|
||||
|
||||
You can customize the build by setting environment variables:
|
||||
|
||||
```bash
|
||||
# In docker-compose.yml or .env file
|
||||
GIT_URL=https://git.six83.ru/ssa/configucci.git
|
||||
GIT_BRANCH=ai
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container Won't Start
|
||||
|
||||
```bash
|
||||
# Check logs
|
||||
docker-compose logs
|
||||
|
||||
# Check if port 80 is in use
|
||||
sudo netstat -tlnp | grep :80
|
||||
|
||||
# Use different port
|
||||
# Edit docker-compose.yml: ports: - "8080:80"
|
||||
```
|
||||
|
||||
### Build Fails
|
||||
|
||||
```bash
|
||||
# Clean build cache
|
||||
docker-compose build --no-cache
|
||||
|
||||
# Remove all Docker resources
|
||||
docker system prune -a
|
||||
```
|
||||
|
||||
### Can't Access Application
|
||||
|
||||
```bash
|
||||
# Check firewall
|
||||
sudo ufw status
|
||||
sudo ufw allow 80/tcp
|
||||
|
||||
# Check container is running
|
||||
docker-compose ps
|
||||
|
||||
# Test from server
|
||||
curl http://localhost
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Automated Deployment with CI/CD
|
||||
|
||||
Create `.gitlab-ci.yml` or GitHub Actions workflow:
|
||||
|
||||
```yaml
|
||||
# Example: GitHub Actions
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ai]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Deploy to server
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
cd /opt/configucci
|
||||
git pull
|
||||
docker-compose build --no-cache
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Backup and Restore
|
||||
|
||||
### Backup
|
||||
|
||||
```bash
|
||||
# Backup configuration
|
||||
tar -czf configucci-backup.tar.gz docker-compose.yml nginx.conf
|
||||
```
|
||||
|
||||
### Restore
|
||||
|
||||
```bash
|
||||
tar -xzf configucci-backup.tar.gz
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Monitoring
|
||||
|
||||
### Install Docker Monitoring
|
||||
|
||||
```bash
|
||||
# Install cAdvisor for container monitoring
|
||||
docker run \
|
||||
--volume=/:/rootfs:ro \
|
||||
--volume=/var/run:/var/run:ro \
|
||||
--volume=/sys:/sys:ro \
|
||||
--volume=/var/lib/docker/:/var/lib/docker:ro \
|
||||
--volume=/dev/disk/:/dev/disk:ro \
|
||||
--publish=8080:8080 \
|
||||
--name=cadvisor \
|
||||
google/cadvisor:latest
|
||||
```
|
||||
|
||||
Access at: `http://your-server:8080`
|
||||
|
||||
---
|
||||
|
||||
## Security Recommendations
|
||||
|
||||
1. **Use HTTPS** - Always use SSL in production
|
||||
2. **Firewall** - Only open necessary ports
|
||||
3. **Regular Updates** - Keep Docker and system updated
|
||||
4. **Non-root User** - Run container as non-root
|
||||
5. **Resource Limits** - Set CPU/memory limits in docker-compose.yml
|
||||
|
||||
```yaml
|
||||
# Add resource limits
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '0.5'
|
||||
memory: 512M
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Support
|
||||
|
||||
For issues, check:
|
||||
- Docker logs: `docker-compose logs`
|
||||
- Nginx logs: `docker exec configucci-app cat /var/log/nginx/error.log`
|
||||
- Application health: `docker inspect --format='{{.State.Health.Status}}' configucci-app`
|
||||
39
Dockerfile
Normal file
39
Dockerfile
Normal file
@@ -0,0 +1,39 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install git
|
||||
RUN apk add --no-cache git
|
||||
|
||||
# Clone repository
|
||||
ARG GIT_URL=https://git.six83.ru/ssa/configucci.git
|
||||
ARG GIT_BRANCH=ai
|
||||
RUN git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_URL} .
|
||||
|
||||
# Install dependencies
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Copy source and build
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy custom nginx config
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Copy built files from build stage
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1
|
||||
|
||||
# Start nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
152
deploy-docker.sh
Normal file
152
deploy-docker.sh
Normal file
@@ -0,0 +1,152 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configucci Docker Deployment Script
|
||||
# Usage: ./deploy-docker.sh [server]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
SERVER="${1:-}"
|
||||
APP_NAME="configucci"
|
||||
GIT_BRANCH="ai"
|
||||
|
||||
echo -e "${GREEN}==================================${NC}"
|
||||
echo -e "${GREEN} Configucci Docker Deployment ${NC}"
|
||||
echo -e "${GREEN}==================================${NC}"
|
||||
|
||||
# Function to deploy locally
|
||||
deploy_local() {
|
||||
echo -e "${YELLOW}Building Docker image...${NC}"
|
||||
docker-compose build --no-cache
|
||||
|
||||
echo -e "${YELLOW}Stopping existing container (if any)...${NC}"
|
||||
docker-compose down || true
|
||||
|
||||
echo -e "${YELLOW}Starting new container...${NC}"
|
||||
docker-compose up -d
|
||||
|
||||
echo -e "${YELLOW}Waiting for application to start...${NC}"
|
||||
sleep 5
|
||||
|
||||
echo -e "${GREEN}==================================${NC}"
|
||||
echo -e "${GREEN} Deployment Complete! ${NC}"
|
||||
echo -e "${GREEN}==================================${NC}"
|
||||
echo ""
|
||||
echo -e "Application URL: ${GREEN}http://localhost${NC}"
|
||||
echo ""
|
||||
echo -e "Useful commands:"
|
||||
echo -e " View logs: ${YELLOW}docker-compose logs -f${NC}"
|
||||
echo -e " Stop app: ${YELLOW}docker-compose down${NC}"
|
||||
echo -e " Restart app: ${YELLOW}docker-compose restart${NC}"
|
||||
echo -e " Rebuild: ${YELLOW}docker-compose build && docker-compose up -d${NC}"
|
||||
}
|
||||
|
||||
# Function to deploy to remote server
|
||||
deploy_remote() {
|
||||
echo -e "${YELLOW}Deploying to server: ${SERVER}${NC}"
|
||||
|
||||
# Check if server is accessible
|
||||
if ! ping -c 1 "$SERVER" &> /dev/null; then
|
||||
echo -e "${RED}Cannot connect to server: ${SERVER}${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create deployment script on server
|
||||
cat << 'EOF' > /tmp/deploy-configucci.sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
APP_DIR="/opt/configucci"
|
||||
GIT_URL="https://git.six83.ru/ssa/configucci.git"
|
||||
GIT_BRANCH="ai"
|
||||
|
||||
echo "Creating app directory..."
|
||||
mkdir -p \$APP_DIR
|
||||
cd \$APP_DIR
|
||||
|
||||
echo "Pulling latest code..."
|
||||
if [ -d ".git" ]; then
|
||||
git pull origin \$GIT_BRANCH
|
||||
else
|
||||
git clone --depth 1 --branch \$GIT_BRANCH \$GIT_URL .
|
||||
fi
|
||||
|
||||
echo "Building Docker image..."
|
||||
docker-compose build --no-cache
|
||||
|
||||
echo "Stopping existing container..."
|
||||
docker-compose down || true
|
||||
|
||||
echo "Starting new container..."
|
||||
docker-compose up -d
|
||||
|
||||
echo "Cleaning up old images..."
|
||||
docker image prune -f
|
||||
|
||||
echo "Deployment complete!"
|
||||
docker-compose ps
|
||||
EOF
|
||||
|
||||
# Copy docker-compose.yml to server
|
||||
echo -e "${YELLOW}Copying files to server...${NC}"
|
||||
scp docker-compose.yml Dockerfile nginx.conf "$SERVER:/tmp/"
|
||||
|
||||
# Execute deployment on server
|
||||
echo -e "${YELLOW}Executing deployment on server...${NC}"
|
||||
ssh "$SERVER" << 'ENDSSH'
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
APP_DIR="/opt/configucci"
|
||||
cd $APP_DIR
|
||||
|
||||
# Copy files from /tmp
|
||||
cp /tmp/docker-compose.yml .
|
||||
cp /tmp/Dockerfile .
|
||||
cp /tmp/nginx.conf .
|
||||
|
||||
# Build and deploy
|
||||
docker-compose build --no-cache
|
||||
docker-compose down || true
|
||||
docker-compose up -d
|
||||
|
||||
# Cleanup
|
||||
docker image prune -f
|
||||
docker-compose ps
|
||||
ENDSSH
|
||||
|
||||
echo -e "${GREEN}==================================${NC}"
|
||||
echo -e "${GREEN} Remote Deployment Complete! ${NC}"
|
||||
echo -e "${GREEN}==================================${NC}"
|
||||
echo ""
|
||||
echo -e "Server: ${GREEN}http://${SERVER}${NC}"
|
||||
echo ""
|
||||
echo -e "Useful commands:"
|
||||
echo -e " SSH to server: ${YELLOW}ssh ${SERVER}${NC}"
|
||||
echo -e " View logs: ${YELLOW}ssh ${SERVER} 'docker-compose logs -f'${NC}"
|
||||
echo -e " Stop app: ${YELLOW}ssh ${SERVER} 'docker-compose down'${NC}"
|
||||
}
|
||||
|
||||
# Check if Docker is available
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo -e "${RED}Docker is not installed or not in PATH${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v docker-compose &> /dev/null; then
|
||||
echo -e "${RED}docker-compose is not installed or not in PATH${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Deploy
|
||||
if [ -z "$SERVER" ]; then
|
||||
deploy_local
|
||||
else
|
||||
deploy_remote
|
||||
fi
|
||||
34
docker-compose.yml
Normal file
34
docker-compose.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
configucci:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
GIT_URL: https://git.six83.ru/ssa/configucci.git
|
||||
GIT_BRANCH: ai
|
||||
container_name: configucci-app
|
||||
ports:
|
||||
- "80:80"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- configucci-network
|
||||
volumes:
|
||||
# Optional: persist nginx logs
|
||||
- nginx-logs:/var/log/nginx
|
||||
environment:
|
||||
- TZ=Europe/Moscow
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
|
||||
networks:
|
||||
configucci-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
nginx-logs:
|
||||
36
nginx.conf
Normal file
36
nginx.conf
Normal file
@@ -0,0 +1,36 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript application/json;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# SPA routing - all routes go to index.html
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Cache static assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# Disable cache for index.html
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user