diff --git a/backend/.dockerignore b/backend/.dockerignore index fe1152b..94630a0 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -1,3 +1,4 @@ +# Ignore common files that shouldn't be in the container **/.classpath **/.dockerignore **/.env @@ -13,16 +14,23 @@ **/*.jfm **/azds.yaml **/bin +**/obj **/charts **/docker-compose* **/Dockerfile* **/node_modules **/npm-debug.log -**/obj -**/secrets.dev.yaml -**/values.dev.yaml -LICENSE -README.md +**/.idea +**/.vs +**/.vscode +**/*.user +**/*.suo +**/*.userosscache +**/*.sln.docstates + +# Include all .csproj files - they are needed for the build +!**/*.csproj +!**/*.sln !**/.gitignore !.git/HEAD !.git/config diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..aea9bcb --- /dev/null +++ b/backend/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7fb478c --- /dev/null +++ b/docker-compose.yml @@ -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