From c38659539f269b87a214bed70231dabf02363581 Mon Sep 17 00:00:00 2001 From: Ayush Sehrawat <69469790+AyushSehrawat@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:13:27 +0000 Subject: [PATCH 1/3] feat: add docker image --- Dockerfile | 28 ++++++++++++++++++ entrypoint.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f8f07e7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Frontend Builder +FROM node:20-alpine AS frontend +WORKDIR /app +COPY package*.json ./ +RUN npm install -g pnpm && pnpm install +COPY / . +RUN pnpm run build && pnpm prune --prod + +# Final Image +FROM node:20-alpine +LABEL name="Riven" \ + description="Riven Media Server: Frontend" \ + url="https://github.com/rivenmedia/riven-frontend" + +# Set working directory +WORKDIR /riven + +# Copy frontend build from the previous stage +COPY --from=frontend /app/build /riven/build +COPY --from=frontend /app/node_modules /riven/node_modules +COPY --from=frontend /app/package.json /riven/package.json + +COPY version.txt entrypoint.sh /riven/ + +# Ensure entrypoint script is executable +RUN chmod +x /riven/entrypoint.sh + +ENTRYPOINT ["/riven/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..f5b4ea5 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# Default PUID and PGID to 1000 if not set +PUID=${PUID:-1001} +PGID=${PGID:-1001} + +echo "Starting Container with $PUID:$PGID permissions..." + +if [ "$PUID" = "0" ]; then + echo "Running as root user" + USER_HOME="/root" + mkdir -p "$USER_HOME" +else + # Validate PUID and PGID are integers + if ! echo "$PUID" | grep -qE '^[0-9]+$'; then + echo "PUID is not a valid integer. Exiting..." + exit 1 + fi + + if ! echo "$PGID" | grep -qE '^[0-9]+$'; then + echo "PGID is not a valid integer. Exiting..." + exit 1 + fi + + # Default USERNAME and GROUPNAME if not set + USERNAME=${USERNAME:-riven} + GROUPNAME=${GROUPNAME:-riven} + USER_HOME="/home/$USERNAME" + + # Create group if it doesn't exist + if ! getent group "$PGID" > /dev/null; then + addgroup -g "$PGID" "$GROUPNAME" + if [ $? -ne 0 ]; then + echo "Failed to create group. Exiting..." + exit 1 + fi + else + GROUPNAME=$(getent group "$PGID" | cut -d: -f1) + fi + + # Create user if it doesn't exist + if ! getent passwd "$USERNAME" > /dev/null; then + if getent passwd "$PUID" > /dev/null; then + EXISTING_USER=$(getent passwd "$PUID" | cut -d: -f1) + if [ "$EXISTING_USER" != "$USERNAME" ]; then + echo "UID $PUID is already in use by $EXISTING_USER. Please choose a different UID." + exit 1 + else + echo "User $USERNAME already exists with UID $PUID." + fi + else + adduser -D -h "$USER_HOME" -u "$PUID" -G "$GROUPNAME" "$USERNAME" + if [ $? -ne 0 ]; then + echo "Failed to create user. Exiting..." + exit 1 + fi + fi + else + if [ "$PUID" -ne 0 ]; then + echo "User modification not supported in this script for Alpine. Please ensure correct PUID/PGID beforehand." + fi + fi + + mkdir -p "$USER_HOME" + chown -R "$PUID:$PGID" "$USER_HOME" +fi + +umask 002 + +export XDG_CONFIG_HOME="$USER_HOME/.config" +export XDG_DATA_HOME="$USER_HOME/.local/share" +export HOME="$USER_HOME" + +: ${ORIGIN:="http://localhost:3000"} +: ${BACKEND_URL:="http://127.0.0.1"} + +# Start the frontend +echo "Starting frontend..." +exec su -m $USERNAME -c "ORIGIN=$ORIGIN BACKEND_URL=$BACKEND_URL node /riven/build" \ No newline at end of file From c3a3cee192f9c34dbf932cbd95caa4fcedd5a0ee Mon Sep 17 00:00:00 2001 From: Ayush Sehrawat <69469790+AyushSehrawat@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:28:23 +0000 Subject: [PATCH 2/3] fix: Dockerfile and add .dockerignore --- .dockerignore | 30 ++++++++++++++++++++++++++++++ Dockerfile | 3 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d58bafa --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +# Extras That Shouldn't Be Here +.git/ +.gitignore +.dockerignore +docker-compose* +Dockerfile +makefile +htmlcov/ +coverage.xml +.coverage* + +.vscode/ +.ruff_cache/ +*.dat + +# Backend +settings.json + +# frontend + +.DS_Store +node_modules +/build +/.svelte-kit +/package +.env +.env.* +!.env.example +vite.config.js.timestamp-* +vite.config.ts.timestamp-* diff --git a/Dockerfile b/Dockerfile index f8f07e7..b6dbc10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,8 @@ # Frontend Builder FROM node:20-alpine AS frontend WORKDIR /app -COPY package*.json ./ +COPY . . RUN npm install -g pnpm && pnpm install -COPY / . RUN pnpm run build && pnpm prune --prod # Final Image From 1088509873afe010b64b621192a8737f776451a6 Mon Sep 17 00:00:00 2001 From: Ayush Sehrawat <69469790+AyushSehrawat@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:29:26 +0000 Subject: [PATCH 3/3] chore: format --- .github/ISSUE_TEMPLATE/bug_report.md | 20 ++++++++++--------- .github/workflows/ci.yml | 2 +- .../settings/mediaserver/+page.server.ts | 1 - src/routes/settings/scrapers/+page.server.ts | 1 - 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 5220463..59f50eb 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Create a report to help us improve -title: "[BUG] Title" +title: '[BUG] Title' labels: '' assignees: '' - --- **Describe the bug** @@ -12,6 +11,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] **Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] **Additional context** Add any other context about the problem here. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d0489b..b4dbe03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,4 +39,4 @@ jobs: - name: Install dependencies run: pnpm install - - run: pnpm lint \ No newline at end of file + - run: pnpm lint diff --git a/src/routes/settings/mediaserver/+page.server.ts b/src/routes/settings/mediaserver/+page.server.ts index 73a012e..ea84dff 100644 --- a/src/routes/settings/mediaserver/+page.server.ts +++ b/src/routes/settings/mediaserver/+page.server.ts @@ -12,7 +12,6 @@ import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.serv import { env } from '$env/dynamic/private'; const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; - export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { try { diff --git a/src/routes/settings/scrapers/+page.server.ts b/src/routes/settings/scrapers/+page.server.ts index c9b7f6d..9db0120 100644 --- a/src/routes/settings/scrapers/+page.server.ts +++ b/src/routes/settings/scrapers/+page.server.ts @@ -12,7 +12,6 @@ import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.serv import { env } from '$env/dynamic/private'; const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080'; - export const load: PageServerLoad = async ({ fetch }) => { async function getPartialSettings() { try {