Commit bc1aa5e0 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

refactor(deploy): 将环境变量从 inventory 移至 Makefile 参数

parent 63a3c66e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ TeamCity 中推荐直接调用 `make`(仓库根目录的 `Makefile` 会转发
```bash
set -e

export ENV=p368
export IMAGE_TAG=test
export BUILD_NUMBER=100000
export HARBOR_PROJECT=harbor.csst.nao:10443/csst/
+10 −5
Original line number Diff line number Diff line
@@ -13,6 +13,11 @@ TARGET_API_GATEWAY := $(HARBOR_PROJECT)csst-airflow-api-gateway:$(IMAGE_TAG)
TARGET_TASK_PORTAL := $(HARBOR_PROJECT)csst-airflow-task-portal:$(IMAGE_TAG)
TARGET_JS9 := $(HARBOR_PROJECT)csst-airflow-js9:$(IMAGE_TAG)

ANSIBLE_EXTRA_VARS := -e env=$(ENV) -e image_tag=$(IMAGE_TAG)
ifneq ($(strip $(HARBOR_PROJECT)),)
ANSIBLE_EXTRA_VARS += -e harbor_project=$(HARBOR_PROJECT)
endif

help:
	@echo "======================================================================"
	@echo "		 CSST Airflow Operations & Delivery		   "
@@ -130,27 +135,27 @@ update-code:
ansible-deploy:
	@if [ -z "$(ENV)" ]; then echo "Error: ENV is not set. Usage: make ansible-deploy ENV=p368"; exit 1; fi
	@if [ ! -f "deploy_configs/$(ENV)/inventory.ini" ]; then echo "Error: deploy_configs/$(ENV)/inventory.ini not found"; exit 1; fi
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/deploy.yml -e env=$(ENV)
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/deploy.yml $(ANSIBLE_EXTRA_VARS)

ansible-update:
	@if [ -z "$(ENV)" ]; then echo "Error: ENV is not set. Usage: make ansible-update ENV=p368"; exit 1; fi
	@if [ ! -f "deploy_configs/$(ENV)/inventory.ini" ]; then echo "Error: deploy_configs/$(ENV)/inventory.ini not found"; exit 1; fi
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/update.yml -e env=$(ENV)
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/update.yml $(ANSIBLE_EXTRA_VARS)

ansible-down:
	@if [ -z "$(ENV)" ]; then echo "Error: ENV is not set. Usage: make ansible-down ENV=p368"; exit 1; fi
	@if [ ! -f "deploy_configs/$(ENV)/inventory.ini" ]; then echo "Error: deploy_configs/$(ENV)/inventory.ini not found"; exit 1; fi
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/down.yml -e env=$(ENV)
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/down.yml $(ANSIBLE_EXTRA_VARS)

ansible-check:
	@if [ -z "$(ENV)" ]; then echo "Error: ENV is not set. Usage: make ansible-check ENV=p368"; exit 1; fi
	@if [ ! -f "deploy_configs/$(ENV)/inventory.ini" ]; then echo "Error: deploy_configs/$(ENV)/inventory.ini not found"; exit 1; fi
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/check.yml -e env=$(ENV)
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/check.yml $(ANSIBLE_EXTRA_VARS)

ansible-sync-dags:
	@if [ -z "$(ENV)" ]; then echo "Error: ENV is not set. Usage: make ansible-sync-dags ENV=p368"; exit 1; fi
	@if [ ! -f "deploy_configs/$(ENV)/inventory.ini" ]; then echo "Error: deploy_configs/$(ENV)/inventory.ini not found"; exit 1; fi
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/sync_dags.yml -e env=$(ENV)
	ansible-playbook -i deploy_configs/$(ENV)/inventory.ini ansible/sync_dags.yml $(ANSIBLE_EXTRA_VARS)

pull:
	@total=$$(grep -v '^#' $(REQ_FILE) | grep -v '^$$' | wc -l); \
+0 −10
Original line number Diff line number Diff line
@@ -8,18 +8,8 @@ csu-master ansible_host=192.168.25.18 ansible_user=root
# e.g., csu-worker2 ansible_host=192.168.25.20 ansible_user=root deploy_dir=/opt/csst-airflow-worker2 worker_concurrency=32

[all:vars]
# The environment name to deploy (e.g., p368, csu, zjlab)
# This dictates which .env file is used
env=csu

# The destination directory on remote nodes where the project will be deployed
deploy_dir=/opt/csst-airflow

# 镜像仓库前缀 (例如 csu-harbor.csst.nao:10443/csst/),为空则代表不使用私有仓库而直接使用公网/本地镜像
harbor_project=csu-harbor.csst.nao:10443/csst/

# 业务镜像版本
image_tag=latest

# API Gateway 与 Airflow Webserver 通信所用的 JWT 密钥 (各环境可独立生成以保证安全)
jwt_secret=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhaXJmbG93IiwiaWF0IjoxNzU1NDQ3NjMxLCJleHAiOjE3ODY5ODM2MzF9.CbxQayEt370iHhvYXhHMESsk1IWmi8QLMOcctIlbicXhybNtBbfboDUdUDMClwvkSuTjC0AOeSHL23pGyy0plQ
+5 −10
Original line number Diff line number Diff line
[master]
# Because we are testing on the local p368 machine itself, use ansible_connection=local
# ansible_connection options (common):
# - local: run on the same machine as the controller (no SSH)
# - ssh (default): remote SSH connection (omit ansible_connection to use default)
# - paramiko: SSH via Paramiko (fallback when system SSH is unavailable)
# - docker: connect to a local Docker container (less common in this repo)
p368-master ansible_host=10.73.0.27 ansible_connection=local

[worker]
@@ -7,21 +11,12 @@ p368-master ansible_host=10.73.0.27 ansible_connection=local
p368-worker1 ansible_host=10.73.0.27 ansible_connection=local worker_concurrency=16

[all:vars]
# The environment name to deploy (e.g., p368, csu, zjlab)
# This dictates which .env file is used
env=p368

# The destination directory on remote nodes where the project will be deployed
deploy_dir=/opt/csst-airflow

# 镜像仓库前缀 (例如 csu-harbor.csst.nao:10443/csst/),为空则代表不使用私有仓库而直接使用公网/本地镜像
harbor_project=harbor.csst.nao:10443/csst/

# 是否在 update 过程中强制从镜像仓库 pull(本机测试/离线环境建议 false)
registry_pull=false

# 业务镜像版本
image_tag=test

# API Gateway 与 Airflow Webserver 通信所用的 JWT 密钥 (各环境可独立生成以保证安全)
jwt_secret=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhaXJmbG93IiwiaWF0IjoxNzU1NDQ3NjMxLCJleHAiOjE3ODY5ODM2MzF9.CbxQayEt370iHhvYXhHMESsk1IWmi8QLMOcctIlbicXhybNtBbfboDUdUDMClwvkSuTjC0AOeSHL23pGyy0plQ
+0 −10
Original line number Diff line number Diff line
@@ -8,18 +8,8 @@ zjlab-master ansible_host=10.200.60.244 ansible_user=root
# e.g., zjlab-worker2 ansible_host=10.200.60.246 ansible_user=root deploy_dir=/opt/csst-airflow-worker2 worker_concurrency=32

[all:vars]
# The environment name to deploy (e.g., p368, csu, zjlab)
# This dictates which .env file is used
env=zjlab

# The destination directory on remote nodes where the project will be deployed
deploy_dir=/opt/csst-airflow

# 镜像仓库前缀 (例如 zjlab-harbor.csst.ac.cn:10443/my-project/),为空则代表不使用私有仓库而直接使用公网/本地镜像
harbor_project=zjlab-harbor.csst.ac.cn:10443/my-project/

# 业务镜像版本
image_tag=latest

# API Gateway 与 Airflow Webserver 通信所用的 JWT 密钥 (各环境可独立生成以保证安全)
jwt_secret=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhaXJmbG93IiwiaWF0IjoxNzU1NDQ3NjMxLCJleHAiOjE3ODY5ODM2MzF9.CbxQayEt370iHhvYXhHMESsk1IWmi8QLMOcctIlbicXhybNtBbfboDUdUDMClwvkSuTjC0AOeSHL23pGyy0plQ