diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..77393ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY *.sln . +COPY DotnetApiPostgres.Api/*.csproj ./DotnetApiPostgres.Api/ +RUN dotnet restore + +# copy everything else and build app +COPY DotnetApiPostgres.Api/. ./DotnetApiPostgres.Api/ +WORKDIR /source/DotnetApiPostgres.Api +RUN dotnet publish -c release -o /app + +# final stage/image +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final +WORKDIR /app +COPY --from=build /app ./ + +ENTRYPOINT ["dotnet", "DotnetApiPostgres.Api.dll"] diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..ae801eb --- /dev/null +++ b/compose.yml @@ -0,0 +1,32 @@ +services: + web_api: + container_name: person_api_app + build: . + image: people-api:1.0.0 + ports: + - 8080:8080 + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://+:8080 + - ConnectionStrings__default=Host=db;Database=PersonDb;Username=postgres;Password=p@55w0rd + depends_on: + db: + condition: service_healthy + restart: true + db: + image: postgres:16.9-bullseye + container_name: postgres_db + ports: + - 5432:5432 + environment: + POSTGRES_PASSWORD: p@55w0rd + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U postgres" ] + interval: 10s + retries: 5 + start_period: 30s + timeout: 10s +volumes: + postgres_data: