Combine dev and prod dockerfiles

This commit is contained in:
Garen Tyler 2024-11-27 23:39:55 -07:00
parent 641fccfd60
commit a85422d513
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
7 changed files with 39 additions and 28 deletions

View File

@ -2,4 +2,9 @@
Inferno is a decentralized alternative to Discord.
Inferno is licensed under GPLv3.
## Running
- dev: `docker compose up --build`
- prod: `docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build`
Dockerfiles linted using [hadolint](https://github.com/hadolint/hadolint).

View File

@ -1,13 +1,19 @@
FROM node:23.3.0-alpine3.20 AS builder
FROM node:23.3.0-alpine3.20 AS base
WORKDIR /app
COPY package.json .
RUN npm install
ENV PATH=/app/node_modules/.bin:$PATH
COPY . .
FROM base AS dev
EXPOSE 3000
CMD ["npm", "run", "dev", "--", "--host"]
FROM base AS builder
RUN npm run build
FROM nginx:1.27.3-alpine3.20
FROM nginx:1.27.3-alpine3.20 AS prod
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist /var/www/html/
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]

View File

@ -1,8 +0,0 @@
FROM node:23.3.0-alpine3.20
WORKDIR /app
COPY package.json .
ENV PATH=/app/node_modules/.bin:$PATH
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "dev", "--", "--host"]

11
docker-compose.prod.yml Normal file
View File

@ -0,0 +1,11 @@
services:
client-web:
build:
target: prod
volumes: !reset []
server:
build:
context: .
dockerfile: server/Dockerfile
target: prod
volumes: !reset []

View File

@ -3,7 +3,8 @@ services:
restart: unless-stopped
build:
context: ./clients/web/
dockerfile: dev.Dockerfile
dockerfile: Dockerfile
target: dev
ports:
- "3000:3000"
volumes:
@ -13,7 +14,8 @@ services:
restart: unless-stopped
build:
context: ./server/
dockerfile: dev.Dockerfile
dockerfile: Dockerfile
target: dev
ports:
- "3001:3001"
volumes:

View File

@ -1,17 +1,20 @@
# Build from /, not /server.
# Use cargo chef to cache built dependencies.
FROM rust:1.82.0-alpine3.20 AS chef
FROM rust:1.82.0-alpine3.20 AS base
RUN apk add --no-cache musl-dev=1.2.5-r0 git=2.45.2-r0
RUN cargo install cargo-chef --locked --version 0.1.68
RUN cargo install cargo-watch --locked --version 8.5.3
WORKDIR /app
RUN git config --global --add safe.directory /app
FROM chef AS planner
FROM base AS dev
EXPOSE 3001
CMD ["cargo", "watch", "-x", "run"]
FROM base AS planner
COPY server/Cargo.toml .
COPY server/Cargo.lock .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
FROM base AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY server .
@ -19,9 +22,8 @@ COPY .git .git
RUN cargo build --release
RUN strip target/release/inferno
# Multi-stage build to minimize container size
FROM alpine:3.20
FROM alpine:3.20 AS prod
WORKDIR /app
COPY --from=builder /app/target/release/inferno .
EXPOSE 3001
CMD ["/app/inferno"]
CMD ["/app/inferno"]

View File

@ -1,7 +0,0 @@
FROM rust:1.82.0-alpine3.20
RUN apk add --no-cache musl-dev=1.2.5-r0 git=2.45.2-r0
RUN cargo install cargo-watch --locked --version 8.5.3
WORKDIR /app
RUN git config --global --add safe.directory /app
EXPOSE 3001
CMD ["cargo", "watch", "-x", "run"]