Skip to content

Commit 68079fc

Browse files
committed
Merge branch 'claude/fix-quickstart-command-FwS3d' into 'main'
fix(ci): use correct CLI command and run Node.js e2e tests on MRs; remove bash CLI See merge request postgres-ai/postgres_ai!126
2 parents 564527c + dc5906a commit 68079fc

7 files changed

Lines changed: 64 additions & 2302 deletions

File tree

.gitlab-ci.yml

Lines changed: 5 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -94,84 +94,6 @@ reporter:tests:
9494
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
9595
- if: '$CI_COMMIT_BRANCH == "main"'
9696

97-
cli:smoke:test:
98-
stage: test
99-
image: alpine:3.20
100-
variables:
101-
GIT_STRATEGY: fetch
102-
before_script:
103-
- apk add --no-cache bash curl git docker-cli docker-compose
104-
script:
105-
- bash -n ./postgres_ai
106-
- |
107-
set -euo pipefail
108-
out=$(./postgres_ai help | tr -d "\r")
109-
echo "$out" | grep -q "Postgres AI CLI"
110-
echo "$out" | grep -q "COMMANDS:"
111-
rules:
112-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
113-
114-
cli:e2e:dind:
115-
stage: test
116-
image: alpine:3.20
117-
services:
118-
- name: docker:24-dind
119-
command: ["--tls=false"]
120-
needs:
121-
- job: build:test:images
122-
variables:
123-
DOCKER_HOST: tcp://docker:2375
124-
DOCKER_TLS_CERTDIR: ""
125-
DOCKER_API_VERSION: "1.43"
126-
GIT_STRATEGY: fetch
127-
PGAI_TAG: ${CI_COMMIT_REF_SLUG}
128-
before_script:
129-
- apk add --no-cache bash curl git coreutils docker-cli docker-compose openssl
130-
- docker version
131-
# Pull images from GitLab Container Registry
132-
- echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
133-
- |
134-
echo "Pulling images from GitLab Container Registry..."
135-
docker pull "$CI_REGISTRY_IMAGE/postgres-ai-configs:$PGAI_TAG"
136-
docker pull "$CI_REGISTRY_IMAGE/reporter:$PGAI_TAG"
137-
docker pull "$CI_REGISTRY_IMAGE/monitoring-flask-backend:$PGAI_TAG"
138-
echo "Images ready:"
139-
docker images | grep "$CI_REGISTRY_IMAGE"
140-
# Create .env file with registry and tag
141-
- |
142-
cat > .env << EOF
143-
PGAI_REGISTRY=$CI_REGISTRY_IMAGE
144-
PGAI_TAG=$PGAI_TAG
145-
EOF
146-
script:
147-
- set -euo pipefail
148-
- bash -n ./postgres_ai
149-
- ./postgres_ai check || true
150-
- ./postgres_ai quickstart --demo -y
151-
- timeout 60 ./postgres_ai status
152-
- timeout 10 ./postgres_ai logs grafana || true
153-
- ./postgres_ai config
154-
- ./postgres_ai update-config
155-
- ./postgres_ai list-instances || true
156-
- ./postgres_ai add-key "test_key_123"
157-
- ./postgres_ai show-key
158-
- ./postgres_ai remove-key
159-
- ./postgres_ai generate-grafana-password || true
160-
- ./postgres_ai show-grafana-credentials || true
161-
- ./postgres_ai add-instance "postgresql://postgres:postgres@target-db:5432/target_database" "ci-demo"
162-
- ./postgres_ai test-instance "ci-demo" || true
163-
- printf "y\n" | ./postgres_ai reset sink-postgres
164-
- ./postgres_ai restart
165-
- ./postgres_ai stop
166-
- ./postgres_ai start
167-
- printf "y\n" | ./postgres_ai reset
168-
- ./postgres_ai clean
169-
after_script:
170-
- docker ps -a || true
171-
- docker system prune -af || true
172-
rules:
173-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
174-
17597
cli:node:smoke:
17698
stage: test
17799
image: node:20-alpine
@@ -465,10 +387,7 @@ cli:node:e2e:dind:
465387
docker images | grep "$CI_REGISTRY_IMAGE"
466388
# Create .env file with registry and tag
467389
- |
468-
cat > .env << EOF
469-
PGAI_REGISTRY=$CI_REGISTRY_IMAGE
470-
PGAI_TAG=$PGAI_TAG
471-
EOF
390+
printf "%s\n" "PGAI_REGISTRY=$CI_REGISTRY_IMAGE" "PGAI_TAG=$PGAI_TAG" > .env
472391
script:
473392
- ./tests/e2e.cli.sh
474393
after_script:
@@ -509,13 +428,10 @@ cli:node:full:dind:
509428
docker images | grep "$CI_REGISTRY_IMAGE"
510429
# Create .env file with registry and tag
511430
- |
512-
cat > .env << EOF
513-
PGAI_REGISTRY=$CI_REGISTRY_IMAGE
514-
PGAI_TAG=$PGAI_TAG
515-
EOF
431+
printf "%s\n" "PGAI_REGISTRY=$CI_REGISTRY_IMAGE" "PGAI_TAG=$PGAI_TAG" > .env
516432
script:
517-
- echo "=== Testing quickstart (demo mode) ==="
518-
- node ./cli/dist/bin/postgres-ai.js mon quickstart --demo
433+
- echo "=== Testing local-install (demo mode) ==="
434+
- node ./cli/dist/bin/postgres-ai.js mon local-install --demo
519435
- sleep 10
520436
- node ./cli/dist/bin/postgres-ai.js mon status
521437
- echo ""
@@ -535,6 +451,7 @@ cli:node:full:dind:
535451
after_script:
536452
- docker ps -a || true
537453
rules:
454+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
538455
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^feature\//'
539456
allow_failure: false
540457

