Skip to content

Commit

Permalink
Release 11.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfagun74 authored Apr 2, 2024
2 parents a9a83eb + 9db44fd commit 93b39f5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 56 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
22 changes: 20 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,65 @@
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
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" ]
10 changes: 7 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
fi
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
51 changes: 1 addition & 50 deletions src/modules/files/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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");
});
Expand Down Expand Up @@ -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<void> {
if (!existsSync(path)) {
this.logger.error(errorMessage);
await mkdir(path);
}
}
}

0 comments on commit 93b39f5

Please sign in to comment.