add-docker-registry-deployment-scripts

This commit is contained in:
sysadmin 2025-11-20 16:22:54 +00:00
parent fcff57dd1f
commit cdef6f04e1
2 changed files with 300 additions and 0 deletions

207
DEPLOY.md Normal file
View File

@ -0,0 +1,207 @@
# TeleShop & TeleBot Docker Deployment Guide
## Prerequisites
- Docker installed on your local machine or build server
- Network access to the Docker registry at `10.8.0.1:5000`
- Git repository cloned locally
## Quick Deployment
### Option 1: Using the Deployment Script (Recommended)
```bash
# Make script executable (if not already)
chmod +x deploy-to-registry.sh
# Run the deployment
./deploy-to-registry.sh
```
The script will:
1. ✅ Test registry connectivity
2. 📦 Build both TeleShop and TeleBot images
3. 🏷️ Tag images with `latest` and `clean-slate` tags
4. 🚀 Push all images to the registry
### Option 2: Manual Steps
If you prefer to run commands manually:
```bash
# 1. Build TeleShop image
docker build -f Dockerfile -t teleshop:latest .
# 2. Build TeleBot image
docker build -f Dockerfile.telebot -t telebot:latest .
# 3. Tag images for registry
docker tag teleshop:latest 10.8.0.1:5000/teleshop:latest
docker tag teleshop:latest 10.8.0.1:5000/teleshop:clean-slate
docker tag telebot:latest 10.8.0.1:5000/telebot:latest
docker tag telebot:latest 10.8.0.1:5000/telebot:clean-slate
# 4. Push to registry
docker push 10.8.0.1:5000/teleshop:latest
docker push 10.8.0.1:5000/teleshop:clean-slate
docker push 10.8.0.1:5000/telebot:latest
docker push 10.8.0.1:5000/telebot:clean-slate
```
## Registry Configuration
### If Using HTTP (Insecure) Registry
The registry at `10.8.0.1:5000` is HTTP (not HTTPS). You need to configure Docker to allow insecure registries:
#### On Linux
Edit `/etc/docker/daemon.json`:
```json
{
"insecure-registries": ["10.8.0.1:5000"]
}
```
Restart Docker:
```bash
sudo systemctl restart docker
```
#### On Windows (Docker Desktop)
1. Open Docker Desktop
2. Go to Settings → Docker Engine
3. Add to the JSON configuration:
```json
{
"insecure-registries": ["10.8.0.1:5000"]
}
```
4. Click "Apply & Restart"
#### On macOS (Docker Desktop)
1. Open Docker Desktop
2. Go to Preferences → Docker Engine
3. Add to the JSON configuration:
```json
{
"insecure-registries": ["10.8.0.1:5000"]
}
```
4. Click "Apply & Restart"
## Verify Deployment
After pushing, verify the images are in the registry:
```bash
# List all repositories
curl http://10.8.0.1:5000/v2/_catalog
# Expected output:
# {"repositories":["telebot","teleshop"]}
# List tags for TeleShop
curl http://10.8.0.1:5000/v2/teleshop/tags/list
# List tags for TeleBot
curl http://10.8.0.1:5000/v2/telebot/tags/list
```
## Pulling Images
On your deployment server, pull the images:
```bash
# Pull TeleShop
docker pull 10.8.0.1:5000/teleshop:latest
# or specific version
docker pull 10.8.0.1:5000/teleshop:clean-slate
# Pull TeleBot
docker pull 10.8.0.1:5000/telebot:latest
# or specific version
docker pull 10.8.0.1:5000/telebot:clean-slate
```
## Using with docker-compose
Update your `docker-compose.yml` to use the registry images:
```yaml
services:
littleshop:
image: 10.8.0.1:5000/teleshop:latest
# ... rest of configuration
telebot:
image: 10.8.0.1:5000/telebot:latest
# ... rest of configuration
```
## Troubleshooting
### Cannot connect to registry
```bash
# Test connectivity
curl http://10.8.0.1:5000/v2/_catalog
# If this fails, check:
# - Network connectivity to 10.8.0.1
# - Registry service is running
# - Port 5000 is accessible (check firewall)
```
### Permission denied when pushing
```bash
# Registry may require authentication. Contact your registry administrator.
```
### HTTP request forbidden
```bash
# You need to configure the insecure registry setting (see above)
```
## Image Details
### TeleShop Image
- **Base Image**: mcr.microsoft.com/dotnet/aspnet:9.0
- **Exposed Port**: 8080
- **Database**: SQLite at `/app/data/teleshop-prod.db`
- **Volumes**:
- `/app/data` - Database storage
- `/app/wwwroot/uploads` - Product images
- `/app/logs` - Application logs
### TeleBot Image
- **Base Image**: mcr.microsoft.com/dotnet/aspnet:9.0
- **Dependencies**: Connects to TeleShop API
- **Volumes**:
- `/app/logs` - Application logs
- `/app/data` - Bot data
- `/app/image_cache` - Cached product images
## Version Tags
- `latest` - Always points to the most recent build
- `clean-slate` - Baseline version with migrations, no sample data (current clean state)
## CI/CD Integration
You can integrate this deployment script into your CI/CD pipeline:
```yaml
# GitLab CI example
deploy:
stage: deploy
script:
- ./deploy-to-registry.sh
only:
- main
- tags
```
```yaml
# GitHub Actions example
- name: Deploy to Registry
run: ./deploy-to-registry.sh
```

