Skip to content

Commit

Permalink
refactor(stremio)!: new patching system
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The compose script will now load patches from files/patches folder instead of the patches.sh file.
  • Loading branch information
n0bodysec committed Jun 29, 2023
1 parent 78c64c6 commit 62d0e87
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 72 deletions.
3 changes: 0 additions & 3 deletions stremio/.env.example

This file was deleted.

16 changes: 8 additions & 8 deletions stremio/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
##########################################################################

# Builder image
# builder image
FROM node:alpine AS builder

# Build args
# build args
ARG SERVER_VERSION=master
ARG DOWNLOAD_URL=https://dl.strem.io/four/${SERVER_VERSION}

Expand All @@ -12,11 +12,11 @@ RUN apk add --no-cache git wget dos2unix
RUN git clone https://github.com/Stremio/stremio-web.git

WORKDIR /srv/stremio/dist
COPY files/*.sh ./
COPY files/run.sh ./
RUN chmod +x *.sh && dos2unix *.sh

WORKDIR /srv/stremio/dist/shell
RUN wget -mkEpnp -nH https://staging.strem.io || true
RUN wget -mkEpnp -nH https://staging.strem.io https://staging.strem.io/worker.js https://staging.strem.io/images/anonymous.svg || true

WORKDIR /srv/stremio/stremio-web
RUN npm ci && npm run build && cp -r build ../dist/web
Expand All @@ -26,15 +26,15 @@ RUN wget $DOWNLOAD_URL/server.js $DOWNLOAD_URL/stremio.asar && cp server.js serv

##########################################################################

# Main image
# main image
FROM node:alpine

WORKDIR /srv/stremio
RUN apk add --no-cache ffmpeg
COPY --from=builder /srv/stremio/dist ./
RUN npm install -g http-server

# Expose default ports
EXPOSE 11470 8080 8081
# expose default ports
EXPOSE 11470 12470 8080 8081

CMD ["./run.sh"]
CMD ["./run.sh"]
70 changes: 35 additions & 35 deletions stremio/README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
# stremio-web
# stremio

This docker image contains a built copy of the open source [stremio-web](https://github.com/Stremio/stremio-web/), a copy of the stremio-shell web ui and a copy of the closed source [stremio-server](http://dl.strem.io/four/master/server.js).
<img align="right" src="https://avatars.githubusercontent.com/u/13152917?s=256">

With this image, you can quickly deploy a ready-to-use stremio-web client and server.
Stremio is a modern multimedia center that is an all-in-one solution for your video entertainment. With this Docker image, you can launch a container ready to use with Stremio Web, Stremio Shell and Stremio Server.

## 🃏 Features
### ❓ What is included in this image?
- A build copy of the open source [stremio-web](https://github.com/Stremio/stremio-web/).
- A local copy of the closed source [stremio-shell](https://github.com/Stremio/stremio-shell)'s [web ui](https://app.strem.io/).
- A local copy of the closed source [stremio-server](http://dl.strem.io/four/master/server.js).

- Small final image (thanks to multi-stage builds).
- Fully customizable through environment variables and bind mounts.
- Optional patches for better usability (via script).
- Both Stremio Web & old Web UI (Stremio Shell) included.
> ⚠️ **WARNING**: Stremio released an official server docker image [here](https://github.com/Stremio/server-docker). You can continue to use this version instead, as it supports hot patching and integrates both web ui's into a single image.
## 🚀 Deploy
## 🃏 Features

1. Create a `docker-compose.override.yml` file and edit it to suit your needs (***optional***).
2. Copy `.env.example` to `.env` and edit it accordingly.
3. Run `docker compose up -d`.
- Small final image, thanks to multi-stage builds.
- Optional web ui patches for better usability.
- Optional server patches, customizable through custom scripts and environment variables.

## ⚙️ Configuration
## 🚀 Deploy

## Best practice
You can deploy in two different ways:

Running the container with docker compose, with `APPLY_PATCHES`, `FIX_UNSUPPORTED_MEDIA` and `NO_CORS` env vars is the preferred way to go.
> If you want to use the old webui, then you don't need to apply any patches.
**1. Docker Compose (RECOMMENDED)**
```console
docker compose up -d
```

Example (without compose)
**2. Docker CLI**
```console
docker run --rm -p 8080:8080 -p 8081:8081 -p 11470:11470 -e APPLY_PATCHES=1 -e FIX_UNSUPPORTED_MEDIA=1 -e NO_CORS=1 -v ${PWD}:/root/.stremio-server n0bodysec/stremio
```

## Docker Compose
## ⚙️ Configuration

Using docker compose is the preferred way to go.
```shell
docker compose up -d
```
### Best practices

## Apply custom patches
Enabling the `APPLY_PATCHES`, `FIX_UNSUPPORTED_MEDIA` and `NO_CORS` environment variables is the preferred way to go.
> ⚠️ If your intention is to use only the **old ui web**, then you do not need to apply any patches, therefore, you do not require any of the above environment variables.
To apply the optional patches (see `patches.sh`) you **must** set the environment variable `APPLY_PATCHES`.
```shell
docker run -e APPLY_PATCHES=1 n0bodysec/stremio
```
### Apply custom patches

To apply the optional patches for the server, you must set the `APPLY_PATCHES` environment variable to `1`.
All files with `.sh` extension inside the `files/patches` folder will be loaded when that environment variable is active. You can add your own patches to that folder.
> ⚠️ **WARNING**: As the container runs in a linux environment, it is mandatory that the patch files have `LF` ending instead of `CRLF`.
## Environment variables
### Environment variables

| **Variable** | **Description** | **Source** |
|----------------------- |------------------------------------- |------------ |
| APPLY_PATCHES | Apply patches defined in patches.sh | run.sh |
| FIX_UNSUPPORTED_MEDIA | Fix for HTTP 415 | patches.sh |
| FIX_CORS | **Deprecated.** See NO_CORS | patches.sh |
| NO_CORS | Do no check CORS in the SERVER | server.js |
| WEBUI_LOCATION | Web UI location (direct access) | server.js |
| **Variable** | **Description** | **Source** |
|----------------------- |------------------------------------- |------------ |
| APPLY_PATCHES | Apply patches defined in patches.sh | run.sh |
| FIX_UNSUPPORTED_MEDIA | Fix for HTTP 415 | patches/ |
| NO_CORS | Do no check CORS in the SERVER | server.js |
| WEBUI_LOCATION | Web UI location (direct access) | server.js |

For more environment variables, please check the `server.js` file.
Undocumented env vars: `APPDATA`, `APP_PATH`, `BLUEBIRD_DEBUG`, `BLUEBIRD_LONG_STACK_TRACES`, `BLUEBIRD_WARNINGS`, `BLUEBIRD_W_FORGOTTEN_RETURN`, `CASTING_DISABLED`, `COLORTERM`, `DEBUG`, `DEBUG_COLORS`, `DEBUG_COLORS`, `DEBUG_DEPTH`, `DEBUG_FD`, `DEBUG_MIME`, `DEBUG_SHOW_HIDDEN`, `DISABLE_CACHING`, `DISABLE_CACHING`, `FFMPEG_BIN`, `FFMPEG_DEBUG`, `FFSPLIT_DEBUG`, `FORCE_COLOR`, `HOME`, `HTTPS_CERT_ENDPOINT`, `NODE_DEBUG`, `NODE_ENV`, `NO_DEPRECATION`, `OPEN`, `OSTYPE`, `PATHEXT`, `PORT`, `READABLE_STREAM`, `SUDO_USER`, `SystemRoot`, `TEMP`, `TERM`, `TMP`, `TMPDIR`, `TRACE_DEPRECATION`, `TV_ENV`, `YTDL_NO_UPDATE`, `npm_config_arch`, `npm_config_platform`,
Expand Down
15 changes: 0 additions & 15 deletions stremio/docker-compose.dev.yml

This file was deleted.

10 changes: 8 additions & 2 deletions stremio/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ version: '3.9'
services:
stremio:
image: n0bodysec/stremio
# build: .
ports:
- '11470:11470'
- '12470:12470'
- '8080:8080'
- '8081:8081'
volumes:
- ./data/:/root/.stremio-server
- ./files/patches.js:/srv/stremio/web/patches.js:ro
- ./files/patches.js:/srv/stremio/shell/patches.js:ro
env_file:
- .env
- ./files/patches:/srv/stremio/patches:ro
environment:
WORKDIR: /srv/stremio # important! used for patches
APPLY_PATCHES: 1
FIX_UNSUPPORTED_MEDIA: 1
NO_CORS: 1
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/bin/sh

# Only if you re-use containers (please do not do that)
cp server/server.js.bak server/server.js

# Fix for HTTP 415 Unsupported Media Type
if [ ${FIX_UNSUPPORTED_MEDIA:-0} -eq 1 ]; then
echo "Applying patch for HTTP 415 Unsupported Media Type..."
sed -i -E "s|(var first = req\.params\.first)|if (req.params.first === 'hlsv2') { req.params.first = req.query.mediaURL.split('/')[3]; req.params.second = req.query.mediaURL.split('/')[4]; }\n \1|" server/server.js
sed -i -E 's/HLS.masterMultiPlaylistMiddleware\)/HLS.masterPlaylistMiddleware\)/' server/server.js
sed -i -E "s|(var first = req\.params\.first)|if (req.params.first === 'hlsv2') { req.params.first = req.query.mediaURL.split('/')[3]; req.params.second = req.query.mediaURL.split('/')[4]; }\n \1|" $WORKDIR/server/server.js
sed -i -E 's/HLS.masterMultiPlaylistMiddleware\)/HLS.masterPlaylistMiddleware\)/' $WORKDIR/server/server.js
fi
15 changes: 12 additions & 3 deletions stremio/files/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
# create file if it doesn't exist
touch -a /root/.stremio-server/server-settings.json

# restore a fresh server.js
# cp server/server.js.bak server/server.js

# run patches
if [[ ${APPLY_PATCHES:-0} -eq 1 ]]; then
echo "Applying patches..."
chmod +x ./patches.sh
sh ./patches.sh
if [ ! -d "patches" ]; then
echo "Patches folder does not exist. Skipping patches..."
else
echo "Applying patches..."
for file in patches/*.sh; do
echo "Executing patch $file"
sh $file
done
fi
else
echo "Patches will not be applied this time"
fi
Expand Down

0 comments on commit 62d0e87

Please sign in to comment.