Skip to content

Commit

Permalink
fix docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
leordev committed Aug 30, 2024
1 parent dcce792 commit dbc8bad
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion metrics-collector/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build
.git
.vscode
*metrics.csv
*metrics.json
*metrics.json
data
1 change: 1 addition & 0 deletions metrics-collector/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ temp
*metrics.json
*metrics.csv
build
data
3 changes: 3 additions & 0 deletions metrics-collector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ COPY . .
# Build the TypeScript code
RUN pnpm run build

# Create a directory for storing state data
RUN mkdir -p /usr/src/app/data

# Expose the port the app runs on
EXPOSE 3001
13 changes: 10 additions & 3 deletions metrics-collector/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
postgres:
image: postgres:15-alpine
Expand All @@ -8,6 +6,11 @@ services:
POSTGRES_USER: admin
POSTGRES_PASSWORD: supersecret
POSTGRES_DB: metrics
healthcheck:
test: ["CMD-SHELL", "pg_isready -U admin -d metrics"]
interval: 5s
timeout: 5s
retries: 5
volumes:
- pgdata:/var/lib/postgresql/data
ports:
Expand All @@ -24,9 +27,12 @@ services:
DB_PASSWORD: supersecret
DB_NAME: metrics
depends_on:
- postgres
postgres:
condition: service_healthy
ports:
- "3001:3001"
volumes:
- metrics-data:/usr/src/app/data

grafana:
image: grafana/grafana:latest
Expand All @@ -44,3 +50,4 @@ services:
volumes:
pgdata:
grafana-storage:
metrics-data:
12 changes: 7 additions & 5 deletions metrics-collector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "./sonatype-metrics";
import { getYesterdayDate, readJsonFile } from "./utils";
import { readFile, writeFile } from "fs/promises";
import { existsSync } from "fs";
import { existsSync, mkdirSync } from "fs";

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

Expand Down Expand Up @@ -152,8 +152,7 @@ async function initialLoad(
}

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

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

Expand Down

0 comments on commit dbc8bad

Please sign in to comment.