Compare commits
15 Commits
test
...
fcfd265c46
| Author | SHA1 | Date | |
|---|---|---|---|
| fcfd265c46 | |||
| bc3a44d5ea | |||
| cded235985 | |||
| f15143349e | |||
| 7d8f15104c | |||
| e2b5f2db8c | |||
| 57ba629d2d | |||
| d30ee959ee | |||
| 4e653fd91d | |||
| b4ee875ac8 | |||
| 7d395e2295 | |||
| ddc66efc16 | |||
| 82348a0112 | |||
| e495be1c0b | |||
| 5a530210c0 |
@@ -12,6 +12,7 @@
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
@@ -26,7 +27,4 @@ README.md
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
# Ensure the build output is NOT ignored
|
||||
!**/bin/Release/**/publish/
|
||||
!**/publish/
|
||||
!.git/refs/heads/**
|
||||
74
.drone.yml
74
.drone.yml
@@ -1,68 +1,24 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build-and-package
|
||||
name: package
|
||||
|
||||
steps:
|
||||
- name: build-test-publish
|
||||
image: nexus.khongisa.co.za/sdk:10.0
|
||||
- name: dotnet publish
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||
commands:
|
||||
- dotnet restore --source https://nexus.khongisa.co.za/repository/nuget-group/index.json --no-cache
|
||||
- dotnet build --configuration Release --no-restore
|
||||
- dotnet test --configuration Release --no-build
|
||||
- dotnet publish --configuration Release --no-build
|
||||
- dotnet publish --configuration Release
|
||||
- ls ./SampleApi/bin/Release/net8.0/publish/
|
||||
|
||||
- name: docker-build-and-push
|
||||
- name: docker build and push
|
||||
image: plugins/docker
|
||||
settings:
|
||||
registry: nexus.khongisa.co.za
|
||||
repo: nexus.khongisa.co.za/webapitest
|
||||
tags: [ "${DRONE_BUILD_NUMBER}", "latest" ]
|
||||
username: { from_secret: docker_username }
|
||||
password: { from_secret: docker_password }
|
||||
|
||||
- name: vulnerability-scan
|
||||
image: aquasec/trivy:0.50.1
|
||||
environment:
|
||||
TRIVY_USERNAME: { from_secret: docker_username }
|
||||
TRIVY_PASSWORD: { from_secret: docker_password }
|
||||
commands:
|
||||
- trivy image --image-src remote --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
exclude:
|
||||
- promote
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: deploy-to-uat
|
||||
|
||||
depends_on:
|
||||
- build-and-package
|
||||
|
||||
steps:
|
||||
- name: uat-deployment
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host: { from_secret: ssh_host }
|
||||
username: { from_secret: ssh_user }
|
||||
password: { from_secret: ssh_password }
|
||||
script:
|
||||
- echo $DOCKER_PASSWORD | docker login nexus.khongisa.co.za -u $DOCKER_USERNAME --password-stdin
|
||||
- docker pull nexus.khongisa.co.za/webapitest:latest
|
||||
- docker stop webapi 2>/dev/null || true
|
||||
- docker rm webapi 2>/dev/null || true
|
||||
- docker run -d --name webapi --restart unless-stopped -e ASPNETCORE_ENVIRONMENT=Development -p 4000:8081 nexus.khongisa.co.za/webapitest:latest
|
||||
environment:
|
||||
DOCKER_USERNAME: { from_secret: docker_username }
|
||||
DOCKER_PASSWORD: { from_secret: docker_password }
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- promote
|
||||
target:
|
||||
- staging
|
||||
repo: gitea.khongisa.co.za/khwezi/sampleapi
|
||||
registry: gitea.khongisa.co.za
|
||||
insecure: false
|
||||
username:
|
||||
from_secret: gitea-username
|
||||
password:
|
||||
from_secret: gitea-password
|
||||
dockerfile: Dockerfile
|
||||
context: ./SampleApi/bin/Release/net8.0/publish/
|
||||
26
Dockerfile
26
Dockerfile
@@ -1,11 +1,27 @@
|
||||
FROM nexus.khongisa.co.za/aspnet:10.0 AS final
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
COPY ["SampleApi/SampleApi.csproj", "SampleApi/"]
|
||||
RUN dotnet restore "SampleApi/SampleApi.csproj"
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN dotnet publish "SampleApi/SampleApi.csproj" \
|
||||
-c Release \
|
||||
-o /app/publish \
|
||||
--no-restore \
|
||||
/p:UseAppHost=false
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||
WORKDIR /app
|
||||
|
||||
USER app
|
||||
|
||||
COPY --chown=app:app ./SampleApi/bin/Release/net10.0/publish/ .
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=8081
|
||||
EXPOSE 8081
|
||||
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
RUN ls -la /app
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=8081
|
||||
|
||||
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
||||
@@ -1,43 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace SampleApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class DemoController : ControllerBase
|
||||
{
|
||||
// GET: api/<DemoController>
|
||||
[HttpGet]
|
||||
public IEnumerable<string> Get()
|
||||
{
|
||||
return new string[] { "value1", "value2" };
|
||||
}
|
||||
|
||||
// GET api/<DemoController>/5
|
||||
[HttpGet("{id}")]
|
||||
public string Get(int id)
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
|
||||
// POST api/<DemoController>
|
||||
[HttpPost]
|
||||
public void Post([FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// PUT api/<DemoController>/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE api/<DemoController>/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,25 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.MapHealthChecks("/health");
|
||||
app.UseRouting();
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>cfe6b4ce-2d40-4273-b3a3-e4df67304fc5</UserSecretsId>
|
||||
@@ -9,9 +9,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||
<PackageReference Include="Polly" Version="8.6.6" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user