Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bfab62

Browse files
committed
Feature/new CLI
1 parent0894079 commit9bfab62

18 files changed

+4799
-1
lines changed

‎.gitignore‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ pids
2828
*.seed
2929
*.pid.lock
3030

31+
# Node artifacts
32+
node_modules/
33+
cli/node_modules/
34+
cli/lib/node_modules/
35+
36+
# TypeScript build output
37+
cli/dist/
38+
cli/**/*.js
39+
cli/**/*.js.map
40+
cli/**/*.d.ts
41+
cli/**/*.d.ts.map
42+
!cli/jest.config.js
43+
3144
# Generated config files (these are created by the sources-generator)
3245
config/pgwatch-postgres/sources.yml
3346
config/pgwatch-prometheus/sources.yml

‎.gitlab-ci.yml‎

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
stages:
2+
-test
3+
4+
cli:smoke:test:
5+
stage:test
6+
image:alpine:3.20
7+
variables:
8+
GIT_STRATEGY:fetch
9+
before_script:
10+
-apk add --no-cache bash curl git docker-cli docker-compose
11+
script:
12+
-bash -n ./postgres_ai
13+
-|
14+
set -euo pipefail
15+
out=$(./postgres_ai help | tr -d "\r")
16+
echo "$out" | grep -q "Postgres AI CLI"
17+
echo "$out" | grep -q "COMMANDS:"
18+
rules:
19+
-if:'$CI_COMMIT_BRANCH'
20+
21+
cli:e2e:dind:
22+
stage:test
23+
image:alpine:3.20
24+
services:
25+
-name:docker:24-dind
26+
command:["--tls=false"]
27+
variables:
28+
DOCKER_HOST:tcp://docker:2375
29+
DOCKER_TLS_CERTDIR:""
30+
GIT_STRATEGY:fetch
31+
before_script:
32+
-apk add --no-cache bash curl git coreutils docker-cli docker-compose openssl
33+
-docker version
34+
script:
35+
-set -euo pipefail
36+
-bash -n ./postgres_ai
37+
-./postgres_ai check || true
38+
-./postgres_ai quickstart --demo -y
39+
-timeout 60 ./postgres_ai status
40+
-timeout 10 ./postgres_ai logs grafana || true
41+
-./postgres_ai config
42+
-./postgres_ai update-config
43+
-./postgres_ai list-instances || true
44+
-./postgres_ai add-key "test_key_123"
45+
-./postgres_ai show-key
46+
-./postgres_ai remove-key
47+
-./postgres_ai generate-grafana-password || true
48+
-./postgres_ai show-grafana-credentials || true
49+
-./postgres_ai add-instance "postgresql://postgres:postgres@target-db:5432/target_database" "ci-demo"
50+
-./postgres_ai test-instance "ci-demo" || true
51+
-printf "y\n" | ./postgres_ai reset sink-postgres
52+
-./postgres_ai restart
53+
-./postgres_ai stop
54+
-./postgres_ai start
55+
-printf "y\n" | ./postgres_ai reset
56+
-./postgres_ai clean
57+
after_script:
58+
-docker ps -a || true
59+
-docker system prune -af || true
60+
rules:
61+
-if:'$CI_COMMIT_BRANCH'
62+
cli:node:smoke:
63+
stage:test
64+
image:node:20-alpine
65+
variables:
66+
GIT_STRATEGY:fetch
67+
before_script:
68+
-corepack enable || true
69+
script:
70+
-node -v && npm -v
71+
-npm --prefix cli install --no-audit --no-fund
72+
-node ./cli/dist/bin/postgres-ai.js --help
73+
-node ./cli/dist/bin/postgres-ai.js mon status --help
74+
-node ./cli/dist/bin/postgres-ai.js mon targets list --help
75+
-npm install -g ./cli
76+
-echo "prefix=$(npm config get prefix)" && echo "PATH=$PATH"
77+
-command -v postgres-ai && postgres-ai --help
78+
-command -v pgai && pgai --help
79+
-rm -f .pgwatch-config
80+
-node ./cli/dist/bin/postgres-ai.js add-key "test_key_1234567890"
81+
-node ./cli/dist/bin/postgres-ai.js show-key | grep -E "\*{2,}|[0-9]{4}$"
82+
-test -f ~/.config/postgresai/config.json
83+
-grep -q 'test_key' ~/.config/postgresai/config.json
84+
-node ./cli/dist/bin/postgres-ai.js remove-key
85+
-if grep -q 'apiKey' ~/.config/postgresai/config.json; then echo 'key not removed' && exit 1; fi
86+
-node ./cli/dist/bin/postgres-ai.js mon targets list | head -n 1 || true
87+
-node ./cli/dist/bin/postgres-ai.js mon targets add 'postgresql://user:pass@host:5432/db' ci-test || true
88+
-node ./cli/dist/bin/postgres-ai.js mon targets remove ci-test || true
89+
rules:
90+
-if:'$CI_COMMIT_BRANCH'
91+
92+
cli:node:e2e:dind:
93+
stage:test
94+
image:node:20-alpine
95+
services:
96+
-name:docker:24-dind
97+
command:["--tls=false"]
98+
variables:
99+
DOCKER_HOST:tcp://docker:2375
100+
DOCKER_TLS_CERTDIR:""
101+
GIT_STRATEGY:fetch
102+
before_script:
103+
-corepack enable || true
104+
-apk add --no-cache bash docker-cli docker-compose openssl postgresql-client
105+
-node -v && npm -v && docker version
106+
-npm --prefix cli install --no-audit --no-fund
107+
script:
108+
-./tests/e2e.cli.sh
109+
after_script:
110+
-docker ps -a || true
111+
rules:
112+
-if:'$CI_COMMIT_BRANCH'
113+
114+
cli:node:full:dind:
115+
stage:test
116+
image:node:20-alpine
117+
services:
118+
-name:docker:24-dind
119+
command:["--tls=false"]
120+
variables:
121+
DOCKER_HOST:tcp://docker:2375
122+
DOCKER_TLS_CERTDIR:""
123+
GIT_STRATEGY:fetch
124+
before_script:
125+
-corepack enable || true
126+
-apk add --no-cache bash git docker-cli docker-compose openssl postgresql-client
127+
-node -v && npm -v && docker version
128+
-npm --prefix cli install --no-audit --no-fund
129+
script:
130+
-echo "=== Testing quickstart (demo mode) ==="
131+
-node ./cli/dist/bin/postgres-ai.js mon quickstart --demo
132+
-sleep 10
133+
-node ./cli/dist/bin/postgres-ai.js mon status
134+
-echo ""
135+
-echo "=== Testing shell command ==="
136+
-echo "SELECT 1;" | node ./cli/dist/bin/postgres-ai.js mon shell target-db || true
137+
-echo ""
138+
-echo "=== Testing complete workflow ==="
139+
-node ./cli/dist/bin/postgres-ai.js mon targets add "postgresql://monitor:monitor_pass@target-db:5432/target_database" demo-test
140+
-node ./cli/dist/bin/postgres-ai.js mon targets list
141+
-node ./cli/dist/bin/postgres-ai.js mon targets test demo-test || true
142+
-node ./cli/dist/bin/postgres-ai.js mon health --wait 120
143+
-node ./cli/dist/bin/postgres-ai.js mon show-grafana-credentials
144+
-echo ""
145+
-echo "=== Cleanup ==="
146+
-node ./cli/dist/bin/postgres-ai.js mon stop
147+
-node ./cli/dist/bin/postgres-ai.js mon clean || true
148+
after_script:
149+
-docker ps -a || true
150+
rules:
151+
-if:'$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^feature\//'
152+
allow_failure:false
153+
154+
cli:node:integration:
155+
stage:test
156+
image:node:20-alpine
157+
variables:
158+
GIT_STRATEGY:fetch
159+
before_script:
160+
-corepack enable || true
161+
-node -v && npm -v
162+
-npm --prefix cli install --no-audit --no-fund
163+
script:
164+
-|
165+
set -euo pipefail
166+
: "${PGAI_API_KEY:?PGAI_API_KEY is required for integration tests}"
167+
BASE_URL="${PGAI_BASE_URL:-https://v2.postgres.ai/api/general/}"
168+
echo "Using BASE_URL=$BASE_URL"
169+
# Placeholder: run CLI help until API-backed commands are implemented
170+
node ./cli/dist/bin/postgres-ai.js --help
171+
rules:
172+
-if:'$PGAI_API_KEY'
173+
174+

