-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor progress adding another (users) service
- Loading branch information
1 parent
46f2d77
commit 73fb63b
Showing
20 changed files
with
399 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
# Postgres | ||
POSTGRES_PASSWORD=mysecretpassword | ||
POSTGRES_USER=todos | ||
POSTGRES_DB=todos | ||
POSTGRES_USER=postgres | ||
POSTGRES_DB=postgres | ||
POSTGRES_HOST=localhost | ||
POSTGRES_PORT=5432 | ||
|
||
# Open Telemetry Collector | ||
OTEL_COLLECTOR_HOST="http://otel-collector:4317" | ||
|
||
# Services | ||
DATABASE_HOST="postgres" | ||
ENVIRONMENT_NAME="Docker" | ||
|
||
# Todos API | ||
ASPNETCORE_ENVIRONMENT="Docker" | ||
ASPNETCORE_ENVIRONMENT=${ENVIRONMENT_NAME} | ||
ServiceOptions__ServiceName="Todos API" | ||
ServiceOptions__ConnectionString="Host=postgres; Database=todos; Username=todos; Password=mysecretpassword" | ||
ServiceOptions__ConnectionString="Host=${DATABASE_HOST}; Database=todos; Username=${POSTGRES_USER}; Password=${POSTGRES_PASSWORD}" | ||
ServiceOptions__HangfireEnabled="true" | ||
ServiceOptions__TelemetryCollectorHost=${OTEL_COLLECTOR_HOST} | ||
|
||
# Users API | ||
ASPNETCORE_ENVIRONMENT=${ENVIRONMENT_NAME} | ||
ServiceOptions__ServiceName="Users API" | ||
ServiceOptions__ConnectionString="Host=postgres; Database=users; Username=${POSTGRES_USER}; Password=${POSTGRES_PASSWORD}" | ||
ServiceOptions__HangfireEnabled="true" | ||
ServiceOptions__TelemetryCollectorHost="http://otel-collector:4317" | ||
ServiceOptions__TelemetryCollectorHost=${OTEL_COLLECTOR_HOST} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Build Users Api | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
paths: | ||
- ".github/workflows/users.yml" | ||
- "dockerfiles/users.Dockerfile" | ||
- "src/**" | ||
pull_request: | ||
branches: | ||
- "main" | ||
paths: | ||
- ".github/workflows/users.yml" | ||
- "dockerfiles/users.Dockerfile" | ||
- "src/**" | ||
|
||
jobs: | ||
dotnet-test: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./src/ | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
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 | ||
|
||
docker-build: | ||
runs-on: ubuntu-latest | ||
needs: dotnet-test | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build the Docker image | ||
run: docker build -f dockerfiles/users.Dockerfile src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
WORKDIR /app | ||
|
||
COPY *.sln ./ | ||
COPY */*.csproj ./ | ||
|
||
RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done | ||
RUN dotnet restore | ||
|
||
COPY . . | ||
RUN dotnet build | ||
RUN dotnet publish Ast.Users/Ast.Users.csproj -c Release -o out | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime | ||
WORKDIR /app | ||
|
||
COPY --from=build /app/out . | ||
ENTRYPOINT [ "dotnet", "Ast.Users.dll" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MediatR" Version="12.2.0"/> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Ast.Platform\Ast.Platform.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
14 changes: 14 additions & 0 deletions
14
src/Ast.Users/Database/Configurations/UserConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Ast.Users.Database.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Ast.Users.Database.Configurations; | ||
|
||
public class UserConfiguration : IEntityTypeConfiguration<User> | ||
{ | ||
public void Configure(EntityTypeBuilder<User> todo) | ||
{ | ||
todo.HasKey(t => t.Id); | ||
todo.Property(t => t.Name).HasMaxLength(UserConstants.Name.MaxLength).IsRequired(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Ast.Users.Database.Configurations; | ||
|
||
public static class UserConstants | ||
{ | ||
public static class Name | ||
{ | ||
public const int MaxLength = 250; | ||
public const int MinLength = 1; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Ast.Users/Database/Migrations/20240620214244_Initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
src/Ast.Users/Database/Migrations/20240620214244_Initial.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace Ast.Users.Database.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class Initial : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Users", | ||
columns: table => new | ||
{ | ||
Id = table.Column<Guid>(type: "uuid", nullable: false), | ||
Name = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Users", x => x.Id); | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Users"); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Ast.Users/Database/Migrations/UserContextModelSnapshot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// <auto-generated /> | ||
using System; | ||
using Ast.Users.Database; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; | ||
|
||
#nullable disable | ||
|
||
namespace Ast.Users.Database.Migrations | ||
{ | ||
[DbContext(typeof(UserContext))] | ||
partial class UserContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
#pragma warning disable 612, 618 | ||
modelBuilder | ||
.HasAnnotation("ProductVersion", "8.0.4") | ||
.HasAnnotation("Relational:MaxIdentifierLength", 63); | ||
|
||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); | ||
|
||
modelBuilder.Entity("Ast.Users.Database.Models.User", b => | ||
{ | ||
b.Property<Guid>("Id") | ||
.ValueGeneratedOnAdd() | ||
.HasColumnType("uuid"); | ||
b.Property<string>("Name") | ||
.IsRequired() | ||
.HasMaxLength(250) | ||
.HasColumnType("character varying(250)"); | ||
b.HasKey("Id"); | ||
b.ToTable("Users"); | ||
}); | ||
#pragma warning restore 612, 618 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Ast.Users.Database.Models; | ||
|
||
public class User | ||
{ | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
Check warning on line 6 in src/Ast.Users/Database/Models/User.cs GitHub Actions / dotnet-test
Check warning on line 6 in src/Ast.Users/Database/Models/User.cs GitHub Actions / dotnet-test
Check warning on line 6 in src/Ast.Users/Database/Models/User.cs GitHub Actions / dotnet-test
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Ast.Users.Database.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Ast.Users.Database; | ||
|
||
public class UserContext : DbContext | ||
{ | ||
public DbSet<User> Users { get; init; } | ||
|
||
public UserContext(DbContextOptions options) : base(options) | ||
{ | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(UserContext).Assembly); | ||
} | ||
} |
Oops, something went wrong.