Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add docker image #11

Merged
merged 7 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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-*
20 changes: 11 additions & 9 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG] Title"
title: '[BUG] Title'
labels: ''
assignees: ''

---

**Describe the bug**
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 '....'
Expand All @@ -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.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
- name: Install dependencies
run: pnpm install

- run: pnpm lint
- run: pnpm lint
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Frontend Builder
FROM node:20-alpine AS frontend
WORKDIR /app
COPY . .
RUN npm install -g pnpm && pnpm install
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"]
79 changes: 79 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion src/routes/settings/mediaserver/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/routes/settings/scrapers/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading