parent
0c410052b0
commit
f88c94ba46
@ -0,0 +1,139 @@
|
|||||||
|
# Docker utilities for Swarms project (PowerShell version)
|
||||||
|
# Usage: .\scripts\docker-utils.ps1 [command]
|
||||||
|
|
||||||
|
param(
|
||||||
|
[Parameter(Position=0)]
|
||||||
|
[string]$Command = "help"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
$ImageName = "swarms"
|
||||||
|
$Registry = "kyegomez"
|
||||||
|
$FullImageName = "$Registry/$ImageName"
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
function Write-Usage {
|
||||||
|
Write-Host "Docker Utilities for Swarms" -ForegroundColor Blue
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Usage: .\scripts\docker-utils.ps1 [command]"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Commands:"
|
||||||
|
Write-Host " build Build the Docker image locally"
|
||||||
|
Write-Host " test Test the Docker image"
|
||||||
|
Write-Host " run Run the Docker image interactively"
|
||||||
|
Write-Host " push Push to DockerHub (requires login)"
|
||||||
|
Write-Host " clean Clean up Docker images and containers"
|
||||||
|
Write-Host " logs Show logs from running containers"
|
||||||
|
Write-Host " shell Open shell in running container"
|
||||||
|
Write-Host " compose-up Start services with docker-compose"
|
||||||
|
Write-Host " compose-down Stop services with docker-compose"
|
||||||
|
Write-Host " help Show this help message"
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function Build-Image {
|
||||||
|
Write-Host "Building Docker image..." -ForegroundColor Green
|
||||||
|
docker build -t "$ImageName`:latest" .
|
||||||
|
Write-Host "✅ Image built successfully!" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-Image {
|
||||||
|
Write-Host "Testing Docker image..." -ForegroundColor Green
|
||||||
|
docker run --rm "$ImageName`:latest" python test_docker.py
|
||||||
|
Write-Host "✅ Image test completed!" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
function Run-Interactive {
|
||||||
|
Write-Host "Running Docker image interactively..." -ForegroundColor Green
|
||||||
|
docker run -it --rm -v "${PWD}:/app" -w /app "$ImageName`:latest" bash
|
||||||
|
}
|
||||||
|
|
||||||
|
function Push-ToDockerHub {
|
||||||
|
Write-Host "⚠️ Make sure you're logged into DockerHub first!" -ForegroundColor Yellow
|
||||||
|
Write-Host "Pushing to DockerHub..." -ForegroundColor Green
|
||||||
|
|
||||||
|
# Tag the image
|
||||||
|
docker tag "$ImageName`:latest" "$FullImageName`:latest"
|
||||||
|
|
||||||
|
# Push to DockerHub
|
||||||
|
docker push "$FullImageName`:latest"
|
||||||
|
|
||||||
|
Write-Host "✅ Image pushed to DockerHub!" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
function Clean-Docker {
|
||||||
|
Write-Host "Cleaning up Docker resources..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# Stop and remove containers
|
||||||
|
docker ps -aq | ForEach-Object { docker rm -f $_ }
|
||||||
|
|
||||||
|
# Remove images
|
||||||
|
docker images "$ImageName" -q | ForEach-Object { docker rmi -f $_ }
|
||||||
|
|
||||||
|
# Remove dangling images
|
||||||
|
docker image prune -f
|
||||||
|
|
||||||
|
Write-Host "✅ Docker cleanup completed!" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
function Show-Logs {
|
||||||
|
Write-Host "Showing logs from running containers..." -ForegroundColor Green
|
||||||
|
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# Show logs for swarms containers
|
||||||
|
$containers = docker ps --filter "name=swarms" --format "{{.Names}}"
|
||||||
|
foreach ($container in $containers) {
|
||||||
|
Write-Host "Logs for $container:" -ForegroundColor Blue
|
||||||
|
docker logs $container --tail 20
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Open-Shell {
|
||||||
|
Write-Host "Opening shell in running container..." -ForegroundColor Green
|
||||||
|
|
||||||
|
# Find running swarms container
|
||||||
|
$container = docker ps --filter "name=swarms" --format "{{.Names}}" | Select-Object -First 1
|
||||||
|
|
||||||
|
if (-not $container) {
|
||||||
|
Write-Host "❌ No running swarms container found!" -ForegroundColor Red
|
||||||
|
Write-Host "Start a container first with: .\scripts\docker-utils.ps1 run"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Opening shell in $container..." -ForegroundColor Blue
|
||||||
|
docker exec -it $container bash
|
||||||
|
}
|
||||||
|
|
||||||
|
function Compose-Up {
|
||||||
|
Write-Host "Starting services with docker-compose..." -ForegroundColor Green
|
||||||
|
docker-compose up -d
|
||||||
|
Write-Host "✅ Services started!" -ForegroundColor Green
|
||||||
|
Write-Host "Use 'docker-compose logs -f' to view logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Compose-Down {
|
||||||
|
Write-Host "Stopping services with docker-compose..." -ForegroundColor Yellow
|
||||||
|
docker-compose down
|
||||||
|
Write-Host "✅ Services stopped!" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main script logic
|
||||||
|
switch ($Command.ToLower()) {
|
||||||
|
"build" { Build-Image }
|
||||||
|
"test" { Test-Image }
|
||||||
|
"run" { Run-Interactive }
|
||||||
|
"push" { Push-ToDockerHub }
|
||||||
|
"clean" { Clean-Docker }
|
||||||
|
"logs" { Show-Logs }
|
||||||
|
"shell" { Open-Shell }
|
||||||
|
"compose-up" { Compose-Up }
|
||||||
|
"compose-down" { Compose-Down }
|
||||||
|
"help" { Write-Usage }
|
||||||
|
default {
|
||||||
|
Write-Host "❌ Unknown command: $Command" -ForegroundColor Red
|
||||||
|
Write-Usage
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,167 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Docker utilities for Swarms project
|
||||||
|
# Usage: ./scripts/docker-utils.sh [command]
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
IMAGE_NAME="swarms"
|
||||||
|
REGISTRY="kyegomez"
|
||||||
|
FULL_IMAGE_NAME="${REGISTRY}/${IMAGE_NAME}"
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
print_usage() {
|
||||||
|
echo -e "${BLUE}Docker Utilities for Swarms${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "Usage: $0 [command]"
|
||||||
|
echo ""
|
||||||
|
echo "Commands:"
|
||||||
|
echo " build Build the Docker image locally"
|
||||||
|
echo " test Test the Docker image"
|
||||||
|
echo " run Run the Docker image interactively"
|
||||||
|
echo " push Push to DockerHub (requires login)"
|
||||||
|
echo " clean Clean up Docker images and containers"
|
||||||
|
echo " logs Show logs from running containers"
|
||||||
|
echo " shell Open shell in running container"
|
||||||
|
echo " compose-up Start services with docker-compose"
|
||||||
|
echo " compose-down Stop services with docker-compose"
|
||||||
|
echo " help Show this help message"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
build_image() {
|
||||||
|
echo -e "${GREEN}Building Docker image...${NC}"
|
||||||
|
docker build -t "${IMAGE_NAME}:latest" .
|
||||||
|
echo -e "${GREEN}✅ Image built successfully!${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_image() {
|
||||||
|
echo -e "${GREEN}Testing Docker image...${NC}"
|
||||||
|
docker run --rm "${IMAGE_NAME}:latest" python test_docker.py
|
||||||
|
echo -e "${GREEN}✅ Image test completed!${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_interactive() {
|
||||||
|
echo -e "${GREEN}Running Docker image interactively...${NC}"
|
||||||
|
docker run -it --rm \
|
||||||
|
-v "$(pwd):/app" \
|
||||||
|
-w /app \
|
||||||
|
"${IMAGE_NAME}:latest" bash
|
||||||
|
}
|
||||||
|
|
||||||
|
push_to_dockerhub() {
|
||||||
|
echo -e "${YELLOW}⚠️ Make sure you're logged into DockerHub first!${NC}"
|
||||||
|
echo -e "${GREEN}Pushing to DockerHub...${NC}"
|
||||||
|
|
||||||
|
# Tag the image
|
||||||
|
docker tag "${IMAGE_NAME}:latest" "${FULL_IMAGE_NAME}:latest"
|
||||||
|
|
||||||
|
# Push to DockerHub
|
||||||
|
docker push "${FULL_IMAGE_NAME}:latest"
|
||||||
|
|
||||||
|
echo -e "${GREEN}✅ Image pushed to DockerHub!${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_docker() {
|
||||||
|
echo -e "${YELLOW}Cleaning up Docker resources...${NC}"
|
||||||
|
|
||||||
|
# Stop and remove containers
|
||||||
|
docker ps -aq | xargs -r docker rm -f
|
||||||
|
|
||||||
|
# Remove images
|
||||||
|
docker images "${IMAGE_NAME}" -q | xargs -r docker rmi -f
|
||||||
|
|
||||||
|
# Remove dangling images
|
||||||
|
docker image prune -f
|
||||||
|
|
||||||
|
echo -e "${GREEN}✅ Docker cleanup completed!${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
show_logs() {
|
||||||
|
echo -e "${GREEN}Showing logs from running containers...${NC}"
|
||||||
|
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Show logs for swarms containers
|
||||||
|
for container in $(docker ps --filter "name=swarms" --format "{{.Names}}"); do
|
||||||
|
echo -e "${BLUE}Logs for $container:${NC}"
|
||||||
|
docker logs "$container" --tail 20
|
||||||
|
echo ""
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
open_shell() {
|
||||||
|
echo -e "${GREEN}Opening shell in running container...${NC}"
|
||||||
|
|
||||||
|
# Find running swarms container
|
||||||
|
container=$(docker ps --filter "name=swarms" --format "{{.Names}}" | head -1)
|
||||||
|
|
||||||
|
if [ -z "$container" ]; then
|
||||||
|
echo -e "${RED}❌ No running swarms container found!${NC}"
|
||||||
|
echo "Start a container first with: $0 run"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${BLUE}Opening shell in $container...${NC}"
|
||||||
|
docker exec -it "$container" bash
|
||||||
|
}
|
||||||
|
|
||||||
|
compose_up() {
|
||||||
|
echo -e "${GREEN}Starting services with docker-compose...${NC}"
|
||||||
|
docker-compose up -d
|
||||||
|
echo -e "${GREEN}✅ Services started!${NC}"
|
||||||
|
echo "Use 'docker-compose logs -f' to view logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
compose_down() {
|
||||||
|
echo -e "${YELLOW}Stopping services with docker-compose...${NC}"
|
||||||
|
docker-compose down
|
||||||
|
echo -e "${GREEN}✅ Services stopped!${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main script logic
|
||||||
|
case "${1:-help}" in
|
||||||
|
build)
|
||||||
|
build_image
|
||||||
|
;;
|
||||||
|
test)
|
||||||
|
test_image
|
||||||
|
;;
|
||||||
|
run)
|
||||||
|
run_interactive
|
||||||
|
;;
|
||||||
|
push)
|
||||||
|
push_to_dockerhub
|
||||||
|
;;
|
||||||
|
clean)
|
||||||
|
clean_docker
|
||||||
|
;;
|
||||||
|
logs)
|
||||||
|
show_logs
|
||||||
|
;;
|
||||||
|
shell)
|
||||||
|
open_shell
|
||||||
|
;;
|
||||||
|
compose-up)
|
||||||
|
compose_up
|
||||||
|
;;
|
||||||
|
compose-down)
|
||||||
|
compose_down
|
||||||
|
;;
|
||||||
|
help|--help|-h)
|
||||||
|
print_usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${RED}❌ Unknown command: $1${NC}"
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
@ -0,0 +1,113 @@
|
|||||||
|
# Setting up DockerHub Secrets for GitHub Actions
|
||||||
|
|
||||||
|
This guide will help you set up the required secrets for the Docker workflow to automatically build and push images to DockerHub.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
1. A DockerHub account
|
||||||
|
2. Admin access to the GitHub repository
|
||||||
|
3. DockerHub access token
|
||||||
|
|
||||||
|
## Step 1: Create a DockerHub Access Token
|
||||||
|
|
||||||
|
1. Log in to [DockerHub](https://hub.docker.com/)
|
||||||
|
2. Go to your account settings
|
||||||
|
3. Navigate to "Security" → "Access Tokens"
|
||||||
|
4. Click "New Access Token"
|
||||||
|
5. Give it a name (e.g., "GitHub Actions")
|
||||||
|
6. Set the permissions to "Read & Write"
|
||||||
|
7. Copy the generated token (you won't be able to see it again!)
|
||||||
|
|
||||||
|
## Step 2: Add Secrets to GitHub Repository
|
||||||
|
|
||||||
|
1. Go to your GitHub repository
|
||||||
|
2. Navigate to "Settings" → "Secrets and variables" → "Actions"
|
||||||
|
3. Click "New repository secret"
|
||||||
|
4. Add the following secrets:
|
||||||
|
|
||||||
|
### Required Secrets
|
||||||
|
|
||||||
|
| Secret Name | Value | Description |
|
||||||
|
|-------------|-------|-------------|
|
||||||
|
| `DOCKERHUB_USERNAME` | Your DockerHub username | Your DockerHub username (e.g., `kyegomez`) |
|
||||||
|
| `DOCKERHUB_TOKEN` | Your DockerHub access token | The access token you created in Step 1 |
|
||||||
|
|
||||||
|
## Step 3: Verify Setup
|
||||||
|
|
||||||
|
1. Push a commit to the `main` branch
|
||||||
|
2. Go to the "Actions" tab in your GitHub repository
|
||||||
|
3. You should see the "Docker Build and Publish" workflow running
|
||||||
|
4. Check that it completes successfully
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Common Issues
|
||||||
|
|
||||||
|
1. **Authentication Failed**
|
||||||
|
- Double-check your DockerHub username and token
|
||||||
|
- Ensure the token has "Read & Write" permissions
|
||||||
|
- Make sure the token hasn't expired
|
||||||
|
|
||||||
|
2. **Permission Denied**
|
||||||
|
- Verify you have admin access to the repository
|
||||||
|
- Check that the secrets are named exactly as shown above
|
||||||
|
|
||||||
|
3. **Workflow Not Triggering**
|
||||||
|
- Ensure you're pushing to the `main` branch
|
||||||
|
- Check that the workflow file is in `.github/workflows/`
|
||||||
|
- Verify the workflow file has the correct triggers
|
||||||
|
|
||||||
|
### Testing Locally
|
||||||
|
|
||||||
|
You can test the Docker build locally before pushing:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build the image locally
|
||||||
|
docker build -t swarms:test .
|
||||||
|
|
||||||
|
# Test the image
|
||||||
|
docker run --rm swarms:test python test_docker.py
|
||||||
|
|
||||||
|
# If everything works, push to GitHub
|
||||||
|
git add .
|
||||||
|
git commit -m "Add Docker support"
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## Security Notes
|
||||||
|
|
||||||
|
- Never commit secrets directly to your repository
|
||||||
|
- Use repository secrets for sensitive information
|
||||||
|
- Regularly rotate your DockerHub access tokens
|
||||||
|
- Consider using organization-level secrets for team repositories
|
||||||
|
|
||||||
|
## Additional Configuration
|
||||||
|
|
||||||
|
### Custom Registry
|
||||||
|
|
||||||
|
If you want to use a different registry (not DockerHub), update the workflow file:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
env:
|
||||||
|
REGISTRY: your-registry.com
|
||||||
|
IMAGE_NAME: your-org/your-repo
|
||||||
|
```
|
||||||
|
|
||||||
|
### Multiple Tags
|
||||||
|
|
||||||
|
The workflow automatically creates tags based on:
|
||||||
|
- Git branch name
|
||||||
|
- Git commit SHA
|
||||||
|
- Version tags (v*.*.*)
|
||||||
|
- Latest tag for main branch
|
||||||
|
|
||||||
|
You can customize this in the workflow file under the "Extract Docker metadata" step.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you encounter issues:
|
||||||
|
|
||||||
|
1. Check the GitHub Actions logs for detailed error messages
|
||||||
|
2. Verify your DockerHub credentials
|
||||||
|
3. Ensure the workflow file is properly configured
|
||||||
|
4. Open an issue in the repository with the error details
|
Loading…
Reference in new issue