Browse Source

feat: New docker setup

pull/12/head
Dale 3 weeks ago
parent
commit
e9c755a953
Signed by: Deiru GPG Key ID: AA250C0277B927E1
  1. 1
      backend.Dockerfile
  2. 10
      default.nix
  3. 23
      docker-compose/docker-compose.yml
  4. 0
      docker-compose/docker.miracle-tv.json
  5. 13
      docker-compose/rtmp-configs/nginx-rtmp/nginx.conf.template
  6. 2
      package.json

1
backend.Dockerfile

@ -4,7 +4,6 @@ RUN apk add --no-cache python g++ make
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn build:server
COPY ./src/server/graphql/schema dist/server/graphql
EXPOSE 4000
CMD yarn run:server /conf/config.json

10
default.nix

@ -28,6 +28,8 @@ in mkYarnPackage rec {
cp -R $node_modules/* ./node_modules
cp -R $node_modules/.bin ./node_modules
# rm -rf ./node_modules/socket.io/client-dist
runHook preConfigure
'';
@ -35,7 +37,6 @@ in mkYarnPackage rec {
runHook preBuild
# Build server and client
yarn --offline build:server
yarn --offline build:client
yarn --offline build:cli
@ -48,6 +49,7 @@ in mkYarnPackage rec {
# Create output dirs
mkdir -p $out/bin
mkdir -p $out/dist/server/graphql
mkdir -p $out/dist/shared
mkdir -p $out/dist/server/lib/binding/napi-v3
# Copy files needed for the suite to run
@ -57,13 +59,15 @@ in mkYarnPackage rec {
cp next.config.js $out/next.config.js
# Copy server dist
cp -r ./dist/server/* $out/dist/server
cp -r ./src/server/graphql/schema/* $out/dist/server/graphql
cp -r ./src/server/* $out/dist/server
cp -r ./src/shared/* $out/dist/shared
# Wrap yarn to run server as `miracle-server`
makeWrapper $yarnPkg/bin/yarn $out/bin/miracle-server \
--add-flags "--cwd $out" \
--add-flags "run:server" \
--set NODE_PATH "$node_modules" \
--set PATH "$PATH:$node_modules/.bin" \
--set NODE_ENV production
# Copy client dist

23
docker-compose.yml → docker-compose/docker-compose.yml

@ -1,4 +1,5 @@
version: "3.9"
services:
nginx:
image: "alqutami/rtmp-hls"
@ -7,29 +8,43 @@ services:
- "1337:1337"
volumes:
- ./nginx.conf.template:/etc/nginx/nginx.conf
depends_on:
depends_on:
- miracle-backend
- miracle-frontend
networks:
- external_network
- internal_network
rethinkdb:
image: "rethinkdb"
networks:
- internal_network
miracle-backend:
build:
context: "."
dockerfile: "backend.Dockerfile"
dockerfile: "../backend.Dockerfile"
ports:
- "4000:4000"
depends_on:
- rethinkdb
volumes:
- ./docker.miracle-tv.json:/conf/config.json
networks:
- internal_network
miracle-frontend:
build:
context: "."
dockerfile: "frontend.Dockerfile"
ports:
dockerfile: "../frontend.Dockerfile"
ports:
- "3000:3000"
depends_on:
- miracle-backend
environment:
- NEXT_PUBLIC_ENV=local
- NEXT_PUBLIC_API_URL=localhost:1337/api
networks:
- internal_network
networks:
external_network:
internal_network:
internal: true

0
docker.miracle-tv.json → docker-compose/docker.miracle-tv.json

13
nginx.conf.template → docker-compose/rtmp-configs/nginx-rtmp/nginx.conf.template

@ -37,10 +37,10 @@ rtmp {
# On 2xx: Allows streaming.
# On 3xx: Redirects? Not sure what that would be, honestly.
# On 4xx: Denies streaming.
on_publish "http://miracle-backend:4000/api/hook/on_publish?name=$uri";
on_publish "http://miracle-backend:4000/api/hook/nginx-rtmp/on_publish?name=$uri";
# Callback for when a stream stops.
on_publish_done http://miracle-backend:4000/api/hook/on_publish_done;
on_publish_done http://miracle-backend:4000/api/hook/nginx-rtmp/on_publish_done;
# Deny listening to this endpoint for non-localhost.
allow play 127.0.0.1;
@ -110,12 +110,12 @@ http {
# }
# HLS fragments.
location /hls {
location /streaming/hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt;
alias /mnt/hls/;
# Don't cache.
add_header Cache-Control no-cache;
@ -135,12 +135,12 @@ http {
# DASH fragments; largely similar to HLS config.
# TODO: refactor so these cache bits can be more DRY?
location /dash {
location /streaming/dash {
types {
application/dash+xml mpd;
video/mp4 mp4;
}
root /mnt;
alias /mnt/dash/;
}
# Proxy all /api requests to Miracle backend.
@ -186,5 +186,4 @@ http {
}
}
}
}

2
package.json

@ -9,7 +9,7 @@
"daemon:stop": "pm2 delete miracle-tv",
"daemon:restart": "name=miracle-tv pm2 restart miracle-tv --update-env",
"dev:server": "nodemon -e ts,tsx,graphql --ignore src/shared/theme --ignore src/client --ignore src/pages --exec \"ts-node -r tsconfig-paths/register src/server/server.ts\"",
"run:server": "NODE_ENV=production node dist/server/index.js",
"run:server": "NODE_ENV=production ts-node -r tsconfig-paths/register src/server/server.ts",
"run:ctl": "NODE_ENV=production node dist/cli/index.js",
"build:server": "ncc build src/server/server.ts -o ./dist/server",
"build:client": "next build",

Loading…
Cancel
Save