Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure docker images can build in pipeline #1208

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,5 @@ jobs:
- name: Lint
run: pnpm lint-check

- name: Build
run: |
pnpm run -F @dotkomonline/brevduen \
-F @dotkomonline/invoicification \
-F @dotkomonline/rif \
-F @dotkomonline/rpc \
build
- name: Build docker images
run: pnpm run docker:build
7 changes: 6 additions & 1 deletion apps/dashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ ENV DOCKER_BUILD=1

RUN npm install -g [email protected] [email protected] --ignore-scripts
COPY --from=builder /app/out/json .
RUN pnpm install --ignore-scripts
COPY --from=builder /app/out/full/packages/db/prisma/schema.prisma packages/db/prisma/schema.prisma

# Must enable scripts here for Prisma codegen to build
RUN apk update && apk add --no-cache python3 gcc g++ make
RUN pnpm install

COPY --from=builder /app/out/full .
RUN turbo run build --filter @dotkomonline/dashboard

Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"dev": "next dev -p 3002 --turbo",
"build": "next build",
"docker:build": "docker build --platform linux/amd64 -t dashboard:latest -f Dockerfile --progress plain ../..",
"start": "next start",
"lint": "biome check . --write",
"lint-check": "biome check .",
Expand Down
2 changes: 1 addition & 1 deletion apps/invoicification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "biome check . --write",
"lint-check": "biome check .",
"type-check": "tsc --noEmit",
"docker:build": "docker build --platform linux/amd64 -t invoicification:latest -f Dockerfile ../..",
"docker:build": "docker build --platform linux/amd64 -t invoicification:latest -f Dockerfile --progress plain ../..",
"docker:push:prod": "docker tag invoicification:latest 891459268445.dkr.ecr.eu-north-1.amazonaws.com/monoweb/prod/invoicification:latest && docker push 891459268445.dkr.ecr.eu-north-1.amazonaws.com/monoweb/prod/invoicification:latest"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/rif/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "biome check . --write",
"lint-check": "biome check .",
"type-check": "tsc --noEmit",
"docker:build": "docker build --platform linux/amd64 -t rif:latest -f Dockerfile ../..",
"docker:build": "docker build --platform linux/amd64 -t rif:latest -f Dockerfile --progress plain ../..",
"docker:push:prod": "docker tag rif:latest 891459268445.dkr.ecr.eu-north-1.amazonaws.com/monoweb/prod/rif:latest && docker push 891459268445.dkr.ecr.eu-north-1.amazonaws.com/monoweb/prod/rif:latest"
},
"dependencies": {
Expand Down
17 changes: 11 additions & 6 deletions apps/rpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ ENV DOCKER_BUILD=1

RUN npm install -g [email protected] [email protected] --ignore-scripts
COPY --from=builder /app/out/json .
RUN pnpm install --ignore-scripts
COPY --from=builder /app/out/full .
RUN turbo run build --filter @dotkomonline/rpc
COPY --from=builder /app/out/full/packages/db/prisma/schema.prisma packages/db/prisma/schema.prisma

# Must enable scripts here for Prisma codegen to build
RUN apk update && apk add --no-cache python3 gcc g++ make
RUN pnpm install

# Install for production
RUN pnpm install --production

FROM base AS runner
WORKDIR /app
Expand All @@ -34,7 +39,7 @@ RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 rpc
USER rpc

COPY --from=installer --chown=nodejs:rpc --chmod=755 /app/apps/rpc/dist/index.js ./
COPY --from=installer --chown=nodejs:rpc --chmod=755 /app/apps/rpc/package.json ./
COPY --from=installer --chown=rpc:nodejs --chmod=755 /app .
COPY --from=builder --chown=rpc:nodejs --chmod=755 /app/out/full .

CMD node index.js
CMD node --loader ./apps/rpc/runtime.mjs --experimental-strip-types ./apps/rpc/src/index.ts
4 changes: 1 addition & 3 deletions apps/rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "dotenv -o -- tsx watch src/index.ts",
"build": "tsup src/index.ts",
"docker:build": "docker build --platform linux/amd64 -t rpc:latest -f Dockerfile --progress plain ../..",
"lint": "biome check . --write",
"lint-check": "biome check .",
"type-check": "tsc --noEmit"
Expand All @@ -29,8 +29,6 @@
"@types/node": "^22.0.0",
"dotenv-cli": "^8.0.0",
"tslib": "^2.6.2",
"tsup": "^8.3.0",
"tsx": "^4.15.6",
"typescript": "^5.8"
}
}
21 changes: 21 additions & 0 deletions apps/rpc/runtime.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "node:path"
import { URL } from "node:url"

