Skip to content

Commit 18e539d

Browse files
authored
Merge pull request #6 from topcoder-platform/develop
Build / security fixes, Prisma updates to run migrations on deploy, and add new subcontractingEndCustomer field to billing accounts to be loaded from Salesforce.
2 parents e21db62 + ecce205 commit 18e539d

12 files changed

Lines changed: 735 additions & 186 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ pids
5353
*.seed
5454
*.pid.lock
5555

56+
# TypeScript build info
57+
tsconfig.tsbuildinfo
58+
5659
# Diagnostic reports (https://nodejs.org/api/report.html)
5760
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
5861

Dockerfile

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
# ---- Base Stage ----
2-
FROM node:20-alpine AS base
2+
FROM node:22.19-alpine AS base
3+
RUN apk add --no-cache openssh-client git openssl
34
WORKDIR /usr/src/app
45

56
# ---- Dependencies Stage ----
67
FROM base AS deps
7-
# Install pnpm
88
RUN npm install -g pnpm
9-
# Copy dependency-defining files
109
COPY package.json pnpm-lock.yaml ./
11-
# Install dependencies
12-
RUN pnpm install --frozen-lockfile --prod
10+
RUN pnpm install --frozen-lockfile
1311

1412
# ---- Build Stage ----
15-
FROM base AS build
16-
RUN npm install -g pnpm
17-
COPY --from=deps /usr/src/app/node_modules ./node_modules
13+
FROM deps AS build
1814
COPY . .
19-
# Build the application
15+
# Build the application (runs prisma generate via package script)
2016
RUN pnpm build
2117

2218
# ---- Production Stage ----
2319
FROM base AS production
2420
ENV NODE_ENV=production
25-
# Install OpenSSL runtime (provides libssl.so.3 for Prisma musl OpenSSL 3)
26-
RUN apk add --no-cache openssl
27-
# Copy built application from the build stage
21+
WORKDIR /usr/src/app
22+
23+
# Copy built artifacts and runtime deps
2824
COPY --from=build /usr/src/app/dist ./dist
29-
# Copy production dependencies (including generated Prisma client) from the build stage
3025
COPY --from=build /usr/src/app/node_modules ./node_modules
26+
COPY --from=build /usr/src/app/prisma ./prisma
27+
COPY --from=build /usr/src/app/entrypoint.sh /entrypoint.sh
3128

32-
# Expose the application port
33-
EXPOSE 3000
29+
RUN chmod +x /entrypoint.sh
3430

35-
# The command to run the application
36-
CMD ["node", "dist/main.js"]
31+
ENTRYPOINT ["/entrypoint.sh"]

entrypoint.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
echo "Starting Billing Accounts API v6..."
6+
7+
# Run database migrations
8+
# Prisma uses PostgreSQL advisory locks to prevent concurrent migrations
9+
# Only one instance will run migrations, others will wait
10+
11+
echo "Running database migrations..."
12+
13+
npx prisma migrate deploy
14+
15+
# Check migration status
16+
if [ $? -eq 0 ]; then
17+
echo "Migrations completed successfully"
18+
else
19+
echo "Migration failed with exit code $?"
20+
exit 1
21+
fi
22+
23+
# Start the application
24+
echo "Starting application server..."
25+
exec node /usr/src/app/dist/main.js

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"prisma:generate": "prisma generate",
1414
"prisma:migrate": "prisma migrate dev --name init",
1515
"import:legacy": "ts-node scripts/import-legacy.ts",
16-
"import:access": "ts-node scripts/import-ba-access.ts"
16+
"import:access": "ts-node scripts/import-ba-access.ts",
17+
"import:markup": "ts-node scripts/import-markup.ts",
18+
"backfill:clientIds": "ts-node scripts/backfill-client-ids.ts"
1719
},
1820
"dependencies": {
1921
"@nestjs/common": "^10.3.0",
@@ -23,17 +25,17 @@
2325
"@nestjs/swagger": "^7.4.2",
2426
"@nestjs/mapped-types": "^2.1.0",
2527
"@nestjs/platform-express": "^10.3.0",
26-
"@prisma/client": "^5.18.0",
28+
"@prisma/client": "^6.18.0",
2729
"@types/express": "^5.0.3",
2830
"class-transformer": "^0.5.1",
2931
"class-validator": "^0.14.0",
3032
"dotenv": "^16.4.5",
3133
"pino": "^9.0.0",
32-
"prisma": "^5.18.0",
34+
"prisma": "^6.18.0",
3335
"reflect-metadata": "^0.1.13",
3436
"rimraf": "^5.0.7",
3537
"swagger-ui-express": "^5.0.0",
36-
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v3.0.1"
38+
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#security"
3739
},
3840
"devDependencies": {
3941
"@eslint/eslintrc": "^3.2.0",
@@ -50,7 +52,7 @@
5052
},
5153
"pnpm": {
5254
"onlyBuiltDependencies": [
53-
"@prisma/client"
55+
"@prisma/client"
5456
]
5557
}
5658
}

0 commit comments

Comments
 (0)