fix: deploy com private key e appsettings correto
This commit is contained in:
parent
944de92af6
commit
3395cc7478
50
.github/workflows/deploy.yml
vendored
50
.github/workflows/deploy.yml
vendored
@ -64,11 +64,12 @@ jobs:
|
|||||||
TAG="develop"
|
TAG="develop"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build da imagem
|
# Build da imagem para ARM64 (servidores Ampere OCI)
|
||||||
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG .
|
docker buildx build \
|
||||||
|
--platform linux/arm64 \
|
||||||
# Push para o registry (sem autenticação conforme mencionado)
|
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG \
|
||||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG
|
--push \
|
||||||
|
.
|
||||||
|
|
||||||
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
|
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
|
||||||
|
|
||||||
@ -80,13 +81,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Deploy to Staging Servers
|
- name: Deploy to Staging Servers
|
||||||
run: |
|
run: |
|
||||||
# Configura SSH known_hosts
|
# Configura SSH
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
# Deploy no Servidor 1
|
# Deploy no Servidor 1
|
||||||
ssh ubuntu@141.148.162.114 << 'EOF'
|
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 << 'EOF'
|
||||||
# Para o container atual se existir
|
# Para o container atual se existir
|
||||||
docker stop qrrapido-staging || true
|
docker stop qrrapido-staging || true
|
||||||
docker rm qrrapido-staging || true
|
docker rm qrrapido-staging || true
|
||||||
@ -107,7 +108,7 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Deploy no Servidor 2
|
# Deploy no Servidor 2
|
||||||
ssh ubuntu@129.146.116.218 << 'EOF'
|
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 << 'EOF'
|
||||||
# Para o container atual se existir
|
# Para o container atual se existir
|
||||||
docker stop qrrapido-staging || true
|
docker stop qrrapido-staging || true
|
||||||
docker rm qrrapido-staging || true
|
docker rm qrrapido-staging || true
|
||||||
@ -136,13 +137,27 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Deploy to Production Servers
|
- name: Deploy to Production Servers
|
||||||
run: |
|
run: |
|
||||||
# Configura SSH known_hosts
|
# Debug SSH setup
|
||||||
|
echo "=== Configurando SSH ==="
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
|
# Verifica se a chave foi criada
|
||||||
|
echo "=== Verificando chave SSH ==="
|
||||||
|
ls -la ~/.ssh/
|
||||||
|
echo "Primeiras linhas da chave:"
|
||||||
|
head -2 ~/.ssh/id_rsa
|
||||||
|
|
||||||
|
# Testa conexão SSH com debug
|
||||||
|
echo "=== Testando conexão SSH ==="
|
||||||
|
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -v ubuntu@141.148.162.114 'echo "Conexão SSH funcionando!"' || echo "Falha na conexão SSH"
|
||||||
|
|
||||||
|
# Se a conexão funcionou, continua com o deploy
|
||||||
|
echo "=== Iniciando Deploy ==="
|
||||||
|
|
||||||
# Deploy no Servidor 1 (com NGINX)
|
# Deploy no Servidor 1 (com NGINX)
|
||||||
ssh ubuntu@141.148.162.114 << 'EOF'
|
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 << 'EOF'
|
||||||
# Para o container atual se existir
|
# Para o container atual se existir
|
||||||
docker stop qrrapido-prod || true
|
docker stop qrrapido-prod || true
|
||||||
docker rm qrrapido-prod || true
|
docker rm qrrapido-prod || true
|
||||||
@ -167,7 +182,7 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Deploy no Servidor 2
|
# Deploy no Servidor 2
|
||||||
ssh ubuntu@129.146.116.218 << 'EOF'
|
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 << 'EOF'
|
||||||
# Para o container atual se existir
|
# Para o container atual se existir
|
||||||
docker stop qrrapido-prod || true
|
docker stop qrrapido-prod || true
|
||||||
docker rm qrrapido-prod || true
|
docker rm qrrapido-prod || true
|
||||||
@ -195,8 +210,7 @@ jobs:
|
|||||||
|
|
||||||
# Verifica se os serviços estão respondendo
|
# Verifica se os serviços estão respondendo
|
||||||
echo "Verificando Servidor 1..."
|
echo "Verificando Servidor 1..."
|
||||||
ssh ubuntu@141.148.162.114 'curl -f http://localhost:5001/health || echo "Servidor 1 pode não estar respondendo"'
|
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 'curl -f http://localhost:5001/health || echo "Servidor 1 pode não estar respondendo"'
|
||||||
|
|
||||||
echo "Verificando Servidor 2..."
|
echo "Verificando Servidor 2..."
|
||||||
ssh ubuntu@129.146.116.218 'curl -f http://localhost:5001/health || echo "Servidor 2 pode não estar respondendo"'
|
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 'curl -f http://localhost:5001/health || echo "Servidor 2 pode não estar respondendo"'
|
||||||
|
|
||||||
336
appsettings.json
336
appsettings.json
@ -1,216 +1,120 @@
|
|||||||
name: Deploy QR Rapido
|
{
|
||||||
on:
|
"App": {
|
||||||
push:
|
"Name": "QR Rapido",
|
||||||
branches: [ main, develop ]
|
"BaseUrl": "https://qrrapido.site",
|
||||||
pull_request:
|
"TaglinePT": "Gere QR codes em segundos!",
|
||||||
branches: [ main ]
|
"TaglineES": "¡Genera códigos QR en segundos!",
|
||||||
|
"TaglineEN": "Generate QR codes in seconds!",
|
||||||
env:
|
"Version": "1.0.0"
|
||||||
REGISTRY: registry.redecarneir.us
|
},
|
||||||
IMAGE_NAME: qrrapido
|
"ConnectionStrings": {
|
||||||
|
"MongoDB": "mongodb://localhost:27017/QrRapido"
|
||||||
jobs:
|
},
|
||||||
test:
|
"Authentication": {
|
||||||
runs-on: ubuntu-latest
|
"Google": {
|
||||||
|
"ClientId": "1080447252222-dqjsu999tvrpb69oj5iapckdh9g8rvha.apps.googleusercontent.com",
|
||||||
steps:
|
"ClientSecret": "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"
|
||||||
- uses: actions/checkout@v4
|
},
|
||||||
|
"Microsoft": {
|
||||||
- name: Setup .NET
|
"ClientId": "9bec3835-acdb-4c5a-8668-6b90955c6ad2",
|
||||||
uses: actions/setup-dotnet@v4
|
"ClientSecret": "Oe38Q~FsZ3X5ouptAB6oYyX7MXaGUvxXcqT.aaT9"
|
||||||
with:
|
}
|
||||||
dotnet-version: 8.0.x
|
},
|
||||||
|
"Stripe": {
|
||||||
- name: Cache dependencies
|
"PublishableKey": "pk_test_51Rs42tBeR5IFYUsBooapyDwQTgh6CFuKbya5R3MVDTrdOUKmgiHQYipU0pgOdG5iKogH77RUYIKBJzbCt5BghUOY00xitV5KiN",
|
||||||
uses: actions/cache@v3
|
"SecretKey": "sk_test_51Rs42tBeR5IFYUsBtycRlJJcdwgoMbh8MfQIKIGelBPTQFwDcOn2iCCbw5uG6hnqlpgNAUuFgWRAUUMA8qkABKun00EIx4odDF",
|
||||||
with:
|
"WebhookSecret": "whsec_2e828803ceb48e7865458b0cf332b68535fdff8753d26d69b1c88ea55cb0e482",
|
||||||
path: ~/.nuget/packages
|
"PriceId": "prod_SnfQTxwE3i8r5L"
|
||||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
|
},
|
||||||
restore-keys: |
|
"AdSense": {
|
||||||
${{ runner.os }}-nuget-
|
"ClientId": "ca-pub-XXXXXXXXXX",
|
||||||
|
"Enabled": true
|
||||||
- name: Restore dependencies
|
},
|
||||||
run: dotnet restore
|
"Performance": {
|
||||||
|
"QRGenerationTimeoutMs": 2000,
|
||||||
- name: Build
|
"CacheExpirationMinutes": 60,
|
||||||
run: dotnet build --no-restore --configuration Release
|
"MaxConcurrentGenerations": 100
|
||||||
|
},
|
||||||
- name: Test
|
"HistoryCleanup": {
|
||||||
run: dotnet test --no-build --configuration Release --verbosity normal --collect:"XPlat Code Coverage"
|
"GracePeriodDays": 7,
|
||||||
|
"CleanupIntervalHours": 6
|
||||||
- name: Upload coverage
|
},
|
||||||
uses: codecov/codecov-action@v3
|
"Premium": {
|
||||||
with:
|
"FreeQRLimit": 10,
|
||||||
files: coverage.cobertura.xml
|
"PremiumPrice": 12.90,
|
||||||
|
"Features": {
|
||||||
build-and-push:
|
"UnlimitedQR": true,
|
||||||
needs: test
|
"DynamicQR": true,
|
||||||
runs-on: ubuntu-latest
|
"NoAds": true,
|
||||||
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
|
"PrioritySupport": true,
|
||||||
|
"AdvancedAnalytics": true,
|
||||||
steps:
|
"SpeedBoost": true
|
||||||
- name: Checkout
|
}
|
||||||
uses: actions/checkout@v4
|
},
|
||||||
|
"SEO": {
|
||||||
- name: Set up Docker Buildx
|
"KeywordsPT": "qr rapido, gerador qr rapido, qr code rapido, codigo qr rapido, qr gratis rapido",
|
||||||
uses: docker/setup-buildx-action@v3
|
"KeywordsES": "qr rapido, generador qr rapido, codigo qr rapido, qr gratis rapido",
|
||||||
|
"KeywordsEN": "fast qr, quick qr generator, rapid qr code, qr code generator"
|
||||||
- name: Build and push to registry
|
},
|
||||||
run: |
|
"ApplicationName": "QRRapido",
|
||||||
# Determina a tag baseada na branch
|
"Environment": "Personal",
|
||||||
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
|
"Serilog": {
|
||||||
TAG="latest"
|
"SeqUrl": "http://localhost:5341",
|
||||||
else
|
"ApiKey": "",
|
||||||
TAG="develop"
|
"MinimumLevel": {
|
||||||
fi
|
"Default": "Information",
|
||||||
|
"Override": {
|
||||||
# Build da imagem para ARM64 (servidores Ampere OCI)
|
"Microsoft": "Warning",
|
||||||
docker buildx build \
|
"Microsoft.AspNetCore": "Warning",
|
||||||
--platform linux/arm64 \
|
"Microsoft.Hosting.Lifetime": "Information",
|
||||||
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG \
|
"System": "Warning"
|
||||||
--push \
|
}
|
||||||
.
|
}
|
||||||
|
},
|
||||||
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
|
"ResourceMonitoring": {
|
||||||
|
"Enabled": true,
|
||||||
deploy-staging:
|
"IntervalSeconds": 30,
|
||||||
needs: build-and-push
|
"CpuThresholdPercent": 80,
|
||||||
runs-on: ubuntu-latest
|
"MemoryThresholdMB": 512,
|
||||||
if: github.ref == 'refs/heads/develop'
|
"ConsecutiveAlertsBeforeError": 4,
|
||||||
|
"GcCollectionThreshold": 10
|
||||||
steps:
|
},
|
||||||
- name: Deploy to Staging Servers
|
"MongoDbMonitoring": {
|
||||||
run: |
|
"Enabled": true,
|
||||||
# Configura SSH
|
"IntervalMinutes": 5,
|
||||||
mkdir -p ~/.ssh
|
"DatabaseSizeWarningMB": 1024,
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
"DatabaseSizeErrorMB": 5120,
|
||||||
chmod 600 ~/.ssh/id_rsa
|
"GrowthRateWarningMBPerHour": 100,
|
||||||
|
"IncludeCollectionStats": true,
|
||||||
# Deploy no Servidor 1
|
"CollectionsToMonitor": [ "Users", "QRCodeHistory", "AdFreeSessions" ]
|
||||||
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 << 'EOF'
|
},
|
||||||
# Para o container atual se existir
|
"HealthChecks": {
|
||||||
docker stop qrrapido-staging || true
|
"MongoDB": {
|
||||||
docker rm qrrapido-staging || true
|
"TimeoutSeconds": 5,
|
||||||
|
"IncludeDatabaseSize": true,
|
||||||
# Remove imagem antiga
|
"TestQuery": true
|
||||||
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop || true
|
},
|
||||||
|
"Seq": {
|
||||||
# Puxa nova imagem
|
"TimeoutSeconds": 3,
|
||||||
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
"TestLogMessage": "QRRapido health check test"
|
||||||
|
},
|
||||||
# Executa novo container
|
"Resources": {
|
||||||
docker run -d \
|
"CpuThresholdPercent": 85,
|
||||||
--name qrrapido-staging \
|
"MemoryThresholdMB": 600,
|
||||||
--restart unless-stopped \
|
"GcPressureThreshold": 15
|
||||||
-p 5000:8080 \
|
},
|
||||||
-e ASPNETCORE_ENVIRONMENT=Staging \
|
"ExternalServices": {
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
"TimeoutSeconds": 10,
|
||||||
EOF
|
"TestStripeConnection": true,
|
||||||
|
"TestGoogleAuth": false,
|
||||||
# Deploy no Servidor 2
|
"TestMicrosoftAuth": false
|
||||||
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 << 'EOF'
|
}
|
||||||
# Para o container atual se existir
|
},
|
||||||
docker stop qrrapido-staging || true
|
"Logging": {
|
||||||
docker rm qrrapido-staging || true
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
# Remove imagem antiga
|
"Microsoft.AspNetCore": "Warning"
|
||||||
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop || true
|
}
|
||||||
|
},
|
||||||
# Puxa nova imagem
|
"AllowedHosts": "*"
|
||||||
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
}
|
||||||
|
|
||||||
# Executa novo container
|
|
||||||
docker run -d \
|
|
||||||
--name qrrapido-staging \
|
|
||||||
--restart unless-stopped \
|
|
||||||
-p 5000:8080 \
|
|
||||||
-e ASPNETCORE_ENVIRONMENT=Staging \
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
|
||||||
EOF
|
|
||||||
|
|
||||||
deploy-production:
|
|
||||||
needs: build-and-push
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
environment: production
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Deploy to Production Servers
|
|
||||||
run: |
|
|
||||||
# Debug SSH setup
|
|
||||||
echo "=== Configurando SSH ==="
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
|
|
||||||
# Verifica se a chave foi criada
|
|
||||||
echo "=== Verificando chave SSH ==="
|
|
||||||
ls -la ~/.ssh/
|
|
||||||
echo "Primeiras linhas da chave:"
|
|
||||||
head -2 ~/.ssh/id_rsa
|
|
||||||
|
|
||||||
# Testa conexão SSH com debug
|
|
||||||
echo "=== Testando conexão SSH ==="
|
|
||||||
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -v ubuntu@141.148.162.114 'echo "Conexão SSH funcionando!"' || echo "Falha na conexão SSH"
|
|
||||||
|
|
||||||
# Se a conexão funcionou, continua com o deploy
|
|
||||||
echo "=== Iniciando Deploy ==="
|
|
||||||
|
|
||||||
# Deploy no Servidor 1 (com NGINX)
|
|
||||||
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 << 'EOF'
|
|
||||||
# Para o container atual se existir
|
|
||||||
docker stop qrrapido-prod || true
|
|
||||||
docker rm qrrapido-prod || true
|
|
||||||
|
|
||||||
# Remove imagem antiga
|
|
||||||
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest || true
|
|
||||||
|
|
||||||
# Puxa nova imagem
|
|
||||||
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
|
|
||||||
# Executa novo container
|
|
||||||
docker run -d \
|
|
||||||
--name qrrapido-prod \
|
|
||||||
--restart unless-stopped \
|
|
||||||
-p 5001:8080 \
|
|
||||||
-e ASPNETCORE_ENVIRONMENT=Production \
|
|
||||||
-e ASPNETCORE_URLS=http://+:8080 \
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
|
|
||||||
# Recarrega NGINX para garantir que está apontando para o novo container
|
|
||||||
sudo nginx -t && sudo systemctl reload nginx
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Deploy no Servidor 2
|
|
||||||
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 << 'EOF'
|
|
||||||
# Para o container atual se existir
|
|
||||||
docker stop qrrapido-prod || true
|
|
||||||
docker rm qrrapido-prod || true
|
|
||||||
|
|
||||||
# Remove imagem antiga
|
|
||||||
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest || true
|
|
||||||
|
|
||||||
# Puxa nova imagem
|
|
||||||
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
|
|
||||||
# Executa novo container
|
|
||||||
docker run -d \
|
|
||||||
--name qrrapido-prod \
|
|
||||||
--restart unless-stopped \
|
|
||||||
-p 5001:8080 \
|
|
||||||
-e ASPNETCORE_ENVIRONMENT=Production \
|
|
||||||
-e ASPNETCORE_URLS=http://+:8080 \
|
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
EOF
|
|
||||||
|
|
||||||
- name: Health Check
|
|
||||||
run: |
|
|
||||||
# Aguarda um pouco para os containers subirem
|
|
||||||
sleep 30
|
|
||||||
|
|
||||||
# Verifica se os serviços estão respondendo
|
|
||||||
echo "Verificando Servidor 1..."
|
|
||||||
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 'curl -f http://localhost:5001/health || echo "Servidor 1 pode não estar respondendo"'
|
|
||||||
|
|
||||||
echo "Verificando Servidor 2..."
|
|
||||||
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 'curl -f http://localhost:5001/health || echo "Servidor 2 pode não estar respondendo"'
|
|
||||||
Loading…
Reference in New Issue
Block a user