Skip to content

Commit

Permalink
Merge pull request #16 from MadL1me/dev
Browse files Browse the repository at this point in the history
Release v0.2.1 (Npgsql, bugfixes)
  • Loading branch information
MadL1me authored Jul 7, 2022
2 parents 9082b92 + ef753ad commit 8bdb81b
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Level X/Asp.AwesomeTemplates.Main.Nuget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>0.2.0</PackageVersion>
<PackageVersion>0.2.1</PackageVersion>
<PackageId>Asp.AwesomeTemplates.Main</PackageId>
<Title>ASP.NET 6 awesome templates</Title>
<Authors>Ilya Klimenko (MadL1me)</Authors>
Expand Down
28 changes: 27 additions & 1 deletion Level X/Template/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,29 @@
}
]
},
"UseEfDatabase": {
"type": "parameter",
"description": "Adds Database with Entity Framework and Docker-compose",
"datatype": "choice",
"defaultValue": "pgsql",
"choices": [
{
"choice": "pgsql",
"description": "Use PostgreSQL database inside docker compose with pgAdmin"
},
{
"choice": "none",
"description": "Do not use any database provider"
}
]
},
"UsePostgreSql": {
"type": "computed",
"value": "(UseEfDatabase == \"pgsql\")"
},
"UseReact": {
"type": "computed",
"value": "(UseSpaFrontendFramework == \"React\""
"value": "(UseSpaFrontendFramework == \"React\")"
}
},
"sources": [
Expand All @@ -59,6 +79,12 @@
"exclude": [
"react-ui/**"
]
},
{
"condition": "(!UsePostgreSql)",
"exclude": [
"Data/Asp.AwesomeTemplateDbContext.cs"
]
}
]
}
Expand Down
11 changes: 10 additions & 1 deletion Level X/Template/Asp.AwesomeTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<!--#endif -->

<!--#if (UsePostgreSql)-->
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
</ItemGroup>
<!--#endif -->
</Project>
2 changes: 1 addition & 1 deletion Level X/Template/Controllers/ExampleController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;

namespace TestYY.Controllers;
namespace Asp.AwesomeTemplate.Controllers;

public record ExampleUserDto
{
Expand Down
16 changes: 16 additions & 0 deletions Level X/Template/Data/Asp.AwesomeTemplateDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;

namespace Asp.AwesomeTemplate.Data;

public sealed class Asp.AwesomeTemplateDbContext : DbContext
{
public Asp.AwesomeTemplateDbContext(DbContextOptions options) : base(options)
{

}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
8 changes: 4 additions & 4 deletions Level X/Template/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build
WORKDIR /src
COPY ["..", "Asp.AwesomeTemplate/"]
COPY ["Asp.AwesomeTemplate.csproj", "Asp.AwesomeTemplate/"]
RUN dotnet restore "Asp.AwesomeTemplate/Asp.AwesomeTemplate.csproj"
COPY . .
COPY . ./Asp.AwesomeTemplate
WORKDIR "/src/Asp.AwesomeTemplate"
RUN dotnet build "Asp.AwesomeTemplate.csproj" -c Release -o /app/build

Expand Down
12 changes: 11 additions & 1 deletion Level X/Template/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
using System.Text;
#if(EnableSwaggerSupport)
using Microsoft.OpenApi.Models;
#endif
#if (UsePostgreSql)
using Microsoft.EntityFrameworkCore;
using Asp.AwesomeTemplate.Data;
#endif

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -7,15 +14,18 @@
builder.Services.AddControllers();

#if(EnableSwaggerSupport)

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Asp.AwesomeTemplate API", Version = "v1" });
});
#endif

#if (UsePostgreSql)
builder.Services.AddDbContext<Asp.AwesomeTemplateDbContext>(
options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
#endif

var app = builder.Build();
Expand Down
3 changes: 3 additions & 0 deletions Level X/Template/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Host=postgres;User ID=postgres;Password=changeme;Port=5432;Database=postgres"
}
}
44 changes: 44 additions & 0 deletions Level X/Template/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,48 @@ services:
volumes:
- ./react-ui:/usr/src/app/react-ui
- /usr/src/app/react-ui/node_modules
//#if(UsePostgreSql)
networks:
- postgres
//#endif
//#endif
//#if(UsePostgreSql)
postgres:
container_name: postgres_container
image: postgres
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped

pgadmin:
container_name: pgadmin_container
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- pgadmin:/var/lib/pgadmin

ports:
- "${PGADMIN_PORT:-5050}:80"
networks:
- postgres
restart: unless-stopped

networks:
postgres:
driver: bridge

volumes:
postgres:
pgadmin:
//#endif
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ If you don't want to use it, you can start with Level X template like this:
1. Install template:

```sh
dotnet new --install Asp.AwesomeTemplates.Main::0.0.2
dotnet new --install Asp.AwesomeTemplates.Main::0.2.0
```

2. Create template with dotnet new:

```sh
dotnet new aspnet-awesome-main -o "MyAwesomeProjectName"
dotnet new aspnet-awesome-main -o "MyAwesomeProjectName" -U React
```

3. Use your template! (For example, go to Level X template [README](https://github.com/MadL1me/aspnet-awesome-templates/blob/master/Level%20X/Template/README.md), it will have all required commands with your configuration)
Expand Down

0 comments on commit 8bdb81b

Please sign in to comment.