Skip to content

Commit

Permalink
build: add dockerfile/docker-compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonn committed Jul 18, 2024
1 parent a8f374a commit 8b46ade
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.devbox
node_modules
backend/node_modules
frontend
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG NODE_VERSION=20

FROM node:${NODE_VERSION}-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

FROM base as build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run --filter backend build

FROM base
ENV NODE_ENV production
COPY --from=prod-deps /app/node_modules node_modules
COPY --from=prod-deps /app/package*.json .
COPY --from=prod-deps /app/backend/node_modules ./backend/node_modules
COPY --from=prod-deps /app/backend/package*.json ./backend
COPY --from=build /app/backend/dist ./backend/dist

CMD ["node", "backend/dist/main.js"]
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"postinstall": "npx prisma generate"
},
"dependencies": {
"@apollo/server": "^4.10.4",
Expand Down
1 change: 1 addition & 0 deletions backend/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const envSchema = z
NETWORK: z
.enum([NetworkType.mainnet, NetworkType.testnet])
.default(NetworkType.testnet),
ENABLED_GRAPHQL_PLAYGROUND: z.boolean().default(true),

// DATABASE_URL: z.string(),
// REDIS_URL: z.string(),
Expand Down
5 changes: 3 additions & 2 deletions backend/src/modules/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { DataLoaderInterceptor } from '@applifting-io/nestjs-dataloader';
import { CkbModule } from './ckb/ckb.module';
import { RgbppModule } from './rgbpp/rgbpp.module';
import { BitcoinModule } from './bitcoin/bitcoin.module';
import { Env } from 'src/env';

@Module({
imports: [
GraphQLModule.forRootAsync<ApolloDriverConfig>({
driver: ApolloDriver,
inject: [ConfigService, SentryService],
useFactory: async (configService: ConfigService, sentryService: SentryService) => ({
playground: configService.get('NODE_ENV') !== 'production',
useFactory: async (configService: ConfigService<Env>, sentryService: SentryService) => ({
playground: configService.get('ENABLED_GRAPHQL_PLAYGROUND'),
installSubscriptionHandlers: true,
introspection: true,
autoSchemaFile: true,
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

services:
app:
build:
context: .
ports:
- '3000:3000'
env_file:
- ./backend/.env

0 comments on commit 8b46ade

Please sign in to comment.