Compare commits

5 Commits
Author SHA1 Message Date
xrain fe774dc5d6 增加 useHash 配置:hash 路由不注入 nginx.conf 2026-10-20 21:49:53 +08:00
xrain 7d601393d1 支持构建目录 context,构建改用 docker-build-push 2026-10-20 21:45:48 +08:00
xrain 92f110c5e1 如果仓库有nginx.conf就用仓库的 2026-10-06 04:24:46 +08:00
xrain 4e2c837eee fix ci 2026-10-04 23:13:05 +08:00
xrain c18893e6f3 nginx增加了允许跨域 2026-05-04 18:00:58 +08:00
3 changed files with 46 additions and 4 deletions
+32 -4
View File
@@ -1,6 +1,15 @@
# action.yml
name: "build docker image and push to code"
description: "build docker image and push to simcu code"
inputs:
context:
description: "构建目录(相对仓库根目录,默认 .)。例如前端在 vue 目录下时填 vue"
required: false
default: "."
useHash:
description: "前端是否使用 hash 路由(默认 false)。false:用 nginx.conf 做 history 回退并加跨域头;true:用 nginx 默认配置,不再注入 nginx.conf"
required: false
default: "false"
runs:
using: "composite"
steps:
@@ -8,16 +17,35 @@ runs:
with:
entrypoint: "/bin/bash"
args: |
-c "export https_proxy=http://100.100.13.14:8118 && \
export http_proxy=http://100.100.13.14:8118 && \
-c 'cd "${{ inputs.context }}" && \
npm pkg set version=${{ github.ref_name }} && \
npm ci && \
npm run build-only"
npm run build-only'
# Dockerfile 放在仓库根目录(docker build -f 是相对仓库根目录解析的)。
# useHash=false:用 vue.Dockerfile,带上 nginx.conf 做 history 回退(构建目录有 nginx.conf 就用项目自己的);
# useHash=true :hash 路由不需要回退,用 vue-hash.Dockerfile + nginx 默认配置,不注入 nginx.conf
- uses: docker://ubuntu:latest
with:
entrypoint: "/bin/bash"
args: |
-c 'cp "${{ github.action_path }}/nginx.conf" ./ && cp "${{ github.action_path }}/vue.Dockerfile" ./Dockerfile'
-c '
set -e
if [ "${{ inputs.useHash }}" = "true" ]; then
cp "${{ github.action_path }}/vue-hash.Dockerfile" ./Dockerfile
echo "useHash=true:用 nginx 默认配置,不注入 nginx.conf"
else
cp "${{ github.action_path }}/vue.Dockerfile" ./Dockerfile
cd "${{ inputs.context }}"
if [ -f ./nginx.conf ]; then
echo "nginx.conf:用项目自带的"
else
cp "${{ github.action_path }}/nginx.conf" ./nginx.conf
echo "nginx.conf:用 action 内置的"
fi
fi
'
- uses: actions/docker-build-push@main
with:
context: ${{ inputs.context }}
+12
View File
@@ -3,6 +3,18 @@ server {
root /usr/share/nginx/html;
index index.html;
# 👇 跨域配置开始
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE' always;
add_header Access-Control-Allow-Headers '*, Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Token' always;
add_header Access-Control-Allow-Credentials 'true' always;
# 处理预检 OPTIONS 请求
if ($request_method = 'OPTIONS') {
return 204;
}
# 👆 跨域配置结束
location / {
try_files $uri $uri/ /index.html;
}
+2
View File
@@ -0,0 +1,2 @@
FROM nginx:alpine
COPY dist /usr/share/nginx/html