Skip to content

Commit

Permalink
refactor: implement multi-stage builds
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Jun 8, 2024
1 parent 1b96aae commit 03575d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
24 changes: 21 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine
FROM node:20-alpine AS builder

WORKDIR /usr/src/app

Expand All @@ -14,6 +14,15 @@ RUN npm ci --prefix server
COPY . .

ARG VERSION
ENV DATABASE_URL=file:../../data/app.db

RUN npm run batch:writeVersion -- $VERSION
RUN npm run build

FROM node:20-alpine

WORKDIR /usr/src/app

ENV NEXT_PUBLIC_COGNITO_POOL_ENDPOINT=http://localhost:5000
ENV NEXT_PUBLIC_COGNITO_POOL_ID=ap-northeast-1_randomPoolId
ENV NEXT_PUBLIC_COGNITO_CLIENT_ID=random-client-id
Expand All @@ -26,8 +35,17 @@ ENV SMTP_PORT=2500
ENV SMTP_USER=fake_mail_user
ENV SMTP_PASS=fake_mail_password

RUN npm run batch:writeVersion -- $VERSION
RUN npm run build
COPY --from=builder /usr/src/app/client/.next ./client/.next
COPY client/package.json client/package-lock.json ./client/
RUN npm ci --omit=dev --prefix client

COPY server/package.json server/package-lock.json ./server/
RUN npm ci --omit=dev --prefix server

COPY --from=builder /usr/src/app/server/index.js ./server/index.js
COPY --from=builder /usr/src/app/server/node_modules/.prisma/client ./server/node_modules/.prisma/client
COPY package.json .
RUN npm install -g npm-run-all
RUN apk --no-cache add curl

HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD curl -f $API_ORIGIN/health && curl -f $CORS_ORIGIN || exit 1
Expand Down
8 changes: 4 additions & 4 deletions server/service/sendMail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { APP_NAME } from 'api/@constants';
import assert from 'assert';
import { InbucketAPIClient } from 'inbucket-js-client';
import { createTransport } from 'nodemailer';
import type Mail from 'nodemailer/lib/mailer';
import { ulid } from 'ulid';
Expand Down Expand Up @@ -30,10 +29,11 @@ export const sendMail = async (options: {
if (import.meta.vitest) {
const { test, expect } = import.meta.vitest;

assert(process.env.INBUCKET_URL);
const inbucketClient = new InbucketAPIClient(process.env.INBUCKET_URL);

test('sendMail', async () => {
assert(process.env.INBUCKET_URL);

const { InbucketAPIClient } = await import('inbucket-js-client');
const inbucketClient = new InbucketAPIClient(process.env.INBUCKET_URL);
const toAddress = `${ulid()}@example.com`;
const text = 'aaa';

Expand Down

0 comments on commit 03575d2

Please sign in to comment.