diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c58c9d3..cab8c5b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # GameVault Backend Server Changelog +## 11.0.2 + +Recommended Gamevault App Version: `v1.8.2.0` or `v1.9.0.0` + +### Changes + +- Build Image now includes auto-created default folders, due to a permissions bug with the /logs folder now being written to by default. + ## 11.0.1 Recommended Gamevault App Version: `v1.8.2.0` or `v1.9.0.0` diff --git a/Dockerfile b/Dockerfile index 0bc3a257..8d5b130d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,10 @@ FROM node:lts-slim AS base + # Default Variables ENV PUID=1000 ENV PGID=1000 ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true + # Build time variables ## Allow non-root usage ENV NPM_CONFIG_PREFIX=/home/node/.npm-global @@ -10,38 +12,54 @@ ENV PATH=$PATH:/home/node/.npm-global/bin ENV PNPM_HOME=/pnpm ENV PATH=$PNPM_HOME:$PATH ENV SERVER_PORT=8080 -VOLUME /files /images /logs /db + +# Create directories and set more restrictive permissions +RUN mkdir -p /files /images /logs /db \ + && chown -R node:node /files /images /logs /db + # Install pnpm and other needed tools -RUN sed -i -e's/ main/ main non-free non-free-firmware contrib/g' /etc/apt/sources.list.d/debian.sources \ +RUN sed -i -e's/ main/ main non-free non-free-firmware contrib/g' /etc/apt/sources.list.d/debian.sources \ && apt update \ && apt install -y sudo tzdata curl p7zip-full p7zip-rar postgresql-client \ + && apt clean \ && npm i -g pnpm + WORKDIR /app FROM base AS build + # Copy files only needed for install COPY package.json pnpm-lock.yaml ./ RUN pnpm install --frozen-lockfile + # Copy everything for building COPY . . RUN pnpm run build FROM base AS prod-deps + COPY package.json pnpm-lock.yaml ./ RUN pnpm install --prod --frozen-lockfile FROM base AS release + ENV NODE_ENV=production + COPY package.json pnpm-lock.yaml ./ + # Chown /app to the original node user (1000) # As only read is needed this is fine when using --user or PUID COPY --from=build --chown=node:node /app/dist ./dist COPY --from=prod-deps --chown=node:node /app/node_modules ./node_modules + # Entry script for providing dynamic env changes like PUID COPY entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/entrypoint.sh + EXPOSE ${SERVER_PORT}/tcp + # Periodic Healthcheck on /api/v1/health HEALTHCHECK CMD curl -f http://localhost:${SERVER_PORT}/api/health || exit + ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD [ "dist/src/main" ] diff --git a/entrypoint.sh b/entrypoint.sh index 69c2ecc4..f216caf3 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,11 +2,15 @@ set -e # If running as root, it means the --user directive for Docker CLI/Compose was not used -# Use then the PUID env +# Use then the PUID env to set the user and group IDs if [ "$(id -u)" = '0' ]; then + # Modify the group ID of the 'node' user to match the PGID environment variable groupmod -o -g "$PGID" node + # Modify the user ID of the 'node' user to match the PUID environment variable usermod -o -u "$PUID" node + # Run the specified command with the modified user and group IDs sudo -u "#$PUID" -g "#$PGID" -E node "${@}" -else # if using the user directive, run normally +else + # If using the user directive, run the specified command normally exec node "${@}" -fi \ No newline at end of file +fi diff --git a/package.json b/package.json index 1543b304..de75d703 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gamevault-backend", - "version": "11.0.1", + "version": "11.0.2", "description": "the self-hosted gaming platform for drm-free games", "author": "Alkan Alper, Schäfer Philip GbR / Phalcode", "private": true, diff --git a/src/modules/files/files.service.ts b/src/modules/files/files.service.ts index f3bb2f84..d5db3d90 100644 --- a/src/modules/files/files.service.ts +++ b/src/modules/files/files.service.ts @@ -27,7 +27,7 @@ import { watch } from "chokidar"; import { debounce } from "lodash"; import { Readable } from "stream"; import { Throttle } from "stream-throttle"; -import { mkdir, readdir, stat } from "fs/promises"; +import { readdir, stat } from "fs/promises"; import { Cron } from "@nestjs/schedule"; @Injectable() @@ -41,7 +41,6 @@ export class FilesService implements OnApplicationBootstrap { ) {} onApplicationBootstrap() { - this.checkFolders(); this.index("Initial indexing on application start").catch((error) => { this.logger.error(error, "Error in initial file indexing"); }); @@ -550,52 +549,4 @@ export class FilesService implements OnApplicationBootstrap { type, }); } - - /** Checks and creates necessary folders if they do not exist. */ - private checkFolders() { - if (configuration.TESTING.MOCK_FILES) { - this.logger.warn( - "Not checking or creating any folders because TESTING_MOCK_FILES is set to true", - ); - return; - } - - this.createDirectoryIfNotExist( - configuration.VOLUMES.FILES, - `Directory "${configuration.VOLUMES.FILES}" does not exist. Trying to create a new one...`, - ); - - this.createDirectoryIfNotExist( - configuration.VOLUMES.IMAGES, - `Directory "${configuration.VOLUMES.IMAGES}" does not exist. Trying to create a new one...`, - ); - - if (configuration.SERVER.LOG_FILES_ENABLED) { - this.createDirectoryIfNotExist( - configuration.VOLUMES.LOGS, - `Directory "${configuration.VOLUMES.LOGS}" does not exist. Trying to create a new one...`, - ); - } - - if ( - configuration.DB.SYSTEM === "SQLITE" && - !configuration.TESTING.IN_MEMORY_DB - ) { - this.createDirectoryIfNotExist( - configuration.VOLUMES.SQLITEDB, - `Directory "${configuration.VOLUMES.SQLITEDB}" does not exist. Trying to create a new one...`, - ); - } - } - - /** Creates a directory if it does not exist. */ - private async createDirectoryIfNotExist( - path: string, - errorMessage: string, - ): Promise { - if (!existsSync(path)) { - this.logger.error(errorMessage); - await mkdir(path); - } - } }