From cdebd0a4045386a573fad9d8d3b62658330fa4be Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 20 Oct 2026 17:49:03 +0800 Subject: [PATCH] fix(ci): deploy olons server from managed compose env --- .gitea/workflows/deploy.yml | 57 +++++----------------------------- tests/test_actions_workflow.py | 18 ++++++++--- 2 files changed, 21 insertions(+), 54 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 92b9fea..cfa2c6b 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -67,58 +67,15 @@ jobs: ssh "${SSH_ARGS[@]}" "$DEPLOY_USER@$DEPLOY_HOST" ' set -euo pipefail cd /opt/olns - base_file="" - for candidate in compose.yaml compose.yml docker-compose.yaml docker-compose.yml; do - if [ -f "$candidate" ]; then - base_file="$candidate" - break - fi - done - test -n "$base_file" - - im_container="$(docker compose -f "$base_file" ps -q im-server)" - test -n "$im_container" - internal_secret="$(docker inspect "$im_container" --format '"'"'{{range .Config.Env}}{{println .}}{{end}}'"'"' | sed -n '"'"'s/^INTERNAL_API_HOTGO_SECRET=//p'"'"' | head -n 1)" - test -n "$internal_secret" - - olons_container="$(docker compose -f "$base_file" ps -q olons-server)" - if [ -n "$olons_container" ]; then - docker logs "$olons_container" --since 30m 2>&1 | grep "customer service session failed" | tail -n 20 || true - fi - - umask 077 - { - printf "OLONS_IM_INTERNAL_SECRET=%s\n" "$internal_secret" - printf "OLONS_IM_BASE_URL=http://im-server:6060\n" - printf "OLONS_IM_HTTP_API_URL=http://im-server:6060/v1/im\n" - printf "OLONS_IM_WS_URL=ws://im-server:6060/v0/channels\n" - printf "OLONS_IM_FILE_URL=http://im-server:6060/v0/file\n" - printf "OLONS_IM_TENANT_CODE=default\n" - printf "OLONS_IM_API_KEY=AQAAAAABAAAnbYhUP5GAkexs5qlwQ8fR\n" - printf "OLONS_IM_INTERNAL_SERVICE=olons-server\n" - } > .env.olons-server - cat > compose.olons-server-secret.yaml <<"YAML" - services: - olons-server: - environment: - OLONS_IM_INTERNAL_SECRET: ${OLONS_IM_INTERNAL_SECRET} - OLONS_IM_BASE_URL: ${OLONS_IM_BASE_URL} - OLONS_IM_HTTP_API_URL: ${OLONS_IM_HTTP_API_URL} - OLONS_IM_WS_URL: ${OLONS_IM_WS_URL} - OLONS_IM_FILE_URL: ${OLONS_IM_FILE_URL} - OLONS_IM_TENANT_CODE: ${OLONS_IM_TENANT_CODE} - OLONS_IM_API_KEY: ${OLONS_IM_API_KEY} - OLONS_IM_INTERNAL_SERVICE: ${OLONS_IM_INTERNAL_SERVICE} - YAML - - set -a - . ./.env.olons-server - set +a - docker compose -f "$base_file" -f compose.olons-server-secret.yaml pull olons-server - docker compose -f "$base_file" -f compose.olons-server-secret.yaml up -d --no-deps --wait olons-server - docker compose -f "$base_file" -f compose.olons-server-secret.yaml exec -T olons-server sh -c '"'"' + docker compose pull olons-server + docker compose up -d --no-deps --wait olons-server + docker compose exec -T olons-server sh -c '"'"' test -n "$OLONS_IM_INTERNAL_SECRET" + test "$OLONS_IM_TENANT_CODE" = "default" + test "$OLONS_SERVER_DEFAULT_TENANT_ID" = "0" test "$OLONS_IM_BASE_URL" = "http://im-server:6060" test "$OLONS_IM_HTTP_API_URL" = "http://im-server:6060/v1/im" + test "$OLONS_IM_WS_URL" = "ws://im-server:6060/v0/channels" + test "$OLONS_IM_FILE_URL" = "http://im-server:6060/v0/file" '"'"' ' diff --git a/tests/test_actions_workflow.py b/tests/test_actions_workflow.py index 22b950d..15f4c16 100644 --- a/tests/test_actions_workflow.py +++ b/tests/test_actions_workflow.py @@ -35,12 +35,22 @@ class DeployWorkflowContractTest(unittest.TestCase): self.assertNotIn("git.118im.com", self.workflow) def test_uses_internal_im_endpoints_for_server_calls(self): - self.assertIn("OLONS_IM_BASE_URL=http://im-server:6060", self.workflow) - self.assertIn("OLONS_IM_HTTP_API_URL=http://im-server:6060/v1/im", self.workflow) - self.assertIn("OLONS_IM_WS_URL=ws://im-server:6060/v0/channels", self.workflow) - self.assertIn("OLONS_IM_FILE_URL=http://im-server:6060/v0/file", self.workflow) + self.assertIn('"$OLONS_IM_BASE_URL" = "http://im-server:6060"', self.workflow) + self.assertIn('"$OLONS_IM_HTTP_API_URL" = "http://im-server:6060/v1/im"', self.workflow) + self.assertIn('"$OLONS_IM_WS_URL" = "ws://im-server:6060/v0/channels"', self.workflow) + self.assertIn('"$OLONS_IM_FILE_URL" = "http://im-server:6060/v0/file"', self.workflow) self.assertNotIn("OLONS_IM_BASE_URL=https://im-api.yuexuan.shop", self.workflow) + def test_deploy_uses_managed_compose_environment_without_secret_overlay(self): + self.assertNotIn(".env.olons-server", self.workflow) + self.assertNotIn("compose.olons-server-secret.yaml", self.workflow) + self.assertNotIn("INTERNAL_API_HOTGO_SECRET", self.workflow) + self.assertNotIn("OLONS_IM_API_KEY=", self.workflow) + self.assertIn("docker compose pull olons-server", self.workflow) + self.assertIn("docker compose up -d --no-deps --wait olons-server", self.workflow) + self.assertIn('test "$OLONS_IM_TENANT_CODE" = "default"', self.workflow) + self.assertIn('test "$OLONS_SERVER_DEFAULT_TENANT_ID" = "0"', self.workflow) + if __name__ == "__main__": unittest.main()