Fix Dockerfiles
This commit is contained in:
		| @@ -1,21 +1,21 @@ | |||||||
| # --- Etapa 1: Build --- |  | ||||||
| # Usamos la imagen del SDK de .NET 8 para compilar | # Usamos la imagen del SDK de .NET 8 para compilar | ||||||
| FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build | FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build | ||||||
| WORKDIR /src | WORKDIR /src | ||||||
|  |  | ||||||
| # Copiamos el archivo .csproj para restaurar dependencias primero (cache optimization) | # CAMBIO: Las rutas ahora incluyen el prefijo 'backend/' para que coincidan | ||||||
| COPY Inventario.API/Inventario.API.csproj Inventario.API/ | # con la estructura del repositorio, ya que el contexto de build es la raíz. | ||||||
| RUN dotnet restore "Inventario.API/Inventario.API.csproj" | COPY ["backend/Inventario.API.csproj", "backend/"] | ||||||
|  | RUN dotnet restore "backend/Inventario.API.csproj" | ||||||
|  |  | ||||||
| # Copiamos el resto del código fuente | # Copiamos todo el contenido del repositorio al contenedor | ||||||
| COPY . . | COPY . . | ||||||
|  |  | ||||||
| # Publicamos la aplicación en modo Release | # CAMBIO: Nos movemos al directorio correcto del proyecto antes de publicar | ||||||
| WORKDIR "/src/Inventario.API" | WORKDIR "/src/backend" | ||||||
| RUN dotnet publish "Inventario.API.csproj" -c Release -o /app/publish /p:UseAppHost=false | RUN dotnet publish "Inventario.API.csproj" -c Release -o /app/publish /p:UseAppHost=false | ||||||
|  |  | ||||||
| # --- Etapa 2: Final --- | # --- Etapa 2: Final --- | ||||||
| # Usamos la imagen de runtime de ASP.NET, mucho más ligera | # Usamos la imagen de runtime de ASP.NET 8, mucho más ligera | ||||||
| FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final | FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final | ||||||
| WORKDIR /app | WORKDIR /app | ||||||
| COPY --from=build /app/publish . | COPY --from=build /app/publish . | ||||||
|   | |||||||
| @@ -2,31 +2,29 @@ services: | |||||||
|   # Servicio del Backend |   # Servicio del Backend | ||||||
|   inventario-api: |   inventario-api: | ||||||
|     build: |     build: | ||||||
|       context: . |       context: . # El contexto es la raíz del proyecto | ||||||
|       dockerfile: backend/Dockerfile |       dockerfile: backend/Dockerfile # Docker encontrará este archivo dentro del contexto | ||||||
|     container_name: inventario-api |     container_name: inventario-api | ||||||
|     restart: unless-stopped |     restart: unless-stopped | ||||||
|     # 'expose' hace que el puerto sea accesible para otros contenedores en la misma red, |  | ||||||
|     # pero NO lo publica en la máquina host. Esto es lo correcto. |  | ||||||
|     expose: |     expose: | ||||||
|       - "8080" |       - "8080" | ||||||
|     networks: |     networks: | ||||||
|       - inventario-net |       - inventario-net | ||||||
|       - shared-net # Para conectar con la DB |       - shared-net | ||||||
|  |  | ||||||
|   # Servicio del Frontend |   # Servicio del Frontend | ||||||
|   inventario-frontend: |   inventario-frontend: | ||||||
|     build: |     build: | ||||||
|       context: ./frontend |       context: ./frontend # El contexto es la carpeta 'frontend' | ||||||
|       dockerfile: Dockerfile |       dockerfile: Dockerfile # Docker buscará 'Dockerfile' dentro de la carpeta 'frontend' | ||||||
|     container_name: inventario-frontend |     container_name: inventario-frontend | ||||||
|     restart: unless-stopped |     restart: unless-stopped | ||||||
|     expose: |     expose: | ||||||
|       - "80" # El Nginx del frontend escucha en el puerto 80 interno |       - "80" | ||||||
|     networks: |     networks: | ||||||
|       - inventario-net |       - inventario-net | ||||||
|  |  | ||||||
|   # Proxy Inverso que expone los servicios al exterior |   # Proxy Inverso | ||||||
|   inventario-proxy: |   inventario-proxy: | ||||||
|     image: nginx:1.25-alpine |     image: nginx:1.25-alpine | ||||||
|     container_name: inventario-proxy |     container_name: inventario-proxy | ||||||
| @@ -34,7 +32,6 @@ services: | |||||||
|     volumes: |     volumes: | ||||||
|       - ./proxy/nginx.conf:/etc/nginx/conf.d/default.conf |       - ./proxy/nginx.conf:/etc/nginx/conf.d/default.conf | ||||||
|     ports: |     ports: | ||||||
|       # Este es el ÚNICO punto de entrada a la aplicación desde el exterior. |  | ||||||
|       - "8900:80" |       - "8900:80" | ||||||
|     networks: |     networks: | ||||||
|       - inventario-net |       - inventario-net | ||||||
| @@ -43,10 +40,7 @@ services: | |||||||
|       - inventario-frontend |       - inventario-frontend | ||||||
|  |  | ||||||
| networks: | networks: | ||||||
|   # Red interna para la comunicación entre los servicios de este stack |  | ||||||
|   inventario-net: |   inventario-net: | ||||||
|     driver: bridge |     driver: bridge | ||||||
|  |  | ||||||
|   # Red externa para conectar con servicios compartidos (la base de datos) |  | ||||||
|   shared-net: |   shared-net: | ||||||
|     external: true |     external: true | ||||||
		Reference in New Issue
	
	Block a user