export async function resolve(specifier, context, nextResolve) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrites ../index to ../index.ts for node imports. This means things work well with both next's build system and node --strip-experimental-types

// Only handle relative or absolute paths without extensions
if (
(specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/")) &&
!path.extname(specifier)
) {
// Try with .ts extension first
const tsFile = `${specifier}.ts`
const resolvedTsPath = new URL(tsFile, context.parentURL).href
return {
url: resolvedTsPath,
shortCircuit: true,
}
}

// Let Node.js handle it if no match
return nextResolve(specifier)
}
15 changes: 0 additions & 15 deletions apps/rpc/tsup.config.ts

This file was deleted.

12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"name": "monorepo",
"version": "1.0.0",
"description": "Monoweb is the next-generation web application for Online. This is the monorepo source.",
"keywords": [
"online",
"ntnu",
"student-association"
],
"keywords": ["online", "ntnu", "student-association"],
"homepage": "https://online.ntnu.no",
"author": "Dotkom <[email protected]> (https://online.ntnu.no)",
"bugs": {
Expand Down Expand Up @@ -37,13 +33,11 @@
"type-check": "turbo run type-check",
"clean": "turbo run clean",
"docker:login": "aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 891459268445.dkr.ecr.eu-north-1.amazonaws.com",
"docker:build": "turbo run docker:build",
"docker:login:public": "aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws",
"shell": "pnpm --filter=@dotkomonline/shell start"
},
"workspaces": [
"packages/*",
"apps/*"
],
"workspaces": ["packages/*", "apps/*"],
"packageManager": "[email protected]",
"engines": {
"node": ">=20.12.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DBClient } from "@dotkomonline/db"
import { type DBClient, PrismaRuntime } from "@dotkomonline/db"
import {
type Attendance,
type AttendanceId,
Expand All @@ -7,7 +7,6 @@ import {
type Extras,
ExtrasSchema,
} from "@dotkomonline/types"
import { Prisma } from "@prisma/client"
import type { JsonValue } from "@prisma/client/runtime/library"

export interface AttendanceRepository {
Expand Down Expand Up @@ -80,7 +79,7 @@ export class AttendanceRepositoryImpl implements AttendanceRepository {

/** Prisma requires distinction between database null and json null, so here we choose database null */
private correctNullTypes<T extends { extras?: unknown }>(data: T) {
return { ...data, extras: data.extras === null ? Prisma.DbNull : data.extras }
return { ...data, extras: data.extras === null ? PrismaRuntime.DbNull : data.extras }
}

/** Takes an object with unparsed JSON value yearCriteria and returns it with yearCriteria parsed */
Expand Down
4 changes: 2 additions & 2 deletions packages/core/vitest-integration.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { S3Client } from "@aws-sdk/client-s3"
import type { DBClient } from "@dotkomonline/db"
import { getTestClient } from "@dotkomonline/db/src/test-databases"
import { getPrismaClientForTest } from "@dotkomonline/db/test-harness"
import type { ManagementClient } from "auth0"
import { afterAll, beforeEach } from "vitest"
import { mockDeep } from "vitest-mock-extended"
Expand Down Expand Up @@ -28,6 +28,6 @@ afterAll(async () => {
})

beforeEach(async () => {
dbClient = await getTestClient()
dbClient = await getPrismaClientForTest()
core = await createServiceLayerForTesting()
})
17 changes: 15 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
"name": "@dotkomonline/db",
"version": "1.0.0",
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"private": true,
"exports": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed, so that types only imports schemas, and none of the actual Prisma client stuff. The prisma client breaks on Vercel (and shouldn't be used there for any reason either).

Same goes for the test harness

".": {
"import": "./src/index.ts",
"types": "./src/index.ts"
},
"./schemas": {
"import": "./src/schemas.ts",
"types": "./src/schemas.ts"
},
"./test-harness": {
"import": "./src/test-harness.ts",
"types": "./src/test-harness.ts"
}
},
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "biome check . --write",
Expand All @@ -27,6 +39,7 @@
"devDependencies": {
"@biomejs/biome": "^1.9.3",
"@dotkomonline/config": "workspace:*",
"@types/node": "^22.0.0",
"@types/pg": "^8.10.9",
"prisma": "^6.3.1",
"tsx": "^4.19.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ generator zod {
provider = "zod-prisma-types"
output = "../src/schemas"

useMultipleFiles = true
useMultipleFiles = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node does not support directory import, and this codegenerator generates directory import when using multiple files.

createInputTypes = false
addIncludeType = false
addSelectType = false
Expand Down
5 changes: 3 additions & 2 deletions packages/db/src/fixtures/attendance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Prisma } from "@prisma/client"
import type { Prisma } from "@prisma/client"
import { PrismaRuntime } from "../index"

export const getAttendanceFixtures = (): Prisma.AttendanceCreateManyInput[] => [
{
Expand Down Expand Up @@ -52,6 +53,6 @@ export const getAttendanceFixtures = (): Prisma.AttendanceCreateManyInput[] => [
deregisterDeadline: new Date("2023-02-23 11:03:49.289+00"),
createdAt: new Date("2023-02-23 11:03:49.289+00"),
updatedAt: new Date("2023-02-23 11:03:49.289+00"),
extras: Prisma.DbNull,
extras: PrismaRuntime.DbNull,
},
]
11 changes: 8 additions & 3 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { type Prisma, PrismaClient } from "@prisma/client"
import { createRequire } from "node:module"
import type { Prisma, PrismaClient } from "@prisma/client"
import type { DefaultArgs } from "@prisma/client/runtime/library"

export * as schemas from "./schemas"
const require = createRequire(import.meta.url)
const { Prisma: _Prisma, PrismaClient: _PrismaClient } = require("@prisma/client")
export type * from "@prisma/client"

export const PrismaRuntime = _Prisma
export const PrismaClientRuntime = _PrismaClient
export type DBClient = PrismaClient<Prisma.PrismaClientOptions, never, DefaultArgs>
export const createPrisma = (databaseUrl: string): DBClient =>
new PrismaClient({
new _PrismaClient({
datasourceUrl: databaseUrl,
})
1 change: 1 addition & 0 deletions packages/db/src/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as schemas from "./schemas/index"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// biome-ignore lint/style/useNodejsImportProtocol: Cannot import with node path on vercel
import { spawn } from "node:child_process"
import { spawn } from "child_process"
import { PostgreSqlContainer } from "@testcontainers/postgresql"
import { createPrisma } from "."

Expand Down Expand Up @@ -46,10 +46,8 @@ function migrateTestDatabase(dbUrl: string) {
})
}

export async function getTestClient() {
export async function getPrismaClientForTest() {
const dbUrl = await getTestContainerDatabase()

await migrateTestDatabase(dbUrl)

return createPrisma(dbUrl)
}
3 changes: 2 additions & 1 deletion packages/db/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../packages/config/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true
"declaration": true,
"types": ["node"]
},
"include": ["./**/*.ts", "./**/*.tsx"]
}
1 change: 1 addition & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"devDependencies": {
"@biomejs/biome": "^1.9.3",
"@dotkomonline/config": "workspace:*",
"@types/node": "^22.0.0",
"typescript": "^5.8"
}
}
2 changes: 1 addition & 1 deletion packages/types/src/article.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import type { z } from "zod"

export const ArticleTagSchema = schemas.ArticleTagSchema.extend({})
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/attendance/attendance-pool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import { z } from "zod"

export const YearCriteriaSchema = z.array(z.number())
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/attendance/attendance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import { z } from "zod"

export const ExtraSchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/attendance/attendee.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import { z } from "zod"
import type { User } from "../user"

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/attendance/waitlist-attendee.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import type { z } from "zod"

export const WaitlistAttendeeSchema = schemas.WaitlistAttendeeSchema.extend({})
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/committee.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { z } from "zod"

import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"

export const CommitteeSchema = schemas.CommitteeSchema.extend({})

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/company.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import type { z } from "zod"

export const CompanySchema = schemas.CompanySchema.extend({})
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/event-committee.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import type { z } from "zod"

export const EventCommitteeSchema = schemas.EventCommitteeSchema.extend({})
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { z } from "zod"

import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"

import { type Attendance, AttendanceSchema } from "./attendance/attendance"
import type { AttendancePool } from "./attendance/attendance-pool"
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/interest-group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { z } from "zod"

import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"

export const InterestGroupSchema = schemas.InterestGroupSchema.extend({})

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/job-listing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import { z } from "zod"
import { CompanySchema } from "./company"

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/mark.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schemas } from "@dotkomonline/db"
import { schemas } from "@dotkomonline/db/schemas"
import type { z } from "zod"

export const MarkSchema = schemas.MarkSchema.extend({})
Expand Down
Loading
Loading