From ae5e39c6df77e5674238ad36fc53ceaa8f2836b6 Mon Sep 17 00:00:00 2001 From: solufa Date: Tue, 4 Jun 2024 23:47:18 +0900 Subject: [PATCH] chore: add Dockerfile for deploying --- .github/workflows/test.yml | 6 +++--- Dockerfile | 18 ++++++++++++++++++ README.md | 4 ++-- package.json | 1 + server/out | 1 - server/service/app.ts | 7 ++++++- 6 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 Dockerfile delete mode 120000 server/out diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 50dcb45..cb96725 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,11 +27,11 @@ jobs: with: path: 'server/node_modules' key: server-npm-${{ hashFiles('server/package-lock.json') }} - - run: npm install + - run: npm ci if: steps.root-npm-cache.outputs.cache-hit != 'true' - - run: npm install --prefix client + - run: npm ci --prefix client if: steps.client-npm-cache.outputs.cache-hit != 'true' - - run: npm install --prefix server + - run: npm ci --prefix server if: steps.server-npm-cache.outputs.cache-hit != 'true' - run: npm run generate - run: npm run lint diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a13691e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:20-alpine + +WORKDIR /usr/src/app + +COPY package.json package-lock.json . +RUN npm ci + +COPY client/package.json client/package-lock.json ./client/ +RUN npm ci --prefix client + +COPY server/package.json server/package-lock.json ./server/ +RUN npm ci --prefix server + +COPY . . +ARG DATABASE_URL +RUN npm run build + +CMD npm start diff --git a/README.md b/README.md index 42d603d..ece7816 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Next frourio starter -フロントエンドは client ディレクトリの [Next.js](https://nextjs.org/) 、バックエンドは server ディレクトリの [frourio](https://frourio.com/) で構築された TypeScript で一気通貫開発が可能なモノレポサービス +フロントエンドは client ディレクトリの [Next.js](https://nextjs.org) 、バックエンドは server ディレクトリの [frourio](https://frourio.com) で構築された TypeScript で一気通貫開発が可能なモノレポサービス -最新のコミットによるデモ - https://solufa.github.io/next-frourio-starter/ +最新のコミットによるデモ - https://starter.frourio.com ## 開発手順 diff --git a/package.json b/package.json index bb4a074..f88ca8d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "lint": "run-p lint:*", "lint:client": "npm run lint:fix --prefix client", "lint:server": "npm run lint:fix --prefix server", + "start": "npm start --prefix server", "test": "run-p test:*", "test:client": "npm run test --prefix client", "test:server": "npm run test --prefix server", diff --git a/server/out b/server/out deleted file mode 120000 index d82a685..0000000 --- a/server/out +++ /dev/null @@ -1 +0,0 @@ -../client/out \ No newline at end of file diff --git a/server/service/app.ts b/server/service/app.ts index 9d410da..11a8f31 100644 --- a/server/service/app.ts +++ b/server/service/app.ts @@ -4,6 +4,7 @@ import helmet from '@fastify/helmet'; import fastifyStatic from '@fastify/static'; import type { FastifyInstance, FastifyServerFactory } from 'fastify'; import Fastify from 'fastify'; +import { existsSync, readdirSync } from 'fs'; import { join } from 'path'; import { API_BASE_PATH } from 'service/envValues'; @@ -12,7 +13,11 @@ export const init = (serverFactory?: FastifyServerFactory): FastifyInstance => { fastify.register(helmet); fastify.register(cookie); - fastify.register(fastifyStatic, { root: join(__dirname, '../out') }); + fastify.register(fastifyStatic, { root: join(__dirname, '../client/out') }); + console.log( + 333, + existsSync(join(__dirname, '../client/out')) && readdirSync(join(__dirname, '../client/out')), + ); server(fastify, { basePath: API_BASE_PATH }); return fastify;