一分钟搭建影视站,支持Docker等部署方式
test: feat: add Docker workflow for build and push, update Dockerfile for OpenResty, enhance entrypoint script, and configure Nginx for API proxy
developer647aabd1e4a3
diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.ymlnew file mode 100644index 0000000..8ffe3c5--- /dev/null+++ b/.github/workflows/docker-publish.yml@@ -0,0 +1,52 @@+name: Docker Build and Push++on:+ push:+ branches: [ main, master ]+ tags: [ 'v*' ]+ pull_request:+ branches: [ main, master ]++jobs:+ build:+ runs-on: ubuntu-latest+ steps:+ - name: Checkout repository+ uses: actions/checkout@v3++ - name: Set up QEMU+ uses: docker/setup-qemu-action@v2++ - name: Set up Docker Buildx+ uses: docker/setup-buildx-action@v2++ - name: Login to DockerHub+ if: github.event_name != 'pull_request'+ uses: docker/login-action@v2+ with:+ username: ${{ secrets.DOCKERHUB_USERNAME }}+ password: ${{ secrets.DOCKERHUB_TOKEN }}++ - name: Extract metadata for Docker+ id: meta+ uses: docker/metadata-action@v4+ with:+ images: bestzwei/libretv+ tags: |+ type=ref,event=branch+ type=ref,event=pr+ type=semver,pattern={{version}}+ type=semver,pattern={{major}}.{{minor}}+ type=sha,format=long+ latest++ - name: Build and push+ uses: docker/build-push-action@v4+ with:+ context: .+ platforms: linux/amd64,linux/arm64/v8+ push: ${{ github.event_name != 'pull_request' }}+ tags: ${{ steps.meta.outputs.tags }}+ labels: ${{ steps.meta.outputs.labels }}+ cache-from: type=registry,ref=bestzwei/libretv:buildcache+ cache-to: type=registry,ref=bestzwei/libretv:buildcache,mode=maxdiff --git a/Dockerfile b/Dockerfileindex bab077f..34992b7 100644--- a/Dockerfile+++ b/Dockerfile@@ -1,14 +1,21 @@-FROM openresty/openresty:alpine-fat+# 使用指定的基础镜像,支持 amd64 和 arm64/v8 架构+FROM fabiocicerchia/nginx-lua:1.27.5-alpine3.21.3LABEL maintainer="LibreTV Team"LABEL description="LibreTV - 免费在线视频搜索与观看平台"-# 复制应用文件-COPY . /usr/share/nginx/html+# 安装必要的工具+RUN apk add --no-cache curl-# 复制Nginx配置文件+# 复制网站文件+COPY . /usr/share/nginx/html/++# 设置工作目录+WORKDIR /usr/share/nginx/html++# 复制自定义 nginx 配置COPY nginx.conf /etc/nginx/conf.d/default.conf-# 添加执行权限并设置为入口点脚本+# 复制并设置入口点脚本权限COPY docker-entrypoint.sh /RUN chmod +x /docker-entrypoint.sh@@ -18,8 +25,8 @@ EXPOSE 80# 设置入口点ENTRYPOINT ["/docker-entrypoint.sh"]-# 启动 OpenResty (Nginx + Lua)-CMD ["openresty", "-g", "daemon off;"]+# 启动命令+CMD ["nginx", "-g", "daemon off;"]# 健康检查HEALTHCHECK --interval=30s --timeout=3s CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1\ No newline at end of filediff --git a/docker-compose.yml b/docker-compose.ymlindex fa042ae..4b89971 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -2,15 +2,17 @@ version: '3'services:libretv:- build:- context: .- dockerfile: Dockerfile+ image: bestzwei/libretv:latest+ container_name: libretvports:- "8899:80"environment:- - PASSWORD=your_password_here # 设置密码保护,留空则不启用密码- # 可以添加其他环境变量+ - PASSWORD=111111 # 设置密码保护,留空则不启用密码+ # - PROXY_API=true # 启用内部API代理,解决跨域问题restart: unless-stopped- # 如果您想使用外部卷存储数据# volumes:- # - ./data:/usr/share/nginx/html/data\ No newline at end of file+ # - ./data:/usr/share/nginx/html/data+ # 如果希望使用构建模式而非拉取镜像+ # build:+ # context: .+ # dockerfile: Dockerfile\ No newline at end of filediff --git a/docker-entrypoint.sh b/docker-entrypoint.shindex 227e18d..2fa3118 100644--- a/docker-entrypoint.sh+++ b/docker-entrypoint.sh@@ -6,6 +6,11 @@ replace_env_vars() {# Replace the password placeholder in all HTML filesfind /usr/share/nginx/html -type f -name "*.html" -exec sed -i "s/window.__ENV__.PASSWORD = \"{{PASSWORD}}\";/window.__ENV__.PASSWORD = \"${PASSWORD:-}\";/g" {} \;+ # Add proxy API environment variable if needed+ if [ -n "$PROXY_API" ]; then+ find /usr/share/nginx/html -type f -name "*.html" -exec sed -i "s/window.__ENV__.PROXY_API = false;/window.__ENV__.PROXY_API = true;/g" {} \;+ fi+echo "Environment variables have been injected into HTML files."}diff --git a/nginx.conf b/nginx.confindex 0f568b8..eb2ab33 100644--- a/nginx.conf+++ b/nginx.conf@@ -1,6 +1,8 @@server {listen 80;server_name localhost;+ root /usr/share/nginx/html;+ index index.html index.htm;#access_log /var/log/nginx/host.access.log main;@@ -47,9 +49,66 @@ server {proxy_pass $target_url;}+ # 添加API代理,解决跨域问题+ location /api/ {+ default_type application/json;+ content_by_lua_block {+ local http = require "resty.http"+ local cjson = require "cjson"+ local httpc = http.new()++ -- 获取原始请求的信息+ local method = ngx.req.get_method()+ local args = ngx.req.get_uri_args()+ local target_url = args.url++ if not target_url then+ ngx.status = 400+ ngx.say(cjson.encode({error = "Missing url parameter"}))+ return+ end++ -- 移除url参数,保留其他参数+ args.url = nil++ -- 设置超时+ httpc:set_timeout(5000)++ -- 发送请求+ local res, err = httpc:request_uri(target_url, {+ method = method,+ query = args,+ headers = {+ ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",+ ["Content-Type"] = "application/json"+ }+ })++ if not res then+ ngx.status = 500+ ngx.say(cjson.encode({error = "Failed to request: " .. (err or "unknown error")}))+ return+ end++ -- 返回响应+ ngx.status = res.status+ for k, v in pairs(res.headers) do+ -- 排除一些可能导致问题的头+ if k ~= "Transfer-Encoding" and k ~= "Connection" then+ ngx.header[k] = v+ end+ end+ ngx.say(res.body)+ }+ }++ # 静态文件缓存+ location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {+ expires 7d;+ }+location / {- root /usr/share/nginx/html;- index index.html index.htm;+ try_files $uri $uri/ /index.html;}#error_page 404 /404.html;