Skip to content

Commit 5002abb

Browse files
committed
Implement DB and terminated deal tracking
1 parent 4119c45 commit 5002abb

23 files changed

+9224
-2272
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ node_modules
22
.env
33
dist
44

5+
/prisma/generated/
6+
/prismaDmob/generated/
7+
58
src/**/*.js

Dockerfile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@ FROM node:24-alpine AS build
22
WORKDIR /app
33
COPY package*.json ./
44
RUN npm ci
5-
COPY . .
5+
6+
COPY --chown=1000:1000 . .
7+
8+
RUN --mount=type=secret,id=DATABASE_URL,uid=1000 \
9+
env DATABASE_URL=$(cat /run/secrets/DATABASE_URL) \
10+
npx prisma generate --schema=./prisma/schema.prisma
11+
RUN --mount=type=secret,id=DMOB_DATABASE_URL,uid=1000 \
12+
env DMOB_DATABASE_URL=$(cat /run/secrets/DMOB_DATABASE_URL) \
13+
npx prisma generate --schema=./prismaDmob/schema.prisma
14+
615
RUN npm run build
716

817
FROM node:24-alpine
918
WORKDIR /app
1019
COPY package*.json ./
1120
RUN npm ci --omit=dev
1221
COPY --from=build /app/dist ./dist
22+
COPY --from=build --chown=node:node /app/prisma/ ./prisma/
23+
COPY --from=build --chown=node:node /app/prismaDmob/ ./prismaDmob/
24+
COPY ci/aws-secret-to-db-url.js ./
25+
COPY ci/runner.sh ./
26+
27+
ADD --chown=node https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /etc/ssl/certs/aws-global-bundle.pem
28+
ENTRYPOINT [ "/app/runner.sh" ]
29+
1330
EXPOSE 3000
1431
CMD ["node", "dist/index.js"]

ci/aws-secret-to-db-url.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
if (!process.env.DB_CONNECT_PARAMS_JSON) {
2+
console.error("Missing DB_CONNECT_PARAMS_JSON env var!");
3+
process.exit(1);
4+
}
5+
6+
const {
7+
engine,
8+
username,
9+
password: rawPassword,
10+
host,
11+
port,
12+
dbname,
13+
} = JSON.parse(process.env.DB_CONNECT_PARAMS_JSON);
14+
15+
if (!engine) {
16+
console.error("Missing engine in DB_CONNECT_PARAMS_JSON!");
17+
process.exit(1);
18+
}
19+
20+
if (!username) {
21+
console.error("Missing username in DB_CONNECT_PARAMS_JSON!");
22+
process.exit(1);
23+
}
24+
25+
if (!rawPassword) {
26+
console.error("Missing password in DB_CONNECT_PARAMS_JSON!");
27+
process.exit(1);
28+
}
29+
30+
if (!host) {
31+
console.error("Missing host in DB_CONNECT_PARAMS_JSON!");
32+
process.exit(1);
33+
}
34+
35+
if (!port) {
36+
console.error("Missing port in DB_CONNECT_PARAMS_JSON!");
37+
process.exit(1);
38+
}
39+
40+
if (!dbname) {
41+
console.error("Missing dbname in DB_CONNECT_PARAMS_JSON!");
42+
process.exit(1);
43+
}
44+
45+
const options = process.env.DB_OPTIONS ?? "";
46+
const password = encodeURIComponent(rawPassword);
47+
console.log(
48+
`${engine}://${username}:${password}@${host}:${port}/${dbname}?${options}`,
49+
);

ci/runner.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
cd "$(dirname "$0")"
6+
7+
if [ -z "$DATABASE_URL" ]; then
8+
export DATABASE_URL="$(node aws-secret-to-db-url.js)"
9+
fi
10+
11+
if [ -n "$DATABASE_URL" ]; then
12+
exec "$@"
13+
fi

docker-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: "3.9"
2+
services:
3+
oracle-service-db:
4+
image: postgres:17
5+
restart: unless-stopped
6+
volumes:
7+
- postgres_data:/var/lib/postgresql/data
8+
environment:
9+
- PGUSER=postgres
10+
- POSTGRES_DB=postgres
11+
- POSTGRES_USER=postgres
12+
- POSTGRES_PASSWORD=postgres
13+
ports:
14+
- "8038:5432"
15+
healthcheck:
16+
test: "pg_isready"
17+
interval: 30s
18+
timeout: 5s
19+
retries: 2
20+
21+
volumes:
22+
postgres_data:
23+
driver: local

0 commit comments

Comments
 (0)