Skip to content

Commit 92e4bcb

Browse files
committed
fix: restore deploy pipe for server app
1 parent 0b4cde7 commit 92e4bcb

File tree

9 files changed

+52
-65
lines changed

9 files changed

+52
-65
lines changed

apps/server/Dockerfile

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
FROM node:20.12.0-alpine AS base
2+
RUN apk update
3+
RUN apk add --no-cache libc6-compat
24

35
RUN corepack enable
46

57
ENV PNPM_HOME="/pnpm"
68
ENV PATH="$PNPM_HOME:$PATH"
79

8-
RUN pnpm add -g prisma turbo
10+
RUN pnpm add -g turbo prisma
911

1012
ARG DOCKER_ENV
1113
ENV DOCKER_ENV=${DOCKER_ENV}
@@ -19,31 +21,38 @@ ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
1921

2022
ENV APP_DIR="apps/server"
2123

22-
WORKDIR /app/${APP_DIR}
23-
24-
COPY ./package*.json /app
25-
COPY ./pnpm-*.yaml /app
26-
COPY ./turbo.json /app
27-
COPY ./${APP_DIR} /app/${APP_DIR}
28-
COPY ./packages /app/packages
24+
WORKDIR /app
2925

26+
FROM base AS pruner
27+
COPY . .
28+
RUN turbo prune server --docker
3029

31-
RUN turbo telemetry disable
30+
FROM base As builder
31+
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
32+
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
33+
COPY --from=pruner /app/out/json/ ./
34+
COPY --from=pruner /app/out/full/ .
3235

33-
RUN turbo prune server --docker
3436
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
35-
RUN pnpm -r prisma:generate
3637

37-
FROM base As builder
38-
RUN pnpm ssm pull -e ${DOCKER_ENV}
39-
WORKDIR /app
40-
RUN turbo build
38+
RUN pnpm --filter @packages/database prisma:generate
39+
RUN pnpm --filter server ssm pull -e ${DOCKER_ENV}
40+
RUN turbo build:prod
4141

4242
FROM base As runner
43-
COPY --from=builder /app/packages/database/dist /app/packages/database/dist
43+
COPY --from=builder /app/package*.json .
44+
COPY --from=builder /app/pnpm-*.yaml .
45+
COPY --from=builder /app/packages/ /app/packages
46+
47+
WORKDIR /app/${APP_DIR}
48+
4449
COPY --from=builder /app/${APP_DIR}/dist /app/${APP_DIR}/dist
50+
COPY --from=builder /app/${APP_DIR}/src/graphql /app/${APP_DIR}/src/graphql
51+
COPY --from=builder /app/${APP_DIR}/*.json .
4552
COPY --from=builder /app/${APP_DIR}/env /app/${APP_DIR}/env
4653

54+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
55+
4756
EXPOSE 5003
4857

4958
CMD [ "pnpm", "start" ]

apps/server/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"type": "module",
1717
"scripts": {
1818
"dev": "nodemon --watch './**/*.mts' --exec 'node --import @swc-node/register/esm-register' ./src/main.mts | pino-pretty",
19-
"start": "node --import @swc-node/register/esm-register dist/src/main.mjs",
19+
"start": "NODE_ENV=production DOCKER_ENV=stage node dist/src/main.mjs",
2020
"build": "tsc --project tsconfig.json",
21-
"build:prod": "tsc --project tsconfig.prod.json",
21+
"build:prod": "tsc --project tsconfig.prod.json && tsc-alias -p tsconfig.prod.json",
2222
"codegen": "graphql-codegen --config codegen.ts",
2323
"test": "pnpm jest --detectOpenHandles",
2424
"create-service": "tsx ./scripts/createService.ts",
@@ -43,6 +43,7 @@
4343
"@packages/common-scripts": "workspace:*",
4444
"@packages/database": "workspace:*",
4545
"@prisma/client": "^5.11.0",
46+
"@swc-node/register": "^1.9.0",
4647
"ajv": "^8.12.0",
4748
"axios": "^1.4.0",
4849
"backblaze-b2": "^1.7.0",
@@ -60,6 +61,7 @@
6061
"graphql-scalars": "^1.22.2",
6162
"inquirer": "^9.2.12",
6263
"ioredis": "^5.3.2",
64+
"json-schema-to-ts": "^3.0.1",
6365
"jsonwebtoken": "^9.0.2",
6466
"lru-cache": "^10.0.0",
6567
"marked": "^8.0.0",
@@ -89,9 +91,6 @@
8991
"@graphql-codegen/typescript": "^4.0.0",
9092
"@graphql-codegen/typescript-operations": "^4.0.0",
9193
"@graphql-codegen/typescript-resolvers": "^4.0.0",
92-
"@swc-node/register": "^1.9.0",
93-
"@swc/cli": "^0.3.10",
94-
"@swc/core": "^1.4.11",
9594
"@types/backblaze-b2": "^1.5.2",
9695
"@types/geoip-country": "^4.0.2",
9796
"@types/inquirer": "^9.0.7",
@@ -113,7 +112,6 @@
113112
"jest": "^29.6.4",
114113
"jest-mock-axios": "^4.7.3",
115114
"jest-mock-extended": "^3.0.5",
116-
"json-schema-to-ts": "^2.9.2",
117115
"nodemon": "^2.0.22",
118116
"prettier": "3.0.2",
119117
"ts-jest": "^29.1.1",

apps/server/src/env.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ const appEnv: AppEnvironment = ['stage', 'production'].includes(dockerEnv)
2626
: 'development'
2727

2828
const envFile = envFiles[dockerEnv]
29-
const prefix = './env'
29+
const prefix = dockerEnv === 'development' ? './env' : '../env'
3030

3131
function resolveDir(dir: string): string {
3232
const __filename = fileURLToPath(import.meta.url)
3333
const splited = dirname(__filename).split('/src')
3434
const cwd = splited.slice(0, -1).join('/src')
35+
console.log('cwd', cwd)
3536
return join(cwd, dir)
3637
}
3738

apps/server/src/main.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'reflect-metadata'
2-
import { ENV } from 'src/env.mjs'
2+
import { ENV } from './env.mjs'
33
import app from './app.mjs'
44
import { container } from 'tsyringe'
55
import { startClosing } from '@plugins/global/keepAlivePlugin.mjs'

apps/server/src/types/graphql.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '*.gql' {
2+
import { DocumentNode } from 'graphql'
3+
const value: DocumentNode
4+
export = value
5+
}

apps/server/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,5 @@
3939
"scripts/**.mts",
4040
"scripts/**/*.mts"
4141
],
42-
"exclude": ["node_modules"],
43-
"ts-node": {
44-
"transpileOnly": true,
45-
"esm": true,
46-
"swc": true
47-
}
42+
"exclude": ["node_modules"]
4843
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "Velog is a blog platform for developers.",
55
"private": true,
66
"scripts": {
7-
"prepare": "husky install",
87
"format": "pnpm format --write .",
98
"precommit": "lint-staged",
109
"dev": "pnpm -r dev",

pnpm-lock.yaml

Lines changed: 10 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"$schema": "https://turbo.build/schema.json",
33
"pipeline": {
4+
"build:prod": {
5+
"dependsOn": ["^build"],
6+
"outputs": [".next/**", "!.next/cache/**", "dist/**"]
7+
},
48
"build": {
59
"dependsOn": ["^build"],
610
"outputs": [".next/**", "!.next/cache/**", "dist/**"]

0 commit comments

Comments
 (0)