Skip to content

Commit

Permalink
Create Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
neozhu authored Nov 26, 2024
1 parent 88a78c5 commit 4c9d608
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/CleanAspire.ClientApp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Stage 1: Build the Blazor Client Application
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src

# Copy the project files and restore dependencies
COPY ["src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj", "src/CleanAspire.ClientApp/"]
RUN dotnet restore "src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj"

# Copy the entire source code and build the application in Release mode
COPY . .
WORKDIR /src/src/CleanAspire.ClientApp
RUN dotnet publish -c Release -o /app/publish

# Stage 2: Serve the Blazor Client Application using Nginx
FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html

# Install OpenSSL to create a self-signed certificate
RUN apk add --no-cache openssl && \
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt -subj "/CN=localhost"

# Clean the default nginx content
RUN rm -rf ./*

# Copy the build output from the previous stage
COPY --from=build /app/publish/wwwroot .

# Copy the generated self-signed certificate and configure Nginx for HTTPS
COPY nginx.conf /etc/nginx/nginx.conf

# Expose port 80 for HTTP traffic and 443 for HTTPS traffic
EXPOSE 80
EXPOSE 443

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

0 comments on commit 4c9d608

Please sign in to comment.