Add server dockerfiles

This commit is contained in:
Garen Tyler 2024-11-27 21:41:21 -07:00
parent 37bf75649d
commit 31ed9a08a9
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
6 changed files with 53 additions and 12 deletions

7
.dockerignore Normal file
View File

@ -0,0 +1,7 @@
.DS_Store
._*
target
*.log
logs
inferno.toml
node_modules

View File

@ -1,12 +0,0 @@
on: [push]
name: Clippy
# Fail on all warnings, including clippy lints.
env:
RUSTFLAGS: "-Dwarnings"
jobs:
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Clippy
run: cargo clippy --all-targets --all-features

View File

@ -2,3 +2,4 @@
Inferno is a decentralized alternative to Discord.
Inferno is licensed under GPLv3.
Dockerfiles linted using [hadolint](https://github.com/hadolint/hadolint).

11
docker-compose.yml Normal file
View File

@ -0,0 +1,11 @@
services:
server:
restart: unless-stopped
build:
context: ./server/
dockerfile: dev.Dockerfile
ports:
- "3001:3001"
volumes:
- ./server:/app
- .git:/app/.git

7
server/dev.Dockerfile Normal file
View File

@ -0,0 +1,7 @@
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"]

27
server/prod.Dockerfile Normal file
View File

@ -0,0 +1,27 @@
# Build from /, not /server.
# Use cargo chef to cache built dependencies.
FROM rust:1.82.0-alpine3.20 AS chef
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
WORKDIR /app
RUN git config --global --add safe.directory /app
FROM chef AS planner
COPY server/Cargo.toml .
COPY server/Cargo.lock .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY server .
COPY .git .git
RUN cargo build --release
RUN strip target/release/inferno
# Multi-stage build to minimize container size
FROM alpine:3.20
WORKDIR /app
COPY --from=builder /app/target/release/inferno .
EXPOSE 3001
CMD ["/app/inferno"]