diff --git a/docker-compose.yml b/docker-compose.yml index 96b3718..67f5f3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,12 @@ networks: transcendance-network: driver: bridge services: + # + # The "entry point" as in it does all of this: + # - serve files (images, static files, video) + # - redirect request to appropirate service (reverse proxy) + # - be the one that handles TLS/SSL (basically HTTPS) + # - other stuff I don't know yet nginx: build: ./nginx container_name: nginx @@ -11,22 +17,32 @@ services: ports: - '8888:443' volumes: + # if you need to share files with nginx, you do it here. - images-volume:/volumes/icons environment: + # this can stay the same for developpement. This is an alias to `localhost` - NGINX_DOMAIN=local.maix.me + # an example of an micro service. this one basically only does this: + # - handle uploading of icons + # - write icons to shared volume allowing nginx to serve them (does it better than if we did it in the service) icons-service: + # build is a bit strange: it has two parts build: - dockerfile: ./src/icons-service/Dockerfile # dockerfile to use - context: . # the directory to use as `root` (aka the directory you get with `.`) + # the dockerfile to use + dockerfile: ./src/icons-service/Dockerfile + # the current working directory. This means `.` in Dockerfile + context: . container_name: icons-service restart: always networks: - transcendance-network volumes: - images-volume:/store + - sqlite-volume:/database environment: - USER_ICONS_STORE=/store + - DATABASE_DIR=/database volumes: images-volume: sqlite-volume: diff --git a/nginx/15-local-resolvers.envsh b/nginx/15-local-resolvers.envsh index bc406b4..04512a7 100755 --- a/nginx/15-local-resolvers.envsh +++ b/nginx/15-local-resolvers.envsh @@ -1,6 +1,7 @@ #!/bin/sh # if $NGINX_RESOLVERS set to local, set it to the local resolvers from /etc/resolv.conf and export it +# DO NOT EDIT THIS FILE set -eu diff --git a/nginx/17-add-template-prefix.sh b/nginx/17-add-template-prefix.sh index 185703f..b758867 100755 --- a/nginx/17-add-template-prefix.sh +++ b/nginx/17-add-template-prefix.sh @@ -1,5 +1,8 @@ #!/bin/sh + +# DO NOT EDIT THIS FILE + set -e ME=$(basename "$0") diff --git a/nginx/README.md b/nginx/README.md new file mode 100644 index 0000000..ceb043c --- /dev/null +++ b/nginx/README.md @@ -0,0 +1,8 @@ +# Nginx Configuration + +You want to have a new microservice ? + +Edit/add a file in `conf/locations/` +take example on `conf/locations/icons.conf` on how to make a reverse proxy and on how to serve static files + +# Good Luck Have Fun diff --git a/nginx/conf/default.conf b/nginx/conf/default.conf index d2ffbb0..1ced253 100644 --- a/nginx/conf/default.conf +++ b/nginx/conf/default.conf @@ -1,3 +1,5 @@ +# please make sure you want to edit this file... + # this allows the redirection of `http://domain/URL` to `https://domain/URL` server { charset UTF-8; diff --git a/nginx/conf/locations/db.conf b/nginx/conf/locations/db.conf deleted file mode 100644 index 9c93b52..0000000 --- a/nginx/conf/locations/db.conf +++ /dev/null @@ -1,4 +0,0 @@ -location /api/db { - add_header Content-Type text/plain; - return 200 'db api yay'; -} diff --git a/src/icons-service/Dockerfile b/src/icons-service/Dockerfile index d232772..85a02c7 100644 --- a/src/icons-service/Dockerfile +++ b/src/icons-service/Dockerfile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/06/16 14:57:11 by maiboyer #+# #+# # -# Updated: 2025/06/17 16:31:49 by maiboyer ### ########.fr # +# Updated: 2025/07/19 15:26:15 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -17,6 +17,7 @@ FROM node:24-alpine as utils-builder WORKDIR /app COPY ./src/utils /app +RUN apk add python3; RUN set -x && npm install && npm run build:ts && mkdir /out && cp -r package*.json dist/ /out; # ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/icons-service/src/routes/set/index.ts b/src/icons-service/src/routes/set/index.ts index a65cfd6..db5795c 100644 --- a/src/icons-service/src/routes/set/index.ts +++ b/src/icons-service/src/routes/set/index.ts @@ -6,9 +6,15 @@ import sharp from 'sharp' const example: FastifyPluginAsync = async (fastify, opts): Promise => { // await fastify.register(authMethod, {}); + + // here we register plugins that will be active for the current fastify instance (aka everything in this function) await fastify.register(fastifyRawBody, { encoding: false }); + + // we register a route handler for: `/` + // it sets some configuration options, and set the actual function that will handle the request fastify.post('/:userid', { config: { rawBody: true, encoding: false } }, async function(request, reply) { - console.log(request.headers); + + // this is how we get the `:userid` part of things const userid: string | undefined = (request.params as any)['userid']; if (userid === undefined) { return await reply.code(403); diff --git a/src/utils/README.md b/src/utils/README.md new file mode 100644 index 0000000..668c372 --- /dev/null +++ b/src/utils/README.md @@ -0,0 +1,15 @@ +# Utils Library + +This library is made to be shared by all of the service. +It should handle things like database interface, shared stuff like 'make sure this is accessed by an connected user' + +# How it is used + +Painfully. + +# Why no Docker ? + +Docker compose can't make "build-only" docker images, where we just use them. +So we have to "build" the library in every Dockerfile for every service. +Well not really, dockers caches things for use, +meaning that while it seems that everybody builds it, it is only built once diff --git a/src/utils/package-lock.json b/src/utils/package-lock.json index 13f16fa..7b338ff 100644 --- a/src/utils/package-lock.json +++ b/src/utils/package-lock.json @@ -178,9 +178,9 @@ } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", - "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.4.tgz", + "integrity": "sha512-VT2+G1VQs/9oz078bLrYbecdZKs912zQlkelYpuf+SXF+QvZDYJlbx/LSx+meSAwdDFnF8FVXW92AVjjkVmgFw==", "dev": true, "license": "MIT" }, @@ -252,9 +252,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.15.32", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.32.tgz", - "integrity": "sha512-3jigKqgSjsH6gYZv2nEsqdXfZqIFGAV36XYYjf9KGZ3PSG+IhLecqPnI310RvjutyMwifE2hhhNEklOUrvx/wA==", + "version": "22.16.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.16.5.tgz", + "integrity": "sha512-bJFoMATwIGaxxx8VJPeM8TonI8t579oRvgAuT8zFugJsJZgzqv0Fu8Mhp68iecjzG7cnN3mO2dJQ5uUM2EFrgQ==", "dev": true, "license": "MIT", "dependencies": { @@ -642,9 +642,9 @@ "license": "MIT" }, "node_modules/concurrently": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.1.2.tgz", - "integrity": "sha512-H9MWcoPsYddwbOGM6difjVwVZHl63nwMEwDJG/L7VGtuaJhb12h2caPG2tVPWs7emuYix252iGfqOyrz1GczTQ==", + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.2.0.tgz", + "integrity": "sha512-IsB/fiXTupmagMW4MNp2lx2cdSN2FfZq78vF90LBB+zZHArbIQZjQtzXCiXnvTxCZSvXanTqFLWBjw2UkLx1SQ==", "dev": true, "license": "MIT", "dependencies": { @@ -2178,9 +2178,9 @@ } }, "node_modules/v8-to-istanbul/node_modules/@jridgewell/trace-mapping": { - "version": "0.3.25", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", - "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", + "version": "0.3.29", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.29.tgz", + "integrity": "sha512-uw6guiW/gcAGPDhLmd77/6lW8QLeiV5RUTsAX46Db6oLhGaVj4lhnPwb184s1bkc8kdVg/+h988dro8GRDpmYQ==", "dev": true, "license": "MIT", "dependencies": {