‎Formula/postgresai.rb‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# typed: false
2+
# frozen_string_literal: true
3+
4+
classPostgresai <Formula
5+
desc"postgres_ai CLI (Node.js)"
6+
homepage"https://gitlab.com/postgres-ai/postgres_ai"
7+
url"https://registry.npmjs.org/postgresai/-/postgresai-0.11.0-alpha.8.tgz"
8+
sha256""# Will be calculated after publishing to npm
9+
license"Apache-2.0"
10+
11+
depends_on"node"
12+
13+
definstall
14+
system"npm","install", *Language::Node.std_npm_install_args(libexec)
15+
bin.install_symlinkDir["#{libexec}/bin/*"]
16+
end
17+
18+
testdo
19+
assert_matchversion.to_s,shell_output("#{bin}/postgres-ai --version")
20+
assert_match"PostgresAI CLI",shell_output("#{bin}/postgres-ai --help")
21+
assert_matchversion.to_s,shell_output("#{bin}/pgai --version")
22+
end
23+
end
24+

‎README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ Technical URLs (for advanced users):
219219
./postgres_aihelp
220220
```
221221

222+
###Node.js CLI (early preview)
223+
224+
```bash
225+
# run without install
226+
node ./cli/bin/postgres-ai.js --help
227+
228+
# local dev: install aliases into PATH
229+
npm --prefix cli install --no-audit --no-fund
230+
npm link ./cli
231+
postgres-ai --help
232+
pgai --help
233+
234+
# or install globally after publish (planned)
235+
# npm i -g @postgresai/cli
236+
# postgres-ai --help
237+
# pgai --help
238+
```
239+
222240
##🔑 PostgresAI access token
223241
Get your access token at[PostgresAI](https://postgres.ai) for automated report uploads and advanced analysis.
224242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp