Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

Commit dbc8bad

Browse files
committed
fix docker compose
1 parent dcce792 commit dbc8bad

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

metrics-collector/.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ build
55
.git
66
.vscode
77
*metrics.csv
8-
*metrics.json
8+
*metrics.json
9+
data

metrics-collector/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ temp
44
*metrics.json
55
*metrics.csv
66
build
7+
data

metrics-collector/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ COPY . .
1919
# Build the TypeScript code
2020
RUN pnpm run build
2121

22+
# Create a directory for storing state data
23+
RUN mkdir -p /usr/src/app/data
24+
2225
# Expose the port the app runs on
2326
EXPOSE 3001

metrics-collector/docker-compose.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
postgres:
53
image: postgres:15-alpine
@@ -8,6 +6,11 @@ services:
86
POSTGRES_USER: admin
97
POSTGRES_PASSWORD: supersecret
108
POSTGRES_DB: metrics
9+
healthcheck:
10+
test: ["CMD-SHELL", "pg_isready -U admin -d metrics"]
11+
interval: 5s
12+
timeout: 5s
13+
retries: 5
1114
volumes:
1215
- pgdata:/var/lib/postgresql/data
1316
ports:
@@ -24,9 +27,12 @@ services:
2427
DB_PASSWORD: supersecret
2528
DB_NAME: metrics
2629
depends_on:
27-
- postgres
30+
postgres:
31+
condition: service_healthy
2832
ports:
2933
- "3001:3001"
34+
volumes:
35+
- metrics-data:/usr/src/app/data
3036

3137
grafana:
3238
image: grafana/grafana:latest
@@ -44,3 +50,4 @@ services:
4450
volumes:
4551
pgdata:
4652
grafana-storage:
53+
metrics-data:

metrics-collector/src/index.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "./sonatype-metrics";
1313
import { getYesterdayDate, readJsonFile } from "./utils";
1414
import { readFile, writeFile } from "fs/promises";
15-
import { existsSync } from "fs";
15+
import { existsSync, mkdirSync } from "fs";
1616

1717
const isLocalPersistence = process.env.PERSIST_LOCAL_FILES === "true";
1818

@@ -152,8 +152,7 @@ async function initialLoad(
152152
}
153153

154154
export const getLastSavedState = async (metricName: string) => {
155-
const stateDir = process.env.LAST_SAVED_STATE_PATH || "./";
156-
const filePath = `${stateDir}/last-saved-state-${metricName}`;
155+
const filePath = `./data/last-saved-state-${metricName}`;
157156
if (!existsSync(filePath)) {
158157
return undefined;
159158
}
@@ -162,8 +161,11 @@ export const getLastSavedState = async (metricName: string) => {
162161
};
163162

164163
export const saveLastSavedState = (metricName: string, date: Date) => {
165-
const stateDir = process.env.LAST_SAVED_STATE_PATH || "./";
166-
const filePath = `${stateDir}/last-saved-state-${metricName}`;
164+
const dataDir = "./data";
165+
if (!existsSync(dataDir)) {
166+
mkdirSync(dataDir, { recursive: true });
167+
}
168+
const filePath = `${dataDir}/last-saved-state-${metricName}`;
167169
return writeFile(filePath, date.toISOString());
168170
};
169171

0 commit comments

Comments
 (0)