CONTRIBUTING.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ The demo DB is initialized by `config/target-db/init.sql` and creates the `monit
124124
PGPASSWORD='...' npx postgresai prepare-db postgresql://admin@host:5432/dbname
125125
```
126126

127-
- Add your instance to `instances.yml` (or use the helper CLI: `./postgres_ai add-instance 'postgresql://user:pass@host:port/db' my-db`)
127+
- Add your instance to `instances.yml` (or use the CLI: `postgresai mon targets add 'postgresql://user:pass@host:port/db' my-db`)
128128
- Make sure `is_enabled: true` for that instance.
129129

130130
#### 2) Generate pgwatch sources from `instances.yml`
@@ -296,12 +296,12 @@ make up
296296
make up-local
297297
```
298298

299-
### Option A: Run via the `postgres_ai` script (recommended)
299+
### Option A: Run via the CLI (recommended)
300300

301-
`postgres_ai` uses a single compose file path stored in `COMPOSE_FILE`. You can override it to include the local compose override:
301+
Use the CLI with `COMPOSE_FILE` to include the local compose override:
302302

303303
```bash
304-
COMPOSE_FILE="docker-compose.yml:docker-compose.local.yml" ./postgres_ai quickstart --demo -y
304+
COMPOSE_FILE="docker-compose.yml:docker-compose.local.yml" postgresai mon local-install --demo -y
305305
```
306306

307307
To rebuild on every run:
@@ -310,7 +310,7 @@ To rebuild on every run:
310310
COMPOSE_FILE="docker-compose.yml:docker-compose.local.yml" \
311311
docker compose -f docker-compose.yml -f docker-compose.local.yml build --no-cache
312312

313-
COMPOSE_FILE="docker-compose.yml:docker-compose.local.yml" ./postgres_ai restart
313+
COMPOSE_FILE="docker-compose.yml:docker-compose.local.yml" postgresai mon restart
314314
```
315315

316316
### Option B: Run Docker Compose directly
@@ -333,22 +333,22 @@ docker compose -f docker-compose.yml -f docker-compose.local.yml up -d --force-r
333333
### Reset everything
334334

335335
```bash
336-
./postgres_ai reset
336+
postgresai mon reset
337337
```
338338

339339
### View logs
340340

