From 1370bc8a43c86bd63ac938e0d5e136c9c68b4d98 Mon Sep 17 00:00:00 2001 From: Book-reader Date: Thu, 4 Sep 2025 15:53:53 +1200 Subject: [PATCH] Docker compose setup --- .gitignore | 6 +- Dockerfile.auth-frontend | 16 ++++ Dockerfile.authservice | 16 ++++ Dockerfile.bingservice | 14 ++++ Dockerfile.frontend | 17 +++++ Dockerfile.googleservice | 14 ++++ Dockerfile.vorebot | 14 ++++ asklyphe-auth-frontend/src/main.rs | 4 +- asklyphe-frontend/src/main.rs | 4 +- docker-compose.yml | 113 +++++++++++++++++++++++++++++ nginx/default.conf | 27 +++++++ 11 files changed, 240 insertions(+), 5 deletions(-) create mode 100644 Dockerfile.auth-frontend create mode 100644 Dockerfile.authservice create mode 100644 Dockerfile.bingservice create mode 100644 Dockerfile.frontend create mode 100644 Dockerfile.googleservice create mode 100644 Dockerfile.vorebot create mode 100644 docker-compose.yml create mode 100644 nginx/default.conf diff --git a/.gitignore b/.gitignore index 4d2be69..344be0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ .idea -/target \ No newline at end of file +/target +# /nginx +database +database.bak +.env diff --git a/Dockerfile.auth-frontend b/Dockerfile.auth-frontend new file mode 100644 index 0000000..5247ad5 --- /dev/null +++ b/Dockerfile.auth-frontend @@ -0,0 +1,16 @@ +FROM rust:1.89.0 AS builder + +WORKDIR /usr/src/asklyphe/ +COPY asklyphe-auth-frontend asklyphe-auth-frontend +COPY asklyphe-common asklyphe-common +COPY lyphedb lyphedb + +RUN cargo install --debug --path asklyphe-auth-frontend/ + +FROM debian:trixie-slim +RUN apt-get update && apt-get upgrade -y && apt-get install -y libssl3 && rm -rf /var/lib/apt-get/lists/* +COPY --from=builder /usr/local/cargo/bin/asklyphe-auth-frontend /usr/local/bin/ +COPY --from=builder /usr/src/asklyphe/asklyphe-auth-frontend/static /data/static +VOLUME /data + +CMD ["asklyphe-auth-frontend"] diff --git a/Dockerfile.authservice b/Dockerfile.authservice new file mode 100644 index 0000000..80f8a7a --- /dev/null +++ b/Dockerfile.authservice @@ -0,0 +1,16 @@ +FROM rust:1.89.0 AS builder + +WORKDIR /usr/src/asklyphe/ +COPY authservice authservice +COPY asklyphe-common asklyphe-common +COPY lyphedb lyphedb + +RUN cargo install --debug --path authservice/ +RUN cargo install --debug --path authservice/migration/ + +FROM debian:trixie-slim +RUN apt-get update && apt-get upgrade -y && apt-get install -y libssl3 && rm -rf /var/lib/apt-get/lists/* +COPY --from=builder /usr/local/cargo/bin/authservice /usr/local/bin/ +COPY --from=builder /usr/local/cargo/bin/migration /usr/local/bin/ + +CMD ["authservice"] diff --git a/Dockerfile.bingservice b/Dockerfile.bingservice new file mode 100644 index 0000000..81e0118 --- /dev/null +++ b/Dockerfile.bingservice @@ -0,0 +1,14 @@ +FROM rust:1.89.0 AS builder + +WORKDIR /usr/src/asklyphe/ +COPY bingservice bingservice +COPY asklyphe-common asklyphe-common +COPY lyphedb lyphedb + +RUN cargo install --debug --path bingservice/ + +FROM debian:trixie-slim +RUN apt-get update && apt-get upgrade -y && apt-get install -y libssl3 && rm -rf /var/lib/apt-get/lists/* +COPY --from=builder /usr/local/cargo/bin/bingservice /usr/local/bin/ + +CMD ["bingservice"] diff --git a/Dockerfile.frontend b/Dockerfile.frontend new file mode 100644 index 0000000..61503a7 --- /dev/null +++ b/Dockerfile.frontend @@ -0,0 +1,17 @@ +FROM rust:1.89.0 AS builder + +WORKDIR /usr/src/asklyphe/ +COPY asklyphe-frontend asklyphe-frontend +COPY asklyphe-common asklyphe-common +COPY lyphedb lyphedb +COPY unit_converter unit_converter + +RUN cargo install --debug --path asklyphe-frontend/ + +FROM debian:trixie-slim +RUN apt-get update && apt-get upgrade -y && apt-get install -y libssl3 && rm -rf /var/lib/apt-get/lists/* +COPY --from=builder /usr/local/cargo/bin/asklyphe-frontend /usr/local/bin/ +COPY --from=builder /usr/src/asklyphe/asklyphe-frontend/static /data/static +VOLUME /data + +CMD ["asklyphe-frontend"] diff --git a/Dockerfile.googleservice b/Dockerfile.googleservice new file mode 100644 index 0000000..ed1ed1d --- /dev/null +++ b/Dockerfile.googleservice @@ -0,0 +1,14 @@ +FROM rust:1.89.0 AS builder + +WORKDIR /usr/src/asklyphe/ +COPY googleservice googleservice +COPY asklyphe-common asklyphe-common +COPY lyphedb lyphedb + +RUN cargo install --debug --path googleservice/ + +FROM debian:trixie-slim +RUN apt-get update && apt-get upgrade -y && apt-get install -y libssl3 && rm -rf /var/lib/apt-get/lists/* +COPY --from=builder /usr/local/cargo/bin/googleservice /usr/local/bin/ + +CMD ["googleservice"] diff --git a/Dockerfile.vorebot b/Dockerfile.vorebot new file mode 100644 index 0000000..c9490c3 --- /dev/null +++ b/Dockerfile.vorebot @@ -0,0 +1,14 @@ +FROM rust:1.89.0 AS builder + +WORKDIR /usr/src/asklyphe/ +COPY vorebot vorebot +COPY asklyphe-common asklyphe-common +COPY lyphedb lyphedb + +RUN cargo install --debug --path vorebot/ + +FROM debian:trixie-slim +RUN apt-get update && apt-get upgrade -y && apt-get install -y libssl3 && rm -rf /var/lib/apt-get/lists/* +COPY --from=builder /usr/local/cargo/bin/vorebot /usr/local/bin/ + +CMD ["vorebot"] diff --git a/asklyphe-auth-frontend/src/main.rs b/asklyphe-auth-frontend/src/main.rs index cd16d94..d8324f0 100644 --- a/asklyphe-auth-frontend/src/main.rs +++ b/asklyphe-auth-frontend/src/main.rs @@ -17,7 +17,7 @@ mod login; use std::{env, process}; use std::collections::HashMap; -use std::net::SocketAddr; +use std::net::{SocketAddr, ToSocketAddrs}; use std::ops::Deref; use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; @@ -66,7 +66,7 @@ async fn main() { env_logger::init(); let opts = Opts { bind_addr: env::var("BIND_ADDR").unwrap_or("0.0.0.0:5843".to_string()).parse().expect("Badly formed BIND_ADDR (Needs to be SocketAddr)"), - nats_addr: env::var("NATS_ADDR").unwrap_or("127.0.0.1:4222".to_string()).parse().expect("Badly formed NATS_ADDR (Needs to be SocketAddr)"), + nats_addr: env::var("NATS_ADDR").unwrap_or("127.0.0.1:4222".to_string()).to_socket_addrs().expect("Badly formed NATS_ADDR (Needs to be SocketAddr)").nth(0).unwrap(), nats_cert: env::var("NATS_CERT").expect("NATS_CERT needs to be set"), nats_key: env::var("NATS_KEY").expect("NATS_KEY needs to be set"), asklyphe_url: env::var("ASKLYPHE_URL").unwrap_or("https://asklyphe.com".to_string()), diff --git a/asklyphe-frontend/src/main.rs b/asklyphe-frontend/src/main.rs index e99fe51..1dc7fd0 100644 --- a/asklyphe-frontend/src/main.rs +++ b/asklyphe-frontend/src/main.rs @@ -19,7 +19,7 @@ pub mod routes; use std::{env, process}; use std::collections::HashMap; -use std::net::SocketAddr; +use std::net::{SocketAddr, ToSocketAddrs}; use std::ops::Deref; use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; @@ -85,7 +85,7 @@ async fn main() { env_logger::init(); let opts = Opts { bind_addr: env::var("BIND_ADDR").unwrap_or("0.0.0.0:5842".to_string()).parse().expect("Badly formed BIND_ADDR (Needs to be SocketAddr)"), - nats_addr: env::var("NATS_ADDR").unwrap_or("127.0.0.1:4222".to_string()).parse().expect("Badly formed NATS_ADDR (Needs to be SocketAddr)"), + nats_addr: env::var("NATS_ADDR").unwrap_or("127.0.0.1:4222".to_string()).to_socket_addrs().expect("Badly formed NATS_ADDR (Needs to be SocketAddr)").nth(0).unwrap(), nats_cert: env::var("NATS_CERT").expect("NATS_CERT needs to be set"), nats_key: env::var("NATS_KEY").expect("NATS_KEY needs to be set"), auth_url: env::var("AUTH_URL").unwrap_or("https://auth.asklyphe.com".to_string()), diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7d8bca1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,113 @@ +services: + auth-frontend: + restart: unless-stopped + networks: + - lyphenet + env_file: ".env" + depends_on: + - nats + - authservice + build: + dockerfile: Dockerfile.auth-frontend + volumes: + - auth_frontend_data:/data + image: asklyphe/auth-frontend + authservice: + restart: unless-stopped + networks: + - lyphenet + env_file: ".env" + depends_on: + - nats + build: + dockerfile: Dockerfile.authservice + image: asklyphe/authservice + frontend: + restart: unless-stopped + networks: + - lyphenet + env_file: ".env" + depends_on: + - nats + build: + dockerfile: Dockerfile.frontend + volumes: + - frontend_data:/data + image: asklyphe/frontend +# vorebot: +# restart: unless-stopped +# networks: +# - lyphenet +# - outer +# env_file: ".env" +# depends_on: +# - nats +# build: +# dockerfile: Dockerfile.vorebot +# image: asklyphe/vorebot + +# bingservice: +# restart: unless-stopped +# networks: +# - lyphenet +# - outer +# env_file: ".env" +# depends_on: +# - nats +# build: +# dockerfile: Dockerfile.bingservice +# image: asklyphe/bingservice +# googleservice: +# restart: unless-stopped +# networks: +# - lyphenet +# env_file: ".env" +# depends_on: +# - nats +# - bingservice +# build: +# dockerfile: Dockerfile.googleservice +# image: asklyphe/googleservice + + nats: + restart: unless-stopped + networks: + - lyphenet + depends_on: + - db + env_file: ".env" + image: nats:2.11.8 + cmd: "nats-server -js" + db: + image: postgres:17 + networks: + - lyphenet + env_file: ".env" + healthcheck: + test: ['CMD', 'pg_isready', '-U', 'postgres'] + volumes: + - ./database:/var/lib/postgresql/data + proxy: + image: nginx:latest + networks: + - lyphenet + - outer + depends_on: + - frontend + - auth-frontend + volumes: + - ./nginx:/etc/nginx/conf.d + - frontend_data:/data/frontend + - auth_frontend_data:/data/auth-frontend + ports: + - "1234:80" + - "1235:81" + +networks: + lyphenet: + internal: true + outer: + +volumes: + frontend_data: + auth_frontend_data: diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..aea95c8 --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,27 @@ +server { + listen 81; + server_name 0.0.0.0; + access_log off; + + location /static/ { + root /data/auth-frontend; + } + + location / { + proxy_pass http://auth-frontend:5843; + } +} + +server { + listen 80; + server_name 0.0.0.0; + access_log off; + + location /static/ { + root /data/frontend; + } + + location / { + proxy_pass http://frontend:5842; + } +}