来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
71 lines
2.2 KiB
YAML
71 lines
2.2 KiB
YAML
---
|
|
# Artifact on Semaphore host: /artifacts/backend-deploy.tar.gz
|
|
# Same layout as scripts/deploy-prod-*.ps1 backend tar (dist/, package.json, migrations/, …).
|
|
- name: Deploy backend artifact
|
|
hosts: backend
|
|
gather_facts: false
|
|
become: true
|
|
become_user: ubuntu
|
|
vars:
|
|
artifact_local: /artifacts/backend-deploy.tar.gz
|
|
staging: /home/ubuntu/deploy-staging
|
|
tasks:
|
|
- name: Ensure artifact exists on controller
|
|
ansible.builtin.stat:
|
|
path: "{{ artifact_local }}"
|
|
delegate_to: localhost
|
|
become: false
|
|
register: art
|
|
|
|
- name: Fail if missing artifact
|
|
ansible.builtin.fail:
|
|
msg: "缺少 /artifacts/backend-deploy.tar.gz。请先 scp 构建产物到 Semaphore 机后再跑本任务。"
|
|
when: not art.stat.exists
|
|
run_once: true
|
|
|
|
- name: Prepare staging dir
|
|
ansible.builtin.file:
|
|
path: "{{ staging }}"
|
|
state: directory
|
|
owner: ubuntu
|
|
group: ubuntu
|
|
mode: "0755"
|
|
|
|
- name: Upload artifact
|
|
ansible.builtin.copy:
|
|
src: "{{ artifact_local }}"
|
|
dest: "{{ staging }}/backend-deploy.tar.gz"
|
|
owner: ubuntu
|
|
group: ubuntu
|
|
mode: "0644"
|
|
|
|
- name: Unpack into deploy-staging
|
|
ansible.builtin.shell: |
|
|
set -euo pipefail
|
|
cd {{ staging }}
|
|
rm -rf dist package.json data migrations scripts deploy llm.env.snippet
|
|
tar -xzf backend-deploy.tar.gz
|
|
# tar may place files at top-level or nested; normalize common layouts
|
|
if [ ! -d dist ] && [ -d server/dist ]; then
|
|
mv server/dist dist
|
|
mv server/package.json package.json 2>/dev/null || true
|
|
mv server/data data 2>/dev/null || true
|
|
fi
|
|
test -d dist
|
|
args:
|
|
executable: /bin/bash
|
|
|
|
- name: Set migrate flag (primary only)
|
|
ansible.builtin.set_fact:
|
|
skip_migrate: "{{ '0' if inventory_hostname == 'test-api' else '1' }}"
|
|
|
|
- name: Apply backend
|
|
ansible.builtin.shell: |
|
|
set -euo pipefail
|
|
export SKIP_DB_MIGRATE={{ skip_migrate }}
|
|
bash /opt/ai-fresh-delivery/scripts/prod-apply-backend.sh
|
|
args:
|
|
executable: /bin/bash
|
|
environment:
|
|
HOME: /home/ubuntu
|