Skip to content

一分钟搭建影视站,支持Docker等部署方式

refactor: migrate from nginx-lua to Node.js runtime (#580)

旋律已经死了。f98e5e5feb10
diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml
index 4392d5f..46d9726 100644
--- a/.github/workflows/docker-build.yml
+++ b/.github/workflows/docker-build.yml
@@ -45,4 +45,4 @@ jobs:
file: Dockerfile
push: true
tags: "${{ secrets.DOCKER_USERNAME }}/${{ steps.set-tag.outputs.IMAGE_TAG }}"
- platforms: linux/amd64,linux/arm64/v8
\ No newline at end of file
+ platforms: linux/amd64,linux/arm64/v8,linux/arm/v7
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index dc3ec9f..f0be2cc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,25 +1,42 @@
-FROM fabiocicerchia/nginx-lua:1.27.5-alpine3.21.3
+FROM node:lts-alpine
+
LABEL maintainer="LibreTV Team"
LABEL description="LibreTV - 免费在线视频搜索与观看平台"
-# 复制应用文件
-COPY . /usr/share/nginx/html
+# 设置环境变量
+ENV PORT=8080
+ENV CORS_ORIGIN=*
+ENV DEBUG=false
+ENV REQUEST_TIMEOUT=5000
+ENV MAX_RETRIES=2
+ENV CACHE_MAX_AGE=1d
-# 复制Nginx配置文件
-COPY nginx.conf /etc/nginx/conf.d/default.conf
+# 设置工作目录
+WORKDIR /app
-# 添加执行权限并设置为入口点脚本
-COPY docker-entrypoint.sh /
-RUN chmod +x /docker-entrypoint.sh
+# 复制 package.json 和 package-lock.json(如果存在)
+COPY package*.json ./
-# 暴露端口
-EXPOSE 80
+# 安装依赖
+RUN npm ci --only=production && npm cache clean --force
+
+# 复制应用文件
+COPY . .
+
+# 创建非 root 用户
+RUN addgroup -g 1001 -S nodejs && \
+ adduser -S libretv -u 1001
-# 设置入口点
-ENTRYPOINT ["/docker-entrypoint.sh"]
+# 更改文件所有者
+RUN chown -R libretv:nodejs /app
+USER libretv
-# 启动nginx
-CMD ["nginx", "-g", "daemon off;"]
+# 暴露端口
+EXPOSE 8080
# 健康检查
-HEALTHCHECK --interval=30s --timeout=3s CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
\ No newline at end of file
+HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
+ CMD node -e "require('http').get('http://localhost:8080', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
+
+# 启动应用
+CMD ["npm", "start"]
diff --git a/docker-compose.yml b/docker-compose.yml
index 19e5f31..0d57f08 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,10 +1,9 @@
-version: '3'
services:
libretv:
image: bestzwei/libretv:latest
container_name: libretv
ports:
- - "8899:80"
+ - "8899:8080"
environment:
- PASSWORD=${PASSWORD:-111111}
restart: unless-stopped
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
deleted file mode 100644
index 1548304..0000000
--- a/docker-entrypoint.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/sh
-set -e
-
-# Function to hash a string with SHA-256
-hash_password() {
- if [ -z "$1" ]; then
- echo ""
- else
- echo -n "$1" | sha256sum | cut -d ' ' -f 1
- fi
-}
-
-# Function to replace environment variables in HTML files
-replace_env_vars() {
- # Hash the password if it exists
- local password_hash=""
- if [ -n "$PASSWORD" ]; then
- password_hash=$(hash_password "$PASSWORD")
- fi
-
- # Replace the password placeholder in all HTML files with the hashed password
- find /usr/share/nginx/html -type f -name "*.html" -exec sed -i "s/window.__ENV__.PASSWORD = \"{{PASSWORD}}\";/window.__ENV__.PASSWORD = \"${password_hash}\";/g" {} \;
-
- echo "Environment variables have been injected into HTML files."
-}
-
-# Replace environment variables in HTML files
-replace_env_vars
-
-# Execute the command provided as arguments
-exec "$@"
\ No newline at end of file
diff --git a/proxy.lua b/proxy.lua
deleted file mode 100644
index cd3726c..0000000
--- a/proxy.lua
+++ /dev/null
@@ -1,44 +0,0 @@
--- 解码URL函数
-local function decode_uri(uri)
- ngx.log(ngx.DEBUG, "decode_uri 输入: ", uri)
- local decoded = ngx.unescape_uri(uri)
- ngx.log(ngx.DEBUG, "decode_uri 输出: ", decoded)
- return decoded
-end
-
--- 直接从请求URI获取完整URL
-local request_uri = ngx.var.request_uri
-ngx.log(ngx.DEBUG, "完整请求URI: ", request_uri)
-
--- 提取/proxy/后面的部分
-local _, _, target_path = string.find(request_uri, "^/proxy/(.*)")
-ngx.log(ngx.DEBUG, "提取的目标路径: ", target_path or "nil")
-
-if not target_path or target_path == "" then
- ngx.log(ngx.ERR, "未提供目标URL,返回400")
- ngx.status = 400
- ngx.say("错误: 未提供目标URL")
- return ngx.exit(400)
-end
-
--- 解码URL
-local target_url = decode_uri(target_path)
-ngx.log(ngx.DEBUG, "解码后的目标URL: ", target_url)
-
-if not target_url or target_url == "" then
- ngx.log(ngx.ERR, "无法解析目标URL,返回400")
- ngx.status = 400
- ngx.say("错误: 无法解析目标URL")
- return ngx.exit(400)
-end
-
--- 记录日志
-ngx.log(ngx.STDERR, "代理请求: ", target_url)
-
--- 设置目标URL变量供Nginx使用
-ngx.var.target_url = target_url
-
-ngx.log(ngx.DEBUG, "已设置 ngx.var.target_url: ", ngx.var.target_url)
-
--- 继续执行Nginx配置的其余部分
-return
\ No newline at end of file
diff --git a/readme.md b/readme.md
index d0ed8a4..fa049cd 100644
--- a/readme.md
+++ b/readme.md
@@ -26,8 +26,8 @@ LibreTV 是一个轻量级、免费的在线视频搜索与观看平台,提供
选择以下任一平台,点击一键部署按钮,即可快速创建自己的 LibreTV 实例:
-[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FLibreSpark%2FLibreTV) [![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/LibreSpark/LibreTV)
-
+[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FLibreSpark%2FLibreTV)
+[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/LibreSpark/LibreTV)
[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/LibreSpark/LibreTV)
## ⚠️ 安全与隐私提醒
@@ -42,7 +42,7 @@ LibreTV 是一个轻量级、免费的在线视频搜索与观看平台,提供
### 📝 部署建议
-1. **、设置环境变量 `PASSWORD`**:为您的实例设置一个强密码
+1. **设置环境变量 `PASSWORD`**:为您的实例设置一个强密码
2. **仅供个人使用**:请勿将您的实例链接公开分享或传播
3. **遵守当地法律**:请确保您的使用行为符合当地法律法规
@@ -106,15 +106,14 @@ docker run -d \
`docker-compose.yml` 文件:
```yaml
-version: '3'
services:
libretv:
image: bestzwei/libretv:latest
container_name: libretv
ports:
- - "8899:80"
+ - "8899:8080"
environment:
- - PASSWORD=111111
+ - PASSWORD=${PASSWORD:-111111}
restart: unless-stopped
```