Compare commits
3 Commits
ce2aed7347
...
75523a50d0
| Author | SHA1 | Date | |
|---|---|---|---|
| 75523a50d0 | |||
|
|
4fa52762ee | ||
|
|
314e61eef7 |
67
.gitea/workflows/deploy.yml
Normal file
67
.gitea/workflows/deploy.yml
Normal file
@ -0,0 +1,67 @@
|
||||
name: Build and Deploy ASP.NET API
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ] # Apenas quando merge na main
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: localACDC
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '8.0.x' # ou sua versão
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build application
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
|
||||
- name: Run tests (opcional)
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
|
||||
- name: Publish application
|
||||
run: dotnet publish --configuration Release --output ./publish
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build -t ytextractor:${{ github.sha }} .
|
||||
docker tag ytextractor:${{ github.sha }} registry.redecarneir.us/ytextractor:latest
|
||||
docker tag ytextractor:${{ github.sha }} registry.redecarneir.us/ytextractor:${{ github.sha }}
|
||||
|
||||
- name: Push to registry
|
||||
run: |
|
||||
docker push registry.redecarneir.us/ytextractor:latest
|
||||
docker push registry.redecarneir.us/ytextractor:${{ github.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
|
||||
docker run -d \
|
||||
--name ytextractor-api \
|
||||
--restart unless-stopped \
|
||||
-p 5000:8080 \
|
||||
-e ASPNETCORE_ENVIRONMENT=Production \
|
||||
registry.redecarneir.us/ytextractor:latest
|
||||
|
||||
# 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'
|
||||
@ -1,99 +0,0 @@
|
||||
name: CI/CD Pipeline para YTExtractor
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, 'release/*' ]
|
||||
pull_request:
|
||||
branches: [ main, 'release/*' ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --no-restore
|
||||
|
||||
- name: Test
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
|
||||
- name: Build Docker image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
push: false
|
||||
load: true
|
||||
tags: ytextractor:${{ github.sha }}
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
- name: Save Docker image
|
||||
run: docker save ytextractor:${{ github.sha }} > ytextractor-image.tar
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: docker-image
|
||||
path: ytextractor-image.tar
|
||||
|
||||
deploy-localACDC:
|
||||
needs: build
|
||||
runs-on: ubuntu-22.04
|
||||
if: github.ref == 'refs/heads/main'
|
||||
|
||||
steps:
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: docker-image
|
||||
|
||||
- name: Deploy to localACDC
|
||||
run: |
|
||||
echo "Implantando no servidor localACDC"
|
||||
scp ytextractor-image.tar user@localACDC:/tmp/
|
||||
ssh user@localACDC "docker load < /tmp/ytextractor-image.tar && \
|
||||
docker stop ytextractor || true && \
|
||||
docker rm ytextractor || true && \
|
||||
docker run -d --name ytextractor -p 80:80 ytextractor:${{ github.sha }}"
|
||||
|
||||
deploy-pi2Zero:
|
||||
needs: build
|
||||
runs-on: ubuntu-22.04
|
||||
if: startsWith(github.ref, 'refs/heads/release/')
|
||||
|
||||
steps:
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: docker-image
|
||||
|
||||
- name: Deploy to pi2Zero (Orange Pi Zero)
|
||||
run: |
|
||||
echo "Implantando no Orange Pi Zero (recursos limitados)"
|
||||
# Transfere a imagem para o servidor
|
||||
scp ytextractor-image.tar user@pi2Zero:/tmp/
|
||||
|
||||
# Comandos específicos para o Orange Pi Zero (otimizados para baixa memória)
|
||||
ssh user@pi2Zero "
|
||||
# Limpar recursos não utilizados
|
||||
docker system prune -f
|
||||
|
||||
# Parar e remover contêiner existente
|
||||
docker stop ytextractor || true
|
||||
docker rm ytextractor || true
|
||||
|
||||
# Carregar a nova imagem
|
||||
docker load < /tmp/ytextractor-image.tar
|
||||
|
||||
# Iniciar o serviço com limites de memória
|
||||
docker run -d --name ytextractor -p 80:80 --memory=300m --memory-swap=600m ytextractor:${{ github.sha }}
|
||||
"
|
||||
@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YTExtractor", "YTExtractor\
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pipeline", "pipeline", "{5F17A7E6-48F5-4970-B8F6-310BBF9A3C50}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.gitea\workflow\main.yaml = .gitea\workflow\main.yaml
|
||||
.gitea\workflows\deploy.yml = .gitea\workflows\deploy.yml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
|
||||
@ -10,8 +10,9 @@ namespace YTExtractor.Data
|
||||
public MongoDBConnector(IConfiguration configuration)
|
||||
{
|
||||
var connectionString = configuration.GetSection("MongoDbConnection").Value;
|
||||
var databaseName = configuration.GetSection("MongoDbDatabase").Value;
|
||||
var client = new MongoClient(connectionString);
|
||||
_database = client.GetDatabase("YTExtractor");
|
||||
_database = client.GetDatabase(databaseName);
|
||||
_collection = _database.GetCollection<VideoData>("videos");
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,10 @@
|
||||
<Compile Remove="Services\Handlers\YouExposeHandler.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="appsettings.Production.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.69.0.3707" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.12" />
|
||||
|
||||
@ -23,5 +23,7 @@
|
||||
"Workspace": "Dev",
|
||||
"Application": "YTExtractor"
|
||||
}
|
||||
}
|
||||
},
|
||||
"MongoDbConnection": "mongodb://admin:c4rn31r0@192.168.0.82:27017,192.168.0.81:27017/?replicaSet=rs0",
|
||||
"MongoDbDatabase": "YTExtractor"
|
||||
}
|
||||
|
||||
28
YTExtractor/appsettings.Production.json
Normal file
28
YTExtractor/appsettings.Production.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"System": "Warning"
|
||||
}
|
||||
},
|
||||
"Enrich": [
|
||||
"FromLogContext",
|
||||
"WithMachineName",
|
||||
"WithThreadId",
|
||||
"WithEnvironmentUserName"
|
||||
],
|
||||
"Properties": {
|
||||
"Workspace": "Production",
|
||||
"Application": "YTExtractor"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"MongoDbConnection": "mongodb://admin:c4rn31r0@localhost:27017,localhost:27018/?authSource=admin",
|
||||
"MongoDbDatabase": "YTExtractor.Prod",
|
||||
"YouExpose": {
|
||||
"ApiKey": "sua-chave-api-producao-aqui",
|
||||
"ApiUrl": "https://api.youexpose.com/"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user