feat: pipeline
Some checks are pending
Deploy ASP.NET MVC to OCI / build-and-deploy (push) Waiting to run
Some checks are pending
Deploy ASP.NET MVC to OCI / build-and-deploy (push) Waiting to run
This commit is contained in:
parent
16001eb15b
commit
cbda3db3f3
30
.dockerignore
Normal file
30
.dockerignore
Normal file
@ -0,0 +1,30 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
106
.gitea/workflows/deploy.yml
Normal file
106
.gitea/workflows/deploy.yml
Normal file
@ -0,0 +1,106 @@
|
||||
name: Deploy ASP.NET MVC to OCI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
pull_request:
|
||||
branches: [ main, master ]
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: registry.redecarneir.us
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
registry.redecarneir.us/onlyoneaccesstemplate:latest
|
||||
registry.redecarneir.us/onlyoneaccesstemplate:${{ github.sha }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Deploy to OCI Server
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: 129.146.116.218
|
||||
username: ${{ secrets.SSH_USERNAME }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
port: 22
|
||||
script: |
|
||||
# Login no registry Docker
|
||||
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login registry.redecarneir.us -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
|
||||
|
||||
# Para qualquer container que esteja usando a porta 80
|
||||
echo "=== Verificando containers na porta 80 ==="
|
||||
CONTAINERS_PORT_80=$(docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" | grep ':80->' | awk '{print $2}' || true)
|
||||
if [ ! -z "$CONTAINERS_PORT_80" ]; then
|
||||
echo "Parando containers na porta 80: $CONTAINERS_PORT_80"
|
||||
echo "$CONTAINERS_PORT_80" | xargs -r docker stop
|
||||
echo "$CONTAINERS_PORT_80" | xargs -r docker rm
|
||||
else
|
||||
echo "Nenhum container encontrado na porta 80"
|
||||
fi
|
||||
|
||||
# Para o container anterior da aplicação (se existir)
|
||||
docker stop onlyoneaccesstemplate || true
|
||||
docker rm onlyoneaccesstemplate || true
|
||||
|
||||
# Remove imagem antiga
|
||||
docker rmi registry.redecarneir.us/onlyoneaccesstemplate:latest || true
|
||||
|
||||
# Puxa nova imagem
|
||||
docker pull registry.redecarneir.us/onlyoneaccesstemplate:latest
|
||||
|
||||
# Executa o novo container na porta 80
|
||||
docker run -d \
|
||||
--name onlyoneaccesstemplate \
|
||||
--restart unless-stopped \
|
||||
-p 80:8080 \
|
||||
-p 443:8081 \
|
||||
-e ASPNETCORE_ENVIRONMENT=Production \
|
||||
-e ASPNETCORE_URLS="http://+:8080;https://+:8081" \
|
||||
registry.redecarneir.us/onlyoneaccesstemplate:latest
|
||||
|
||||
# Limpa imagens não utilizadas
|
||||
docker image prune -f
|
||||
|
||||
# Verifica se o container está rodando
|
||||
docker ps | grep onlyoneaccesstemplate
|
||||
|
||||
# Testa se a aplicação está respondendo na porta 80
|
||||
sleep 10
|
||||
curl -f http://localhost:80 || echo "Aplicação pode estar inicializando..."
|
||||
|
||||
- name: Verify deployment
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: 129.146.116.218
|
||||
username: ${{ secrets.SSH_USERNAME }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
port: 22
|
||||
script: |
|
||||
echo "=== Status dos containers ==="
|
||||
docker ps -a | grep onlyoneaccesstemplate
|
||||
|
||||
echo "=== Logs da aplicação (últimas 20 linhas) ==="
|
||||
docker logs onlyoneaccesstemplate --tail 20
|
||||
|
||||
echo "=== Teste de conectividade ==="
|
||||
curl -I http://localhost:80 || echo "Aplicação ainda não está acessível"
|
||||
@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.35122.118
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnlyOneAccessTemplate", "OnlyOneAccessTemplate\OnlyOneAccessTemplate.csproj", "{2A672B8D-D16E-452E-A975-A3E19625453B}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OnlyOneAccessTemplate", "OnlyOneAccessTemplate\OnlyOneAccessTemplate.csproj", "{2A672B8D-D16E-452E-A975-A3E19625453B}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pipeline", "pipeline", "{21A583BA-1BDC-42C4-BE42-DD13267BDA20}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.gitea\workflows\deploy.yml = .gitea\workflows\deploy.yml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
30
OnlyOneAccessTemplate/Dockerfile
Normal file
30
OnlyOneAccessTemplate/Dockerfile
Normal file
@ -0,0 +1,30 @@
|
||||
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["OnlyOneAccessTemplate/OnlyOneAccessTemplate.csproj", "OnlyOneAccessTemplate/"]
|
||||
RUN dotnet restore "./OnlyOneAccessTemplate/OnlyOneAccessTemplate.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/OnlyOneAccessTemplate"
|
||||
RUN dotnet build "./OnlyOneAccessTemplate.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./OnlyOneAccessTemplate.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
|
||||
# Healthcheck (adicional - opcional mas recomendado)
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/health || exit 1
|
||||
|
||||
ENTRYPOINT ["dotnet", "OnlyOneAccessTemplate.dll"]
|
||||
@ -4,6 +4,8 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>c25bc394-1044-45e1-85e6-111f7f46b232</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -16,6 +18,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="3.4.0" />
|
||||
<PackageReference Include="Polly" Version="8.4.0" />
|
||||
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
|
||||
|
||||
@ -1,4 +1,40 @@
|
||||
{
|
||||
{
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5201"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://localhost:7299;http://localhost:5201"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Container (Dockerfile)": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTP_PORTS": "8080"
|
||||
},
|
||||
"publishAllPorts": true
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
@ -7,32 +43,5 @@
|
||||
"applicationUrl": "http://localhost:65221",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5201",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7299;http://localhost:5201",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user