93
deploy-to-registry.sh Normal file
View File

@ -0,0 +1,93 @@
#!/bin/bash
set -e
# Docker Registry Configuration
REGISTRY="10.8.0.1:5000"
TELESHOP_IMAGE="teleshop"
TELEBOT_IMAGE="telebot"
VERSION_TAG="clean-slate"
echo "=================================="
echo "TeleShop & TeleBot Docker Deployment"
echo "Registry: $REGISTRY"
echo "=================================="
echo ""
# Check if Docker is available
if ! command -v docker &> /dev/null; then
echo "❌ Error: Docker is not installed or not in PATH"
exit 1
fi
# Check if registry is accessible
echo "🔍 Testing registry connectivity..."
if curl -s "http://$REGISTRY/v2/_catalog" > /dev/null 2>&1; then
echo "✅ Registry is accessible at http://$REGISTRY"
else
echo "❌ Error: Cannot connect to registry at $REGISTRY"
echo "Please ensure the registry is running and accessible"
exit 1
fi
echo ""
echo "📦 Building TeleShop image..."
docker build -f Dockerfile -t $TELESHOP_IMAGE:latest . || {
echo "❌ Failed to build TeleShop image"
exit 1
}
echo "✅ TeleShop image built successfully"
echo ""
echo "📦 Building TeleBot image..."
docker build -f Dockerfile.telebot -t $TELEBOT_IMAGE:latest . || {
echo "❌ Failed to build TeleBot image"
exit 1
}
echo "✅ TeleBot image built successfully"
echo ""
echo "🏷️ Tagging images for registry..."
docker tag $TELESHOP_IMAGE:latest $REGISTRY/$TELESHOP_IMAGE:latest
docker tag $TELESHOP_IMAGE:latest $REGISTRY/$TELESHOP_IMAGE:$VERSION_TAG
docker tag $TELEBOT_IMAGE:latest $REGISTRY/$TELEBOT_IMAGE:latest
docker tag $TELEBOT_IMAGE:latest $REGISTRY/$TELEBOT_IMAGE:$VERSION_TAG
echo "✅ Images tagged successfully"
echo ""
echo "🚀 Pushing TeleShop to registry..."
docker push $REGISTRY/$TELESHOP_IMAGE:latest || {
echo "❌ Failed to push TeleShop:latest"
exit 1
}
docker push $REGISTRY/$TELESHOP_IMAGE:$VERSION_TAG || {
echo "❌ Failed to push TeleShop:$VERSION_TAG"
exit 1
}
echo "✅ TeleShop pushed successfully"
echo ""
echo "🚀 Pushing TeleBot to registry..."
docker push $REGISTRY/$TELEBOT_IMAGE:latest || {
echo "❌ Failed to push TeleBot:latest"
exit 1
}
docker push $REGISTRY/$TELEBOT_IMAGE:$VERSION_TAG || {
echo "❌ Failed to push TeleBot:$VERSION_TAG"
exit 1
}
echo "✅ TeleBot pushed successfully"
echo ""
echo "=================================="
echo "✅ Deployment Complete!"
echo "=================================="
echo ""
echo "Images pushed to registry:"
echo " - $REGISTRY/$TELESHOP_IMAGE:latest"
echo " - $REGISTRY/$TELESHOP_IMAGE:$VERSION_TAG"
echo " - $REGISTRY/$TELEBOT_IMAGE:latest"
echo " - $REGISTRY/$TELEBOT_IMAGE:$VERSION_TAG"
echo ""
echo "Verify with:"
echo " curl http://$REGISTRY/v2/_catalog"
echo ""