diff --git a/Dockerfile b/Dockerfile index 9cf7cbc..3dce9a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,10 +4,10 @@ EXPOSE 80 FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build WORKDIR /src -COPY *.csproj ./ -RUN dotnet restore +COPY demo001.csproj ./ +RUN dotnet restore demo001.csproj COPY . . -RUN dotnet publish -c Release -o /app/publish +RUN dotnet publish demo001.csproj -c Release -o /app/publish FROM base AS final WORKDIR /app diff --git a/Migrations/AppDbContextModelSnapshot.cs b/Migrations/AppDbContextModelSnapshot.cs new file mode 100644 index 0000000..d56d3de --- /dev/null +++ b/Migrations/AppDbContextModelSnapshot.cs @@ -0,0 +1,41 @@ +using Demo001.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Demo001.Migrations +{ + [DbContext(typeof(AppDbContext))] + partial class AppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .HasAnnotation("ProductVersion", "8.0.0"); + + modelBuilder.Entity("Demo001.Models.TodoItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsComplete") + .HasColumnType("boolean"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("TodoItems"); + }); + } + } +} diff --git a/Migrations/InitialCreate.Designer.cs b/Migrations/InitialCreate.Designer.cs new file mode 100644 index 0000000..bad8327 --- /dev/null +++ b/Migrations/InitialCreate.Designer.cs @@ -0,0 +1,44 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Demo001.Migrations +{ + [DbContext(typeof(Demo001.Data.AppDbContext))] + [Migration("20260514000000_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .HasAnnotation("ProductVersion", "8.0.0"); + + modelBuilder.Entity("Demo001.Models.TodoItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsComplete") + .HasColumnType("boolean"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("TodoItems"); + }); + } + } +} diff --git a/Migrations/InitialCreate.cs b/Migrations/InitialCreate.cs new file mode 100644 index 0000000..df296ca --- /dev/null +++ b/Migrations/InitialCreate.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Demo001.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "TodoItems", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Title = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: true), + IsComplete = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TodoItems", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "TodoItems"); + } + } +} diff --git a/cleanrun.sh b/cleanrun.sh new file mode 100755 index 0000000..f6f364e --- /dev/null +++ b/cleanrun.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +docker compose down +docker compose build --no-cache api +docker compose up + diff --git a/docker-compose.yml b/docker-compose.yml index a067f0a..80c72ce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,11 @@ services: - "5432:5432" volumes: - pgdata:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U demo"] + interval: 10s + timeout: 5s + retries: 5 api: build: @@ -19,9 +24,10 @@ services: environment: ConnectionStrings__DefaultConnection: "Host=db;Port=5432;Database=demo;Username=demo;Password=demo" ports: - - "5000:80" + - "5000:8080" depends_on: - - db + db: + condition: service_healthy volumes: pgdata: