156 lines
5.4 KiB
YAML
156 lines
5.4 KiB
YAML
name: Deploy MinIO Development
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- dev
|
||
workflow_dispatch:
|
||
|
||
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.yml \
|
||
/workspace/repo/setup-buckets.sh \
|
||
${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/
|
||
|
||
# 4️⃣ Deploy on server
|
||
- name: Deploy MinIO Dev 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-dev"
|
||
sudo mkdir -p "$DEPLOY_DIR"
|
||
sudo chown $USER:$USER "$DEPLOY_DIR"
|
||
|
||
echo "📄 Updating compose file and scripts"
|
||
cp /tmp/docker-compose.yml "$DEPLOY_DIR/"
|
||
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 dev config"
|
||
echo "# MinIO Development Configuration" > .env
|
||
echo "MINIO_ROOT_USER=minioadmin" >> .env
|
||
echo "MINIO_ROOT_PASSWORD=minioadmin123" >> .env
|
||
echo "MINIO_SERVER_URL=http://dev.crewsportswear.com:9000" >> .env
|
||
echo "MINIO_BROWSER_REDIRECT_URL=http://dev.crewsportswear.com:9001" >> .env
|
||
echo "MINIO_PORT=9000" >> .env
|
||
echo "MINIO_CONSOLE_PORT=9001" >> .env
|
||
echo ""
|
||
echo "✅ Created dev .env file"
|
||
fi
|
||
|
||
echo "🔧 Fixing .env permissions"
|
||
sudo chown $USER:$USER .env
|
||
sudo chmod 600 .env
|
||
|
||
echo "🌐 Ensure crew-app-net network"
|
||
docker network inspect crew-app-net >/dev/null 2>&1 || \
|
||
docker network create crew-app-net
|
||
|
||
echo "📊 Current MinIO Dev status"
|
||
if docker ps --format '{{.Names}}' | grep -q crew-minio; then
|
||
echo "ℹ️ MinIO Dev is currently running"
|
||
docker ps | grep crew-minio
|
||
else
|
||
echo "ℹ️ MinIO Dev is not running (first deployment)"
|
||
fi
|
||
|
||
echo "🚀 Starting/updating MinIO Dev 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 Dev container is running"
|
||
docker ps | grep crew-minio
|
||
|
||
echo "🪣 Setting up development buckets"
|
||
# Update script to use dev container name
|
||
sed -i 's/crew-minio-prod/crew-minio/g' "$DEPLOY_DIR/setup-buckets.sh"
|
||
bash "$DEPLOY_DIR/setup-buckets.sh" || echo "⚠️ Bucket setup had some warnings (buckets may already exist)"
|
||
|
||
else
|
||
echo "❌ MinIO Dev container failed to start"
|
||
docker compose logs
|
||
exit 1
|
||
fi
|
||
|
||
echo "🧹 Cleanup"
|
||
rm -f /tmp/docker-compose.yml /tmp/setup-buckets.sh
|
||
|
||
echo "✅ MinIO Dev deployment completed!"
|
||
echo "🌐 MinIO S3 API: http://dev.crewsportswear.com:9000"
|
||
echo "🌐 MinIO Console: http://dev.crewsportswear.com:9001"
|
||
echo " Username: minioadmin"
|
||
echo " Password: minioadmin123"
|
||
EOF
|
||
|
||
# 5️⃣ Health check
|
||
- name: Health check
|
||
shell: sh
|
||
env:
|
||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||
run: |
|
||
echo "⏳ Waiting for MinIO Dev to be ready..."
|
||
sleep 10
|
||
|
||
echo "🔍 Testing MinIO health endpoint..."
|
||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 http://${DEPLOY_HOST}:9000/minio/health/live || echo "000")
|
||
|
||
if [ "$HTTP_CODE" = "200" ]; then
|
||
echo "✅ MinIO Dev health check passed! (HTTP $HTTP_CODE)"
|
||
echo "🎉 Development deployment successful!"
|
||
echo ""
|
||
echo "📋 Access points:"
|
||
echo " - API: http://${DEPLOY_HOST}:9000"
|
||
echo " - Console: http://${DEPLOY_HOST}:9001"
|
||
else
|
||
echo "⚠️ MinIO health check status: HTTP $HTTP_CODE"
|
||
echo " MinIO might need more time to initialize."
|
||
echo " Check manually: curl http://${DEPLOY_HOST}:9000/minio/health/live"
|
||
fi
|