Files
Frank John Begornia 4ab1503e6f
Some checks failed
Deploy MinIO Production / deploy (push) Successful in 36s
Backup MinIO Buckets / backup (push) Failing after 10s
Remove workflow_dispatch trigger from deploy.yml
2026-01-14 14:13:53 +08:00

173 lines
6.3 KiB
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Deploy MinIO Production
on:
push:
branches:
- main
- master
jobs:
deploy:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
steps:
# 1⃣ Checkout code
- name: Checkout code
shell: sh
run: |
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git /workspace/repo
cd /workspace/repo
git checkout $GITHUB_REF_NAME
# 2⃣ Setup SSH
- name: Setup SSH
shell: sh
env:
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
run: |
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
# 3⃣ Upload compose files
- name: Upload compose and scripts
shell: sh
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
run: |
scp -i ~/.ssh/id_ed25519 \
/workspace/repo/docker-compose.prod.yml \
/workspace/repo/setup-buckets.sh \
${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/
# 4⃣ Deploy on server
- name: Deploy MinIO on server
shell: sh
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
run: |
ssh -i ~/.ssh/id_ed25519 $DEPLOY_USER@$DEPLOY_HOST << 'EOF'
set -e
DEPLOY_DIR="/var/www/apps/minio-storage"
sudo mkdir -p "$DEPLOY_DIR"
sudo chown $USER:$USER "$DEPLOY_DIR"
echo "📄 Updating compose file and scripts"
cp /tmp/docker-compose.prod.yml "$DEPLOY_DIR/docker-compose.yml"
cp /tmp/setup-buckets.sh "$DEPLOY_DIR/"
chmod +x "$DEPLOY_DIR/setup-buckets.sh"
cd "$DEPLOY_DIR"
echo "🔍 Checking .env file"
if [ ! -f .env ]; then
echo "⚠️ .env file not found, creating from example"
echo "# MinIO Production Configuration" > .env
echo "MINIO_ROOT_USER=admin_$(date +%s)" >> .env
echo "MINIO_ROOT_PASSWORD=$(openssl rand -base64 32 | tr -d '/+=' | cut -c1-32)" >> .env
echo "MINIO_SERVER_URL=https://minio.crewsportswear.com" >> .env
echo "MINIO_BROWSER_REDIRECT_URL=https://console.crewsportswear.com" >> .env
echo "" >> .env
echo "# BasicAuth for console (generate with: htpasswd -nb admin password)" >> .env
echo "# TRAEFIK_CONSOLE_AUTH='admin:\$\$apr1\$\$...'" >> .env
echo ""
echo "⚠️ IMPORTANT: Update .env with proper credentials!"
echo " Generated random password in $DEPLOY_DIR/.env"
echo " Save these credentials securely!"
fi
echo "🔧 Fixing .env permissions"
sudo chown $USER:$USER .env
sudo chmod 600 .env
echo "🌐 Ensure networks"
docker network inspect traefik-public >/dev/null 2>&1 || \
docker network create traefik-public
docker network inspect crew-app-net >/dev/null 2>&1 || \
docker network create crew-app-net
echo "📊 Current MinIO status"
if docker ps --format '{{.Names}}' | grep -q crew-minio; then
echo " MinIO is currently running"
docker ps | grep crew-minio
echo "🛑 Stopping MinIO container"
docker compose down
else
echo " MinIO is not running (first deployment)"
fi
echo "🚀 Starting/updating MinIO container"
docker compose pull
docker compose up -d
echo "⏳ Waiting for MinIO to be ready"
sleep 10
if docker ps --format '{{.Names}}' | grep -q crew-minio; then
echo "✅ MinIO container is running"
docker ps | grep crew-minio
echo "🪣 Setting up buckets"
# Run bucket setup script
bash "$DEPLOY_DIR/setup-buckets.sh" || echo "⚠️ Bucket setup had some warnings (buckets may already exist)"
else
echo "❌ MinIO container failed to start"
docker compose logs
exit 1
fi
echo "🧹 Cleanup"
rm -f /tmp/docker-compose.prod.yml /tmp/setup-buckets.sh
echo "✅ MinIO production deployment completed!"
echo "🌐 MinIO S3 API: https://minio.crewsportswear.com"
echo "🌐 MinIO Console: https://console.crewsportswear.com"
echo ""
echo "📝 Credentials stored in: $DEPLOY_DIR/.env"
EOF
# 5⃣ Health check
- name: Health check
shell: sh
run: |
echo "⏳ Waiting for MinIO to be ready..."
sleep 15
echo "🔍 Testing MinIO health endpoint..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 https://minio.crewsportswear.com/minio/health/live || echo "000")
if [ "$HTTP_CODE" = "200" ]; then
echo "✅ MinIO health check passed! (HTTP $HTTP_CODE)"
echo "🎉 Production deployment successful!"
echo ""
echo "📋 Next steps:"
echo " 1. Access console: https://console.crewsportswear.com"
echo " 2. Configure app .env files with MinIO credentials"
echo " 3. Migrate images from old server"
else
echo "⚠️ MinIO health check status: HTTP $HTTP_CODE"
echo ""
echo "💡 If this is first deployment, MinIO might need more time to initialize."
echo " Check manually: curl https://minio.crewsportswear.com/minio/health/live"
echo ""
echo "🔍 Troubleshooting:"
echo " 1. Check if container is running:"
echo " docker ps | grep crew-minio"
echo ""
echo " 2. Check MinIO logs:"
echo " docker logs crew-minio-prod"
echo ""
echo " 3. Check Traefik routing:"
echo " docker logs traefik"
fi