fix(ci): deploy olons server from managed compose env
Deploy olons-server production / deploy (push) Successful in 32s

This commit is contained in:
Your Name
2026-10-20 17:49:03 +08:00
parent ba87d70478
commit cdebd0a404
2 changed files with 21 additions and 54 deletions
+7 -50
View File
@@ -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"
'"'"'
'
+14 -4
View File
@@ -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()