From a90d5409c65868ea25213713fc9d4c64c35a1b65 Mon Sep 17 00:00:00 2001 From: Mostafa Abdo Date: Tue, 4 Mar 2025 09:26:35 -0800 Subject: [PATCH 1/2] feature: dockerize api --- CSETWebApi/Dockerfile | 28 ++++++++++++++++++++++++++++ CSETWebApi/etc/entrypoint.sh | 5 +++++ docker-compose.yml | 14 ++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 CSETWebApi/Dockerfile create mode 100644 CSETWebApi/etc/entrypoint.sh diff --git a/CSETWebApi/Dockerfile b/CSETWebApi/Dockerfile new file mode 100644 index 0000000000..3bcd342585 --- /dev/null +++ b/CSETWebApi/Dockerfile @@ -0,0 +1,28 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +# Set the working directory inside the container +WORKDIR /app + +# Copy the project files (csproj) and restore dependencies +COPY ./CSETWeb_Api/CSETWeb_ApiCore/*.csproj ./ +RUN dotnet restore + +# Copy the rest of the application code +COPY . . + +# Build the application +RUN dotnet build CSETWeb_Api/CSETWeb_ApiCore --configuration Debug + +# Expose the port the app runs on (default for ASP.NET Core is 5000 for HTTP) +EXPOSE 5000 + +# Set environment variables for development mode +ENV ASPNETCORE_ENVIRONMENT=Development +ENV ASPNETCORE_URLS=http://0.0.0.0:5000 + + +COPY ./etc/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod a+x /usr/local/bin/entrypoint.sh + +# Run the application +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/CSETWebApi/etc/entrypoint.sh b/CSETWebApi/etc/entrypoint.sh new file mode 100644 index 0000000000..d5eff8f566 --- /dev/null +++ b/CSETWebApi/etc/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Run the API +cd /app/publish +dotnet CSETWeb_ApiCore.dll \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 049db4318c..bde1a900be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,19 @@ --- services: + api: + container_name: cset-api + hostname: api + build: + context: CSETWebApi + restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - "5000:5000" + volumes: + - ./CSETWebApi:/app + depends_on: + - sqlserver sqlserver: container_name: cset-mssql hostname: mssql From 227640d1a5af2faaf387909d94c017560d2cd227 Mon Sep 17 00:00:00 2001 From: Mostafa Abdo Date: Tue, 4 Mar 2025 09:27:17 -0800 Subject: [PATCH 2/2] fix entrypoint.sh --- CSETWebApi/etc/entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CSETWebApi/etc/entrypoint.sh b/CSETWebApi/etc/entrypoint.sh index d5eff8f566..823457d6fc 100644 --- a/CSETWebApi/etc/entrypoint.sh +++ b/CSETWebApi/etc/entrypoint.sh @@ -1,5 +1,4 @@ #!/bin/bash # Run the API -cd /app/publish -dotnet CSETWeb_ApiCore.dll \ No newline at end of file +dotnet run --project CSETWeb_Api/CSETWeb_ApiCore