122 lines
4.1 KiB
YAML
122 lines
4.1 KiB
YAML
name: Build and Deploy ASP.NET API
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: localACDC
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
echo "✅ Manual checkout and workspace setup"
|
|
echo "Current directory: $(pwd)"
|
|
echo "Git status:"
|
|
git status || echo "Not a git repo, fetching code..."
|
|
|
|
# Fazer checkout manual se necessário
|
|
git fetch origin main || echo "Fetch failed"
|
|
git reset --hard origin/main || echo "Reset failed"
|
|
git clean -fd || echo "Clean failed"
|
|
|
|
echo "After checkout - Root files:"
|
|
ls -la
|
|
echo "Looking for .sln files:"
|
|
find . -name "*.sln" -type f
|
|
|
|
- name: Restore dependencies
|
|
run: |
|
|
echo "Using solution file from root..."
|
|
ls -la *.sln
|
|
dotnet restore YTExtractor.sln
|
|
|
|
- name: Build application
|
|
run: |
|
|
echo "Building solution from root..."
|
|
dotnet build YTExtractor.sln --configuration Release --no-restore
|
|
|
|
- name: Run tests (opcional)
|
|
run: |
|
|
echo "Running tests on solution..."
|
|
dotnet test YTExtractor.sln --no-build --verbosity normal || true
|
|
|
|
- name: Publish application
|
|
run: |
|
|
echo "Publishing solution..."
|
|
dotnet publish YTExtractor.sln --configuration Release --output ./publish
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
echo "Current directory: $(pwd)"
|
|
echo "Files in current directory:"
|
|
ls -la
|
|
|
|
COMMIT_SHA=$(git rev-parse --short HEAD)
|
|
|
|
# O Dockerfile está em YTExtractor/YTExtractor/ baseado na estrutura mostrada
|
|
if [ -f "YTExtractor/YTExtractor/Dockerfile" ]; then
|
|
echo "✅ Found Dockerfile in YTExtractor/YTExtractor/ directory"
|
|
cd YTExtractor/YTExtractor
|
|
echo "Building Docker image from project directory..."
|
|
echo "Files in this directory:"
|
|
ls -la
|
|
docker build -t ytextractor:$COMMIT_SHA .
|
|
elif [ -f "YTExtractor/Dockerfile" ]; then
|
|
echo "✅ Found Dockerfile in YTExtractor/ directory"
|
|
cd YTExtractor
|
|
docker build -t ytextractor:$COMMIT_SHA .
|
|
else
|
|
echo "❌ Dockerfile not found!"
|
|
echo "Searching for Dockerfile..."
|
|
find . -name "Dockerfile" -type f
|
|
exit 1
|
|
fi
|
|
|
|
# Tag das imagens (voltar para raiz se necessário)
|
|
cd /workspace/ricardo/YTExtractor
|
|
docker tag ytextractor:$COMMIT_SHA registry.redecarneir.us/ytextractor:latest
|
|
docker tag ytextractor:$COMMIT_SHA registry.redecarneir.us/ytextractor:$COMMIT_SHA
|
|
|
|
echo "✅ Docker images built successfully"
|
|
docker images | grep ytextractor
|
|
|
|
- name: Push to registry
|
|
run: |
|
|
COMMIT_SHA=$(git rev-parse --short HEAD)
|
|
docker push registry.redecarneir.us/ytextractor:latest
|
|
docker push registry.redecarneir.us/ytextractor:$COMMIT_SHA
|
|
|
|
- name: Deploy to remote VPS
|
|
run: |
|
|
ssh -o StrictHostKeyChecking=no ubuntu@137.131.63.61 << 'EOF'
|
|
# Pull da nova imagem
|
|
docker pull registry.redecarneir.us/ytextractor:latest
|
|
|
|
# Parar container atual se existir
|
|
docker stop ytextractor-api || true
|
|
docker rm ytextractor-api || true
|
|
|
|
# Rodar novo container em produção
|
|
# Porta 80 interna (do container) mapeada para 5000 externa
|
|
docker run -d \
|
|
--name ytextractor-api \
|
|
--restart unless-stopped \
|
|
-p 5000:80 \
|
|
-e ASPNETCORE_ENVIRONMENT=Production \
|
|
-v /tmp/ytextractor:/app/temp \
|
|
registry.redecarneir.us/ytextractor:latest
|
|
|
|
# Verificar se está rodando
|
|
sleep 5
|
|
docker ps | grep ytextractor-api
|
|
|
|
# Limpeza de imagens antigas (opcional)
|
|
docker image prune -f
|
|
EOF
|
|
|
|
- name: Verify deployment
|
|
run: |
|
|
ssh ubuntu@137.131.63.61 'docker ps | grep ytextractor-api'
|
|
echo "✅ Deploy completed successfully!" |