From 1bc33ab912663aa5cfdb4d2ed132bfa91f1b51e5 Mon Sep 17 00:00:00 2001 From: maix0 Date: Mon, 16 Jun 2025 16:37:20 +0200 Subject: [PATCH] wip --- Docker.mk | 7 +++-- Makefile | 10 +----- docker-compose.yml | 15 +++++++-- nginx/15-local-resolvers.envsh | 15 +++++++++ nginx/17-add-template-prefix.sh | 3 +- nginx/Dockerfile | 4 +-- nginx/conf/default.conf | 3 +- nginx/conf/locations/icons.conf | 4 +++ src/icons-service/.dockerignore | 2 ++ src/{user-icons => icons-service}/.gitignore | 0 src/icons-service/Dockerfile | 31 +++++++++++++++++++ src/{user-icons => icons-service}/README.md | 0 .../package-lock.json | 0 .../package.json | 2 +- src/{user-icons => icons-service}/src/app.ts | 0 .../src/plugins/README.md | 0 .../src/plugins/sensible.ts | 0 .../src/routes/README.md | 0 .../src/routes/get/index.ts | 0 .../src/routes/root.ts | 0 .../src/routes/set/index.ts | 0 src/icons-service/src/run.ts | 16 ++++++++++ .../test/helper.ts | 0 .../test/plugins/support.test.ts | 0 .../test/routes/example.test.ts | 0 .../test/routes/root.test.ts | 0 .../test/tsconfig.json | 0 .../tsconfig.json | 0 28 files changed, 94 insertions(+), 18 deletions(-) create mode 100755 nginx/15-local-resolvers.envsh create mode 100644 nginx/conf/locations/icons.conf create mode 100644 src/icons-service/.dockerignore rename src/{user-icons => icons-service}/.gitignore (100%) create mode 100644 src/icons-service/Dockerfile rename src/{user-icons => icons-service}/README.md (100%) rename src/{user-icons => icons-service}/package-lock.json (100%) rename src/{user-icons => icons-service}/package.json (97%) rename src/{user-icons => icons-service}/src/app.ts (100%) rename src/{user-icons => icons-service}/src/plugins/README.md (100%) rename src/{user-icons => icons-service}/src/plugins/sensible.ts (100%) rename src/{user-icons => icons-service}/src/routes/README.md (100%) rename src/{user-icons => icons-service}/src/routes/get/index.ts (100%) rename src/{user-icons => icons-service}/src/routes/root.ts (100%) rename src/{user-icons => icons-service}/src/routes/set/index.ts (100%) create mode 100644 src/icons-service/src/run.ts rename src/{user-icons => icons-service}/test/helper.ts (100%) rename src/{user-icons => icons-service}/test/plugins/support.test.ts (100%) rename src/{user-icons => icons-service}/test/routes/example.test.ts (100%) rename src/{user-icons => icons-service}/test/routes/root.test.ts (100%) rename src/{user-icons => icons-service}/test/tsconfig.json (100%) rename src/{user-icons => icons-service}/tsconfig.json (100%) diff --git a/Docker.mk b/Docker.mk index 01895ff..bee8255 100644 --- a/Docker.mk +++ b/Docker.mk @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/06/11 18:10:26 by maiboyer #+# #+# # -# Updated: 2025/06/12 22:06:41 by maiboyer ### ########.fr # +# Updated: 2025/06/16 15:37:20 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -15,7 +15,10 @@ all: docker compose up -d logs: - docker compose logs -f --colors + docker compose logs -f + +down: + docker compose down re: $(MAKE) -f ./Docker.mk clean diff --git a/Makefile b/Makefile index eef15fe..3c42ea7 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,10 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2025/06/12 22:06:29 by maiboyer ### ########.fr # +# Updated: 2025/06/16 15:36:58 by maiboyer ### ########.fr # # # # **************************************************************************** # -# Objdir -SRC_DIR = . - -MSG= -NAME=webserv - # Colors GREEN = \033[32m BLACK = \033[30m @@ -56,8 +50,6 @@ prune: logs: @$(MAKE) --no-print-directory -f ./Docker.mk logs -$(NAME): all - # Header header: @$(ECHO) -e '' diff --git a/docker-compose.yml b/docker-compose.yml index f86a02c..c335b64 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,6 @@ services: # service_name: # build: ./service_name # container_name: service_name -# image: service_name # restart: always # env_file: # - ${SECRET_DIR}/service_name.env @@ -24,8 +23,20 @@ services: - transcendance-network ports: - '8888:443' - enviroment: + environment: - NGINX_DOMAIN=local.maix.me + - NGINX_USE_LOCAL_RESOLVER=yes + + icons-service: + build: ./src/icons-service/ + container_name: icons-service + restart: always + networks: + - transcendance-network + volumes: + - /store + environment: + - USER_ICONS_STORE=/store volumes: # service_name-vol: # driver: local diff --git a/nginx/15-local-resolvers.envsh b/nginx/15-local-resolvers.envsh new file mode 100755 index 0000000..6c76285 --- /dev/null +++ b/nginx/15-local-resolvers.envsh @@ -0,0 +1,15 @@ +#!/bin/sh + +# if $NGINX_RESOLVERS set to local, set it to the local resolvers from /etc/resolv.conf and export it + +set -eu + +LC_ALL=C +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +NGINX_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf) +# remove trailing space +NGINX_RESOLVERS="${NGINX_RESOLVERS% }" +echo "_${NGINX_RESOLVERS}_" + +export NGINX_RESOLVERS diff --git a/nginx/17-add-template-prefix.sh b/nginx/17-add-template-prefix.sh index 168d0fe..b26feaf 100755 --- a/nginx/17-add-template-prefix.sh +++ b/nginx/17-add-template-prefix.sh @@ -4,6 +4,7 @@ set -e ME=$(basename "$0") +echo "_{$NGINX_LOCAL_RESOLVERS}_" entrypoint_log() { if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then echo "$@" @@ -19,7 +20,7 @@ auto_template() { entrypoint_log "$ME: ERROR: $template_dir exists, but is not writable" return 0 fi - find "$template_dir" -follow -type f -print | while read -r template; do + find "$template_dir" -follow -type f -name '*.conf' -print | while read -r template; do entrypoint_log "$ME: adding $suffix to $template" mv "$template" "$template$suffix" done diff --git a/nginx/Dockerfile b/nginx/Dockerfile index a0a0105..586c438 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/06/12 16:42:38 by maiboyer #+# #+# # -# Updated: 2025/06/12 18:15:38 by maiboyer ### ########.fr # +# Updated: 2025/06/16 16:26:48 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -20,6 +20,6 @@ RUN mkdir -p /etc/nginx/ && \ -keyout /etc/ssl/private/nginx-selfsigned.key \ -out /etc/ssl/certs/nginx-selfsigned.crt \ -subj "/C=FR/OU=student/CN=${NGINX_DOMAIN}" - +COPY ./15-local-resolvers.envsh /docker-entrypoint.d/ COPY ./17-add-template-prefix.sh /docker-entrypoint.d/ COPY ./conf /etc/nginx/templates diff --git a/nginx/conf/default.conf b/nginx/conf/default.conf index 3b417a6..d2ffbb0 100644 --- a/nginx/conf/default.conf +++ b/nginx/conf/default.conf @@ -3,7 +3,7 @@ server { charset UTF-8; listen 80; listen [::]:80; - + resolver $NGINX_RESOLVERS; server_name $NGINX_DOMAIN; if ($host = $NGINX_DOMAIN) { @@ -17,6 +17,7 @@ server { listen [::]:443 ssl; listen 443 ssl; server_name $NGINX_DOMAIN; + resolver $NGINX_RESOLVERS; ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key; diff --git a/nginx/conf/locations/icons.conf b/nginx/conf/locations/icons.conf new file mode 100644 index 0000000..19dca17 --- /dev/null +++ b/nginx/conf/locations/icons.conf @@ -0,0 +1,4 @@ +location /api/icons { + rewrite ^/api/icons/(.*) /$1 break; + proxy_pass http://icons-service/$uri$is_args$args; +} diff --git a/src/icons-service/.dockerignore b/src/icons-service/.dockerignore new file mode 100644 index 0000000..c925c21 --- /dev/null +++ b/src/icons-service/.dockerignore @@ -0,0 +1,2 @@ +/dist +/node_modules diff --git a/src/user-icons/.gitignore b/src/icons-service/.gitignore similarity index 100% rename from src/user-icons/.gitignore rename to src/icons-service/.gitignore diff --git a/src/icons-service/Dockerfile b/src/icons-service/Dockerfile new file mode 100644 index 0000000..cae216d --- /dev/null +++ b/src/icons-service/Dockerfile @@ -0,0 +1,31 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Dockerfile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: maiboyer +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2025/06/16 14:57:11 by maiboyer #+# #+# # +# Updated: 2025/06/16 15:28:33 by maiboyer ### ########.fr # +# # +# **************************************************************************** # + +FROM node:24-alpine AS builder + +# Don't forget to edit the .dockerignore if needed +COPY . /app + +WORKDIR /app +RUN npm install && npm run build:ts; + +FROM node:24-alpine + +WORKDIR /app + +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/package*.json . + +RUN npm ci --omit=dev; +# Start the app +CMD ["node", "dist/run.js"] + diff --git a/src/user-icons/README.md b/src/icons-service/README.md similarity index 100% rename from src/user-icons/README.md rename to src/icons-service/README.md diff --git a/src/user-icons/package-lock.json b/src/icons-service/package-lock.json similarity index 100% rename from src/user-icons/package-lock.json rename to src/icons-service/package-lock.json diff --git a/src/user-icons/package.json b/src/icons-service/package.json similarity index 97% rename from src/user-icons/package.json rename to src/icons-service/package.json index c422004..d16c574 100644 --- a/src/user-icons/package.json +++ b/src/icons-service/package.json @@ -1,6 +1,6 @@ { "type": "module", - "name": "user-icons", + "name": "icons-service", "version": "1.0.0", "description": "This project was bootstrapped with Fastify-CLI.", "main": "app.ts", diff --git a/src/user-icons/src/app.ts b/src/icons-service/src/app.ts similarity index 100% rename from src/user-icons/src/app.ts rename to src/icons-service/src/app.ts diff --git a/src/user-icons/src/plugins/README.md b/src/icons-service/src/plugins/README.md similarity index 100% rename from src/user-icons/src/plugins/README.md rename to src/icons-service/src/plugins/README.md diff --git a/src/user-icons/src/plugins/sensible.ts b/src/icons-service/src/plugins/sensible.ts similarity index 100% rename from src/user-icons/src/plugins/sensible.ts rename to src/icons-service/src/plugins/sensible.ts diff --git a/src/user-icons/src/routes/README.md b/src/icons-service/src/routes/README.md similarity index 100% rename from src/user-icons/src/routes/README.md rename to src/icons-service/src/routes/README.md diff --git a/src/user-icons/src/routes/get/index.ts b/src/icons-service/src/routes/get/index.ts similarity index 100% rename from src/user-icons/src/routes/get/index.ts rename to src/icons-service/src/routes/get/index.ts diff --git a/src/user-icons/src/routes/root.ts b/src/icons-service/src/routes/root.ts similarity index 100% rename from src/user-icons/src/routes/root.ts rename to src/icons-service/src/routes/root.ts diff --git a/src/user-icons/src/routes/set/index.ts b/src/icons-service/src/routes/set/index.ts similarity index 100% rename from src/user-icons/src/routes/set/index.ts rename to src/icons-service/src/routes/set/index.ts diff --git a/src/icons-service/src/run.ts b/src/icons-service/src/run.ts new file mode 100644 index 0000000..4ee0b64 --- /dev/null +++ b/src/icons-service/src/run.ts @@ -0,0 +1,16 @@ +// this sould only be used by the docker file ! + +import fastify, { FastifyInstance } from "fastify"; +import app from './app.js' + +const start = async () => { + const f: FastifyInstance = fastify({logger: true}); + try { + await f.register(app, {}); + await f.listen({ port: 80, host: '0.0.0.0' }) + } catch (err) { + f.log.error(err) + process.exit(1) + } +} +start() diff --git a/src/user-icons/test/helper.ts b/src/icons-service/test/helper.ts similarity index 100% rename from src/user-icons/test/helper.ts rename to src/icons-service/test/helper.ts diff --git a/src/user-icons/test/plugins/support.test.ts b/src/icons-service/test/plugins/support.test.ts similarity index 100% rename from src/user-icons/test/plugins/support.test.ts rename to src/icons-service/test/plugins/support.test.ts diff --git a/src/user-icons/test/routes/example.test.ts b/src/icons-service/test/routes/example.test.ts similarity index 100% rename from src/user-icons/test/routes/example.test.ts rename to src/icons-service/test/routes/example.test.ts diff --git a/src/user-icons/test/routes/root.test.ts b/src/icons-service/test/routes/root.test.ts similarity index 100% rename from src/user-icons/test/routes/root.test.ts rename to src/icons-service/test/routes/root.test.ts diff --git a/src/user-icons/test/tsconfig.json b/src/icons-service/test/tsconfig.json similarity index 100% rename from src/user-icons/test/tsconfig.json rename to src/icons-service/test/tsconfig.json diff --git a/src/user-icons/tsconfig.json b/src/icons-service/tsconfig.json similarity index 100% rename from src/user-icons/tsconfig.json rename to src/icons-service/tsconfig.json