diff --git a/README.md b/README.md index dbf54e0..54e63c4 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/clients/web/prod.Dockerfile b/clients/web/Dockerfile similarity index 52% rename from clients/web/prod.Dockerfile rename to clients/web/Dockerfile index d505931..df6ba03 100644 --- a/clients/web/prod.Dockerfile +++ b/clients/web/Dockerfile @@ -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;"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] diff --git a/clients/web/dev.Dockerfile b/clients/web/dev.Dockerfile deleted file mode 100644 index 77f8c71..0000000 --- a/clients/web/dev.Dockerfile +++ /dev/null @@ -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"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..7a2008c --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,11 @@ +services: + client-web: + build: + target: prod + volumes: !reset [] + server: + build: + context: . + dockerfile: server/Dockerfile + target: prod + volumes: !reset [] diff --git a/docker-compose.yml b/docker-compose.yml index cd2cd00..2fc356f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/server/prod.Dockerfile b/server/Dockerfile similarity index 68% rename from server/prod.Dockerfile rename to server/Dockerfile index c55ac8b..083f8be 100644 --- a/server/prod.Dockerfile +++ b/server/Dockerfile @@ -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"] \ No newline at end of file +CMD ["/app/inferno"] diff --git a/server/dev.Dockerfile b/server/dev.Dockerfile deleted file mode 100644 index ee2c025..0000000 --- a/server/dev.Dockerfile +++ /dev/null @@ -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"] \ No newline at end of file