From 9861629cc8f7355d5acd8661e8854d8954632d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20St=C4=99pie=C5=84?= Date: Fri, 4 Aug 2023 18:09:17 +0200 Subject: [PATCH] Layered docker images and improved docker-compose deployment (#282) * update docker compose and add layered docker images for kitsune and kitsune-search-server * consistent Dockerfiles * use stable in the Dockerfiles --- .dockerignore | 1 - config.docker.toml | 42 +++++++++++++++++++++++++++ docker-compose.yml | 9 ++++++ kitsune-search-server/Dockerfile.dev | 26 +++++++++++------ kitsune-search-server/Dockerfile.prod | 26 +++++++++++------ kitsune/Dockerfile.dev | 33 +++++++++++++++------ kitsune/Dockerfile.prod | 33 +++++++++++++++------ 7 files changed, 133 insertions(+), 37 deletions(-) create mode 100644 config.docker.toml diff --git a/.dockerignore b/.dockerignore index 59b3396b..cda47b7b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,4 @@ **/node_modules target/ -kitsune-fe/ Dockerfile.dev Dockerfile.prod diff --git a/config.docker.toml b/config.docker.toml new file mode 100644 index 00000000..11e4d51b --- /dev/null +++ b/config.docker.toml @@ -0,0 +1,42 @@ +[cache] +type = "in-memory" + +[database] +url = "postgres://kitsune:password@db/kitsune" +max-connections = 20 + +[instance] +name = "Kitsune" +description = "https://www.youtube.com/watch?v=6lnnPnr_0SU" +character-limit = 5000 +registrations-open = true + +[instance.federation-filter] +type = "deny" +domains = [] + +[job-queue] +redis-url = "redis://redis" +num-workers = 20 + +[messaging] +type = "in-process" + +[server] +frontend-dir = "./kitsune-fe/dist" +max-upload-size = 5242880 # 5MB +media-proxy-enabled = false +port = 5000 +prometheus-port = 9000 +request-timeout-secs = 60 + +[search] +type = "sql" + +[storage] +type = "fs" +upload-dir = "./uploads" + +[url] +scheme = "http" +domain = "localhost:5000" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ad6332b7..e23ef6b8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,8 @@ version: '3.1' services: backend: image: kitsune + command: + - config.toml ports: - "5000:5000" networks: @@ -18,6 +20,13 @@ services: SEARCH_SERVERS: http://backend-search:8080 volumes: - upload-data:/app/uploads + - type: bind + source: ${KITSUNE_CONFIG} + target: /app/config.toml + read_only: true + depends_on: + - db + - redis backend-search: image: kitsune-search diff --git a/kitsune-search-server/Dockerfile.dev b/kitsune-search-server/Dockerfile.dev index c89332e8..4ae8123a 100644 --- a/kitsune-search-server/Dockerfile.dev +++ b/kitsune-search-server/Dockerfile.dev @@ -1,11 +1,19 @@ -FROM rust:1-alpine AS build -RUN rustup default nightly -RUN apk add --no-cache musl-dev -COPY . /build -WORKDIR /build -RUN cargo -Z sparse-registry build +FROM rust:1-alpine AS base +RUN apk add --no-cache musl-dev make protobuf-dev +RUN cargo install cargo-chef +WORKDIR app + +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM base AS build +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --recipe-path recipe.json +COPY . . +RUN cargo build --bin kitsune-search-server FROM alpine:latest -WORKDIR /app -COPY --from=build /build/target/debug/kitsune-search . -CMD ["/app/kitsune-search"] +WORKDIR app +COPY --from=build /app/target/debug/kitsune-search-server . +ENTRYPOINT ["./kitsune-search-server"] diff --git a/kitsune-search-server/Dockerfile.prod b/kitsune-search-server/Dockerfile.prod index 81da7cdf..53214b53 100644 --- a/kitsune-search-server/Dockerfile.prod +++ b/kitsune-search-server/Dockerfile.prod @@ -1,11 +1,19 @@ -FROM rust:1-alpine AS build -RUN rustup default nightly -RUN apk add --no-cache musl-dev -COPY . /build -WORKDIR /build -RUN cargo -Z sparse-registry build --release +FROM rust:1-alpine AS base +RUN apk add --no-cache musl-dev make protobuf-dev +RUN cargo install cargo-chef +WORKDIR app + +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM base AS build +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . . +RUN cargo build --release --bin kitsune-search-server FROM alpine:latest -WORKDIR /app -COPY --from=build /build/target/release/kitsune-search . -CMD ["/app/kitsune-search"] +WORKDIR app +COPY --from=build /app/target/release/kitsune-search-server . +ENTRYPOINT ["./kitsune-search-server"] \ No newline at end of file diff --git a/kitsune/Dockerfile.dev b/kitsune/Dockerfile.dev index 9c3767a9..76dad00e 100644 --- a/kitsune/Dockerfile.dev +++ b/kitsune/Dockerfile.dev @@ -1,11 +1,26 @@ -FROM rust:1-alpine AS build -RUN rustup default nightly -RUN apk add --no-cache musl-dev -COPY . /build -WORKDIR /build -RUN cargo -Z sparse-registry build +FROM rust:1-alpine AS base +RUN apk add --no-cache musl-dev make protobuf-dev +RUN cargo install cargo-chef +WORKDIR app + +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM base AS build +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --recipe-path recipe.json +COPY . . +RUN cargo build --bin kitsune + +FROM base AS frontend +RUN apk add --no-cache yarn +COPY kitsune-fe . +WORKDIR kitsune-fe +RUN yarn install && yarn build FROM alpine:latest -WORKDIR /app -COPY --from=build /build/target/debug/kitsune . -CMD ["/app/kitsune"] +WORKDIR app +COPY --from=build /app/target/debug/kitsune . +COPY --from=frontend /app kitsune-fe +ENTRYPOINT ["./kitsune"] diff --git a/kitsune/Dockerfile.prod b/kitsune/Dockerfile.prod index 931a47f6..e3cd5697 100644 --- a/kitsune/Dockerfile.prod +++ b/kitsune/Dockerfile.prod @@ -1,11 +1,26 @@ -FROM rust:1-alpine AS build -RUN rustup default nightly -RUN apk add --no-cache musl-dev -COPY . /build -WORKDIR /build -RUN cargo -Z sparse-registry build --release +FROM rust:1-alpine AS base +RUN apk add --no-cache musl-dev make protobuf-dev +RUN cargo install cargo-chef +WORKDIR app + +FROM base AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM base AS build +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . . +RUN cargo build --release --bin kitsune + +FROM base AS frontend +RUN apk add --no-cache yarn +COPY kitsune-fe . +WORKDIR kitsune-fe +RUN yarn install && yarn build FROM alpine:latest -WORKDIR /app -COPY --from=build /build/target/release/kitsune . -CMD ["/app/kitsune"] +WORKDIR app +COPY --from=build /app/target/release/kitsune . +COPY --from=frontend /app kitsune-fe +ENTRYPOINT ["./kitsune"]