Compare commits
5
Commits
c64d5a96cb
...
3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe774dc5d6 | ||
|
|
7d601393d1 | ||
|
|
92f110c5e1 | ||
|
|
4e2c837eee | ||
|
|
c18893e6f3 |
+32
-4
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
FROM nginx:alpine
|
||||
COPY dist /usr/share/nginx/html
|
||||
Reference in New Issue
Block a user