341341
```bash
342-
./postgres_ai logs
343-
./postgres_ai logs grafana
344-
./postgres_ai logs monitoring_flask_backend
342+
postgresai mon logs
343+
postgresai mon logs grafana
344+
postgresai mon logs monitoring_flask_backend
345345
```
346346

347347
### Stop / start
348348

349349
```bash
350-
./postgres_ai stop
351-
./postgres_ai start
350+
postgresai mon stop
351+
postgresai mon start
352352
```
353353

354354

README.md

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -145,29 +145,29 @@ If you see errors like `permission denied` / `insufficient_privilege` / code `42
145145
npx postgresai prepare-db --print-sql -d mydb
146146
```
147147

148-
**One command setup:**
148+
**Install the CLI:**
149149

150150
```bash
151-
# Download the CLI
152-
curl -o postgres_ai https://gitlab.com/postgres-ai/postgres_ai/-/raw/main/postgres_ai \
153-
&& chmod +x postgres_ai
151+
npm install -g postgresai
154152
```
155153

156-
Now, start it and wait for a few minutes. To obtain a PostgresAI access token for your organization, visit https://console.postgres.ai (`Your org name → Manage → Access tokens`):
154+
**Start monitoring:**
155+
156+
To obtain a PostgresAI access token for your organization, visit https://console.postgres.ai (`Your org name → Manage → Access tokens`):
157157

158158
```bash
159159
# Production setup with your Access token
160-
./postgres_ai quickstart --api-key=your_access_token
160+
postgresai mon local-install --api-key=your_access_token
161161
```
162162
**Note:** You can also add your database instance in the same command:
163163
```bash
164-
./postgres_ai quickstart --api-key=your_access_token --add-instance="postgresql://user:pass@host:port/DB"
164+
postgresai mon local-install --api-key=your_access_token --db-url="postgresql://user:pass@host:port/DB"
165165
```
166166

167167
Or if you want to just check out how it works:
168168
```bash
169169
# Complete setup with demo database
170-
./postgres_ai quickstart --demo
170+
postgresai mon local-install --demo
171171
```
172172

