From 6e65e9a9122e8d7259ac0c58778da77c72c4a38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BENEDEK=20L=C3=A1szl=C3=B3?= Date: Tue, 10 Jun 2025 13:17:20 +0200 Subject: [PATCH] docker integration --- .env.api | 14 ++++++++++++++ database.docker-compose.yml | 23 +++++++++++++++++++++++ docker-compose.yml | 28 ++++++++++++++++++++++++---- nginx/default.conf | 26 ++++++++++++++++++++++++++ postgres/99-sample.sql | 8 ++++---- 5 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 .env.api create mode 100644 database.docker-compose.yml create mode 100644 nginx/default.conf diff --git a/.env.api b/.env.api new file mode 100644 index 0000000..f094bc6 --- /dev/null +++ b/.env.api @@ -0,0 +1,14 @@ +API_ADDRESS=:5000 +API_BASE=api +API_TOKEN_LIFE=600 + +DB_HOST=database +DB_PORT=5432 +DB_USER=admin +DB_PASSWORD=admin +DB_NAME=chat + +VALKEY_ADDRESS=keystore:6379 +VALKEY_USERNAME=admin +VALKEY_PASSWORD=admin +VALKEY_DB=0 diff --git a/database.docker-compose.yml b/database.docker-compose.yml new file mode 100644 index 0000000..c70987a --- /dev/null +++ b/database.docker-compose.yml @@ -0,0 +1,23 @@ +services: + database: + image: postgres:17-alpine + restart: unless-stopped + ports: + - 5432:5432 + env_file: .env.postgres + volumes: + - pgdata:/var/lib/postgresql/data + - ./postgres:/docker-entrypoint-initdb.d:ro + + keystore: + image: valkey/valkey:8-alpine + restart: unless-stopped + ports: + - 6379:6379 + command: valkey-server /usr/local/etc/valkey/valkey.conf + volumes: + - ./valkey/valkey.conf:/usr/local/etc/valkey/valkey.conf:ro + - ./valkey/users.acl:/usr/local/etc/valkey/users.acl:ro + +volumes: + pgdata: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c70987a..e780237 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,6 @@ services: database: image: postgres:17-alpine restart: unless-stopped - ports: - - 5432:5432 env_file: .env.postgres volumes: - pgdata:/var/lib/postgresql/data @@ -12,12 +10,34 @@ services: keystore: image: valkey/valkey:8-alpine restart: unless-stopped - ports: - - 6379:6379 command: valkey-server /usr/local/etc/valkey/valkey.conf volumes: - ./valkey/valkey.conf:/usr/local/etc/valkey/valkey.conf:ro - ./valkey/users.acl:/usr/local/etc/valkey/users.acl:ro + api: + scale: 1 + image: registry.tek.govt.hu/chat/api:latest + restart: unless-stopped + env_file: .env.api + depends_on: + - database + - keystore + + ui: + scale: 1 + image: registry.tek.govt.hu/chat/ui:debug + restart: unless-stopped + depends_on: + - api + + proxy: + image: nginx:alpine-slim + restart: unless-stopped + ports: + - 80:80 + volumes: + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro + volumes: pgdata: \ No newline at end of file diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..79aa9df --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,26 @@ +server { + listen 80; + + # backend api + location /api/ { + proxy_pass http://api:5000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_read_timeout 86400; + } + + # frontend & static + location / { + proxy_pass http://ui:80; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/postgres/99-sample.sql b/postgres/99-sample.sql index a2cd6f5..e93f95e 100644 --- a/postgres/99-sample.sql +++ b/postgres/99-sample.sql @@ -1,10 +1,10 @@ -- More users insert into "user" ("username", "password_hash", "status", "picture", "bio") values - ('alice', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Online', 'https://example.com/alice.jpg', 'Loves coding and coffee.'), - ('bob', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Away', 'https://example.com/bob.jpg', 'Gamer and tech enthusiast.'), - ('charlie', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Busy', 'https://example.com/charlie.jpg', 'Database aficionado.'), - ('diana', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Online', 'https://example.com/diana.jpg', 'Enjoys reading and hiking.'); + ('alice', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Online', '', 'Loves coding and coffee.'), + ('bob', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Away', '', 'Gamer and tech enthusiast.'), + ('charlie', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Busy', '', 'Database aficionado.'), + ('diana', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Online', '', 'Enjoys reading and hiking.'); -- More roles insert into "role" ("name")