diff --git a/crud-app/.dockerignore b/crud-app/.dockerignore new file mode 100644 index 0000000..effc8ff --- /dev/null +++ b/crud-app/.dockerignore @@ -0,0 +1,13 @@ +bin/ +obj/ +.vs/ +.vscode/ +*.user +*.suo +*.sln.docstates +keploy/ +img/ +*.md +docker-compose.yml +.gitignore +dotnet-install.sh diff --git a/crud-app/Dockerfile b/crud-app/Dockerfile new file mode 100644 index 0000000..d2d6d7a --- /dev/null +++ b/crud-app/Dockerfile @@ -0,0 +1,23 @@ +# ---- Build Stage ---- +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /src + +# Copy csproj and restore dependencies first (layer caching) +COPY simpleAPI_v1.csproj ./ +RUN dotnet restore simpleAPI_v1.csproj + +# Copy the rest of the source code and build +COPY . ./ +RUN dotnet publish simpleAPI_v1.csproj -c Release -o /app/publish + +# ---- Runtime Stage ---- +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime +WORKDIR /app + +COPY --from=build /app/publish . + +# .NET 8 defaults to port 8080 +EXPOSE 8080 +ENV ASPNETCORE_URLS=http://+:8080 + +ENTRYPOINT ["dotnet", "simpleAPI_v1.dll"] diff --git a/crud-app/docker-compose.yml b/crud-app/docker-compose.yml index ee081b9..20e7992 100644 --- a/crud-app/docker-compose.yml +++ b/crud-app/docker-compose.yml @@ -1,12 +1,31 @@ -version: "3.9" services: postgres: - image: postgres:10.5 - container_name: postgresDb - restart: always - environment: - - POSTGRES_DB=postgres - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=password - ports: - - '5432:5432' \ No newline at end of file + image: postgres:10.5 + container_name: postgresDb + restart: always + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=password + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + app: + build: + context: . + dockerfile: Dockerfile + container_name: crud-app + restart: on-failure + ports: + - "5249:8080" + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ConnectionStrings__DefaultConnection=Host=postgres;Port=5432;Database=postgres;Username=postgres;Password=password + depends_on: + postgres: + condition: service_healthy