173173
That's it! Everything is installed, configured, and running.
@@ -205,32 +205,32 @@ Failure to secure these ports may expose sensitive database information!
205205
206206
**For developers:**
207207
```bash
208-
./postgres_ai quickstart --demo
208+
postgresai mon local-install --demo
209209
```
210210
Get a complete monitoring setup with demo data in under 2 minutes.
211211
212212
**For production:**
213213
```bash
214-
./postgres_ai quickstart --api-key=your_key
214+
postgresai mon local-install --api-key=your_key
215215
# Then add your databases
216-
./postgres_ai add-instance "postgresql://user:pass@host:port/DB"
216+
postgresai mon targets add "postgresql://user:pass@host:port/DB"
217217
```
218218
219219
## 🔧 Management commands
220220
221221
```bash
222222
# Instance management
223-
./postgres_ai add-instance "postgresql://user:pass@host:port/DB"
224-
./postgres_ai list-instances
225-
./postgres_ai test-instance my-DB
223+
postgresai mon targets add "postgresql://user:pass@host:port/DB"
224+
postgresai mon targets list
225+
postgresai mon targets test my-DB
226226
227-
# Service management
228-
./postgres_ai status
229-
./postgres_ai logs
230-
./postgres_ai restart
227+
# Service management
228+
postgresai mon status
229+
postgresai mon logs
230+
postgresai mon restart
231231
232232
# Health check
233-
./postgres_ai health
233+
postgresai mon health
234234
```
235235
236236
## 📋 Checkup reports
@@ -297,9 +297,9 @@ postgres_ai monitoring generates automated health check reports based on [postgr
297297
298298
## 🌐 Access points
299299
300-
After running quickstart:
300+
After running local-install:
301301
302-
- **🚀 MAIN: Grafana Dashboard**: http://localhost:3000 (login: `monitoring`; password is shown at the end of quickstart)
302+
- **🚀 MAIN: Grafana Dashboard**: http://localhost:3000 (login: `monitoring`; password is shown at the end of local-install)
303303
304304
Technical URLs (for advanced users):
305305
- **Demo DB**: postgresql://postgres:postgres@localhost:55432/target_database
@@ -309,27 +309,8 @@ Technical URLs (for advanced users):
309309
## 📖 Help
310310
311311
```bash
312-
./postgres_ai help
313-
```
314-
315-
### Node.js CLI (early preview)
316-
317-
```bash
318-
# run without install
319-
node ./cli/bin/postgres-ai.js --help
320-
321-
# local dev: install aliases into PATH
322-
npm --prefix cli install --no-audit --no-fund
323-
npm link ./cli
324-
postgres-ai --help
325312
postgresai --help
326-
pgai --help
327-
328-
# or install globally after publish (planned)
329-
# npm i -g @postgresai/cli
330-
# postgres-ai --help
331-
# postgresai --help
332-
# pgai --help
313+
postgresai mon --help
333314
```
334315
335316
## 🔑 PostgresAI access token

cli/bin/postgres-ai.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,17 +1185,33 @@ mon
11851185

11861186
// Update .env with custom tag if provided
11871187
const envFile = path.resolve(projectDir, ".env");
1188-
const imageTag = opts.tag || pkg.version;
11891188

1190-
// Build .env content
1191-
const envLines: string[] = [`PGAI_TAG=${imageTag}`];
1192-
// Preserve GF_SECURITY_ADMIN_PASSWORD if it exists
1189+
// Build .env content, preserving important existing values
1190+
// Read existing .env first to preserve CI/custom settings
1191+
let existingTag: string | null = null;
1192+
let existingRegistry: string | null = null;
1193+
let existingPassword: string | null = null;
1194+
11931195
if (fs.existsSync(envFile)) {
11941196
const existingEnv = fs.readFileSync(envFile, "utf8");
1197+
// Extract existing values
1198+
const tagMatch = existingEnv.match(/^PGAI_TAG=(.+)$/m);
1199+
if (tagMatch) existingTag = tagMatch[1].trim();
1200+
const registryMatch = existingEnv.match(/^PGAI_REGISTRY=(.+)$/m);
1201+
if (registryMatch) existingRegistry = registryMatch[1].trim();
11951202
const pwdMatch = existingEnv.match(/^GF_SECURITY_ADMIN_PASSWORD=(.+)$/m);
1196-
if (pwdMatch) {
1197-
envLines.push(`GF_SECURITY_ADMIN_PASSWORD=${pwdMatch[1]}`);
1198-
}
1203+
if (pwdMatch) existingPassword = pwdMatch[1].trim();
1204+
}
1205+
1206+
// Priority: CLI --tag flag > existing .env > package version
1207+
const imageTag = opts.tag || existingTag || pkg.version;
1208+
1209+
const envLines: string[] = [`PGAI_TAG=${imageTag}`];
1210+
if (existingRegistry) {
1211+
envLines.push(`PGAI_REGISTRY=${existingRegistry}`);
1212+
}
1213+
if (existingPassword) {
1214+
envLines.push(`GF_SECURITY_ADMIN_PASSWORD=${existingPassword}`);
11991215
}
12001216
fs.writeFileSync(envFile, envLines.join("\n") + "\n", { encoding: "utf8", mode: 0o600 });
12011217

config/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ COPY pgwatch-postgres/metrics.yml /postgres_ai_configs/pgwatch/metrics.yml
2525
COPY pgwatch-prometheus/metrics.yml /postgres_ai_configs/pgwatch-prometheus/metrics.yml
2626
COPY prometheus/ /postgres_ai_configs/prometheus/
2727
COPY sink-postgres/ /postgres_ai_configs/sink-postgres/
28-
# Demo DB – used only for `quickstart --demo`
28+
# Demo DB – used only for `mon local-install --demo`
2929
COPY target-db/ /postgres_ai_configs/target-db/
3030

3131
# Copy infrastructure scripts (entrypoints, generators, etc.)

0 commit comments

Comments
 (0)