diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..b7f006f --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,57 @@ +name: Build and Deploy TenantUI + +on: + push: + branches: + - main + +jobs: + build-and-deploy: + runs-on: host + steps: + - name: Checkout code + run: | + set -e + cd /opt/deploy/tenantui || mkdir -p /opt/deploy/tenantui + cd /opt/deploy/tenantui + + # 如果已有仓库就 pull,否则 clone + if [ -d ".git" ]; then + git fetch origin main + git reset --hard origin/main + git clean -fd + else + git clone --branch main ssh://git@git.laosankeji.com:2222/msumshk/TakeoutSaaS.TenantUI.git . + fi + + - name: Build on host + run: | + set -e + cd /opt/deploy/tenantui + corepack enable + pnpm install --frozen-lockfile + VITE_GLOB_API_URL=https://api-tenant-dev.laosankeji.com/api/tenant/v1 pnpm run build:antd + + rm -rf publish/web-antd-dist + mkdir -p publish + cp -r apps/web-antd/dist publish/web-antd-dist + + - name: Build Docker image + run: | + set -e + cd /opt/deploy/tenantui + docker build -t takeoutsaas-tenantui:latest -f scripts/deploy/Dockerfile.runtime . + + - name: Deploy container + run: | + docker stop tenantui || true + docker rm tenantui || true + docker run -d \ + --name tenantui \ + --restart unless-stopped \ + -p 8010:8080 \ + takeoutsaas-tenantui:latest + + - name: Clean up old images + run: | + docker image prune -f diff --git a/scripts/deploy/Dockerfile.runtime b/scripts/deploy/Dockerfile.runtime new file mode 100644 index 0000000..f7c169e --- /dev/null +++ b/scripts/deploy/Dockerfile.runtime @@ -0,0 +1,16 @@ +FROM nginx:stable-alpine AS runtime + +# 配置 nginx +RUN echo "types { application/javascript js mjs; }" > /etc/nginx/conf.d/mjs.conf \ + && rm -rf /etc/nginx/conf.d/default.conf + +# 复制宿主机构建产物 +COPY publish/web-antd-dist /usr/share/nginx/html + +# 复制 nginx 配置 +COPY scripts/deploy/nginx.conf /etc/nginx/nginx.conf + +EXPOSE 8080 + +# 启动 nginx +CMD ["nginx", "-g", "daemon off;"]