Route preview API through Docker network
Verify mini program and deploy preview / verify-deploy (push) Successful in 23s
Verify mini program and deploy preview / verify-deploy (push) Successful in 23s
This commit is contained in:
@@ -16,7 +16,7 @@ jobs:
|
||||
SOURCE_REPOSITORY: ${{ gitea.repository }}
|
||||
SOURCE_REVISION: ${{ gitea.sha }}
|
||||
DEPLOY_PORT: ${{ vars.DEPLOY_PORT || '3002' }}
|
||||
API_BASE_URL: ${{ vars.API_BASE_URL || 'http://47.83.180.156:18082' }}
|
||||
API_BASE_URL: ${{ vars.API_BASE_URL }}
|
||||
steps:
|
||||
- name: Fetch exact revision
|
||||
env: { SOURCE_TOKEN: "${{ secrets.GITEA_TOKEN || gitea.token }}" }
|
||||
@@ -41,8 +41,9 @@ jobs:
|
||||
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
||||
run: |
|
||||
set -eu
|
||||
docker network inspect pk-lab-public >/dev/null 2>&1 || docker network create pk-lab-public
|
||||
docker rm -f rice-pk-xhs-preview 2>/dev/null || true
|
||||
docker run -d --name rice-pk-xhs-preview --restart unless-stopped --read-only --tmpfs /tmp --tmpfs /var/cache/nginx --tmpfs /var/run -e API_BASE_URL="$API_BASE_URL" -p "$DEPLOY_PORT:8080" "rice-pk-xhs:$SOURCE_REVISION"
|
||||
docker run -d --name rice-pk-xhs-preview --restart unless-stopped --network pk-lab-public --read-only --tmpfs /tmp --tmpfs /var/cache/nginx --tmpfs /var/run -e API_BASE_URL="$API_BASE_URL" -p "$DEPLOY_PORT:8080" "rice-pk-xhs:$SOURCE_REVISION"
|
||||
for i in 1 2 3 4 5 6 7 8 9 10; do
|
||||
status="$(docker inspect --format '{{.State.Health.Status}}' rice-pk-xhs-preview)"
|
||||
[ "$status" = healthy ] && exit 0
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
FROM nginx:1.27-alpine
|
||||
COPY web /usr/share/nginx/html
|
||||
RUN printf 'server { listen 8080; server_name _; root /usr/share/nginx/html; location = /runtime-env.js { alias /tmp/runtime-env.js; } location / { try_files $uri $uri/ /index.html; } location = /health { access_log off; return 200 "ok\\n"; add_header Content-Type text/plain; } }' > /etc/nginx/conf.d/default.conf
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 8080
|
||||
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=5 CMD wget -q -O- http://127.0.0.1:8080/health || exit 1
|
||||
CMD ["/bin/sh","-c","envsubst '$API_BASE_URL' < /usr/share/nginx/html/runtime-env.js > /tmp/runtime-env.js && exec nginx -g 'daemon off;'"]
|
||||
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
|
||||
只开放 `rice` 测试的原生小红书小程序。打开即进入饭类主题,可重复测试、查看自己的饭类历史、输入综合版生成的一次性绑定码,并生成三种风格的分享图。
|
||||
|
||||
将 `app.js` 的 `apiBase` 改成生产 HTTPS API,在小红书后台配置合法域名并绑定独立版 App ID。CI 默认把公网功能预览常驻部署到宿主机 `3002`;仓库变量 `DEPLOY_PORT`、`API_BASE_URL` 可覆盖。
|
||||
|
||||
将 `app.js` 的 `apiBase` 改成生产 HTTPS API,在小红书后台配置合法域名并绑定独立版 App ID。CI 默认把公网功能预览常驻部署到宿主机 `3002`,并加入 `pk-lab-public` Docker 网络;浏览器同源请求 `/api`,由 Nginx 转发到 `pk-lab-api:8000`。`DEPLOY_PORT` 可覆盖,只有跨域部署时才需设置可选的 `API_BASE_URL`。
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
server {
|
||||
listen 8080;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
location = /runtime-env.js {
|
||||
alias /tmp/runtime-env.js;
|
||||
add_header Cache-Control "no-store";
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||
set $api_upstream http://pk-lab-api:8000;
|
||||
proxy_pass $api_upstream;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location = /health {
|
||||
access_log off;
|
||||
return 200 "ok\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user