fix: add Dockerfile and docker-compose configuration for backend and frontend services
Some checks failed
Build and Deploy to Production / deploy (push) Has been cancelled
Some checks failed
Build and Deploy to Production / deploy (push) Has been cancelled
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
# Ignore common files that shouldn't be in the container
|
||||||
**/.classpath
|
**/.classpath
|
||||||
**/.dockerignore
|
**/.dockerignore
|
||||||
**/.env
|
**/.env
|
||||||
@@ -13,16 +14,23 @@
|
|||||||
**/*.jfm
|
**/*.jfm
|
||||||
**/azds.yaml
|
**/azds.yaml
|
||||||
**/bin
|
**/bin
|
||||||
|
**/obj
|
||||||
**/charts
|
**/charts
|
||||||
**/docker-compose*
|
**/docker-compose*
|
||||||
**/Dockerfile*
|
**/Dockerfile*
|
||||||
**/node_modules
|
**/node_modules
|
||||||
**/npm-debug.log
|
**/npm-debug.log
|
||||||
**/obj
|
**/.idea
|
||||||
**/secrets.dev.yaml
|
**/.vs
|
||||||
**/values.dev.yaml
|
**/.vscode
|
||||||
LICENSE
|
**/*.user
|
||||||
README.md
|
**/*.suo
|
||||||
|
**/*.userosscache
|
||||||
|
**/*.sln.docstates
|
||||||
|
|
||||||
|
# Include all .csproj files - they are needed for the build
|
||||||
|
!**/*.csproj
|
||||||
|
!**/*.sln
|
||||||
!**/.gitignore
|
!**/.gitignore
|
||||||
!.git/HEAD
|
!.git/HEAD
|
||||||
!.git/config
|
!.git/config
|
||||||
|
|||||||
47
backend/Dockerfile
Normal file
47
backend/Dockerfile
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Build stage - using .NET SDK
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
# Copy project files first for better layer caching
|
||||||
|
COPY ["*.sln", "./"]
|
||||||
|
COPY ["JoaoLoureiro.Portfolio.Api/*.csproj", "JoaoLoureiro.Portfolio.Api/"]
|
||||||
|
COPY ["JoaoLoureiro.Portfolio.Application/*.csproj", "JoaoLoureiro.Portfolio.Application/"]
|
||||||
|
COPY ["JoaoLoureiro.Portfolio.Domain/*.csproj", "JoaoLoureiro.Portfolio.Domain/"]
|
||||||
|
COPY ["JoaoLoureiro.Portfolio.Infrastructure/*.csproj", "JoaoLoureiro.Portfolio.Infrastructure/"]
|
||||||
|
|
||||||
|
# Restore dependencies
|
||||||
|
WORKDIR "/src/JoaoLoureiro.Portfolio.Api"
|
||||||
|
RUN dotnet restore
|
||||||
|
|
||||||
|
# Copy remaining source code
|
||||||
|
WORKDIR "/src"
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build and publish
|
||||||
|
WORKDIR "/src/JoaoLoureiro.Portfolio.Api"
|
||||||
|
RUN dotnet publish -c Release -o /app/publish
|
||||||
|
|
||||||
|
# Runtime stage
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# curl used by docker-compose healthcheck
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y curl \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Configure logging to show in container logs
|
||||||
|
ENV ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||||
|
ENV ASPNETCORE_URLS=http://+:3001
|
||||||
|
ENV ASPNETCORE_HTTP_PORT=3001
|
||||||
|
ENV ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true
|
||||||
|
|
||||||
|
# Expose the port
|
||||||
|
EXPOSE 3001
|
||||||
|
|
||||||
|
# Copy published app
|
||||||
|
COPY --from=build /app/publish .
|
||||||
|
|
||||||
|
# Entry point with enhanced logging
|
||||||
|
ENTRYPOINT ["dotnet", "JoaoLoureiro.Portfolio.Api.dll"]
|
||||||
47
docker-compose.yml
Normal file
47
docker-compose.yml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
# Backend Service
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: ./backend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: portfolio-backend
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Production
|
||||||
|
- ASPNETCORE_URLS=http://+:80
|
||||||
|
networks:
|
||||||
|
- traefik_network
|
||||||
|
restart: unless-stopped
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.portfolio-backend.rule=Host(`api.yourdomain.com`)"
|
||||||
|
- "traefik.http.routers.portfolio-backend.entrypoints=websecure"
|
||||||
|
- "traefik.http.services.portfolio-backend.loadbalancer.server.port=80"
|
||||||
|
- "traefik.docker.network=traefik_network"
|
||||||
|
- "traefik.http.routers.portfolio-backend.tls.certresolver=le"
|
||||||
|
- "traefik.http.routers.portfolio-backend.middlewares=auth@docker"
|
||||||
|
|
||||||
|
# Frontend Service
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ./frontend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: portfolio-frontend
|
||||||
|
environment:
|
||||||
|
- NEXT_PUBLIC_API_URL=https://api.yourdomain.com
|
||||||
|
networks:
|
||||||
|
- traefik_network
|
||||||
|
restart: unless-stopped
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.portfolio-frontend.rule=Host(`yourdomain.com`, `www.yourdomain.com`)"
|
||||||
|
- "traefik.http.routers.portfolio-frontend.entrypoints=websecure"
|
||||||
|
- "traefik.http.services.portfolio-frontend.loadbalancer.server.port=3000"
|
||||||
|
- "traefik.docker.network=traefik_network"
|
||||||
|
- "traefik.http.routers.portfolio-frontend.tls.certresolver=le"
|
||||||
|
- "traefik.http.routers.portfolio-frontend.middlewares=auth@docker"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
traefik_network:
|
||||||
|
external: true # Using your existing Traefik network
|
||||||
Reference in New Issue
Block a user