feat(docker): ship unified self-hosted image

This commit is contained in:
4gray committed 2026-05-15 11:20:55 +02:00
1 parent 3fb8245f30
commit 8f81db0d2d
4 files changed
+90 -36

No files matched your search

+20 -16
View File
@@ -1,32 +1,36 @@
# Stage 1 - build environment
FROM node:22-alpine AS build
RUN apk add --no-cache python3 make g++ git
# Create app directory
WORKDIR /usr/src/app
# Swtich to node user
#RUN chown node:node ./
#USER node
COPY .npmrc ./
COPY package.json pnpm-lock.yaml ./
# Install app dependencies
RUN corepack enable && pnpm install --frozen-lockfile
# Copy all required files
COPY . .
# Build the application
RUN pnpm run build:web
RUN pnpm nx build web --configuration=pwa
RUN pnpm nx build web-backend
# Stage 2 - the production environment
FROM nginx:stable-alpine
FROM node:22-alpine
# Copy artifacts and nignx.conf
COPY --from=build /usr/src/app/dist/browser /usr/share/nginx/html
COPY --from=build /usr/src/app/docker/nginx.conf /etc/nginx/conf.d/default.conf
RUN apk add --no-cache nginx
CMD sed -i "s#http://localhost:3333#$BACKEND_URL#g" /usr/share/nginx/html/main.js && nginx -g 'daemon off;'
WORKDIR /opt/iptvnator
ENV PORT=3000
ENV BACKEND_URL=/api
ENV CLIENT_URL=http://localhost:4333
COPY --from=build /usr/src/app/dist/apps/web /usr/share/nginx/html
COPY --from=build /usr/src/app/dist/apps/web-backend ./web-backend
COPY docker/nginx.conf /etc/nginx/http.d/default.conf
COPY docker/docker-entrypoint.sh /usr/local/bin/iptvnator-entrypoint
RUN chmod +x /usr/local/bin/iptvnator-entrypoint
EXPOSE 80
CMD ["iptvnator-entrypoint"]
+6 -12
View File
@@ -1,18 +1,12 @@
---
services:
backend:
image: 4gray/iptvnator-backend:latest
ports:
- "7333:3000"
environment:
- CLIENT_URL=http://localhost:4333
# this one should match with the address and port in frontend CLIENT_URL env
frontend:
iptvnator:
image: 4gray/iptvnator:latest
build:
context: ..
dockerfile: docker/Dockerfile
ports:
- "4333:80"
environment:
- BACKEND_URL=http://localhost:7333
# this one should match with the address of the backend service
BACKEND_URL: /api
CLIENT_URL: http://localhost:4333
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh
set -eu
: "${PORT:=3000}"
: "${BACKEND_URL:=/api}"
: "${CLIENT_URL:=http://localhost:4333}"
export PORT BACKEND_URL CLIENT_URL
sed -i "s#127.0.0.1:3000#127.0.0.1:${PORT}#g" /etc/nginx/http.d/default.conf
node <<'NODE'
const fs = require('node:fs');
const configPath = '/usr/share/nginx/html/assets/app-config.js';
const config = { BACKEND_URL: process.env.BACKEND_URL || '/api' };
fs.mkdirSync('/usr/share/nginx/html/assets', { recursive: true });
fs.writeFileSync(
configPath,
`window.__IPTVNATOR_CONFIG__ = Object.assign({}, window.__IPTVNATOR_CONFIG__, ${JSON.stringify(config)});\n`
);
NODE
node /opt/iptvnator/web-backend/main.cjs &
backend_pid="$!"
shutdown() {
kill "$backend_pid" 2>/dev/null || true
}
trap shutdown INT TERM EXIT
nginx -g 'daemon off;'
+30 -8
View File
@@ -1,11 +1,33 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
root /usr/share/nginx/html;
index index.html;
location = /assets/app-config.js {
add_header Cache-Control "no-store";
try_files $uri =404;
}
include /etc/nginx/extra-conf.d/*.conf;
}
location = /ngsw-worker.js {
add_header Cache-Control "no-cache";
try_files $uri =404;
}
location = /ngsw.json {
add_header Cache-Control "no-cache";
try_files $uri =404;
}
location /api/ {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:3000/;
}
location / {
try_files $uri $uri/ /index.html;
}
}