feat: setup database

This commit is contained in:
Keisuke Hirata 2024-08-17 16:10:26 +09:00
parent 53a4a08796
commit 0823070534
6 changed files with 1036 additions and 18 deletions

26
Dockerfile Normal file
View File

@ -0,0 +1,26 @@
# For Build
FROM node:22-slim as builder
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY tsconfig.json ./
RUN npm ci
COPY . .
RUN npm run build
# For Run
FROM node:22-slim
WORKDIR /app
COPY --from=builder /app/build ./build
COPY --from=builder /app/package.json .
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "./build"]

23
docker-compose.yml Normal file
View File

@ -0,0 +1,23 @@
services:
frontend:
build:
context: .
dockerfile: ./Dockerfile
environment:
- PORT=${WEB_PORT}
ports:
- ${WEB_PORT}:${WEB_PORT}
volumes:
- ./src:/app/src
- ./static:/app/static
- ./vite.config.js:/app/vite.config.js
- ./tsconfig.json:/app/tsconfig.json
- ./svelte.config.js:/app/svelte.config.js
db:
image: postgres:16
environment:
- POSTGRES_PASSWORD=${PG_PASS}
ports:
- ${PG_PORT}:5432
volumes:
- ./postgres:/var/lib/postgresql/data

976
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,9 +15,11 @@
"devDependencies": {
"@playwright/test": "^1.28.1",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/adapter-node": "^5.2.2",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "^9.6.0",
"@types/pg": "^8.11.6",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
@ -30,5 +32,10 @@
"typescript-eslint": "^8.0.0",
"vite": "^5.0.3"
},
"type": "module"
"type": "module",
"dependencies": {
"dotenv": "^16.4.5",
"pg": "^8.12.0",
"sass": "^1.77.8"
}
}

18
src/lib/database.ts Normal file
View File

@ -0,0 +1,18 @@
import pg from 'pg';
const { Pool } = pg;
import {
DB_USER,
DB_PASS,
DB_HOST,
PG_PORT,
DB_DATABASE,
} from '$env/static/private'
const connectionString = `postgres://${DB_USER}:${DB_PASS}@${DB_HOST}:${PG_PORT}/${DB_DATABASE}`;
const pool = new Pool({
connectionString: connectionString,
max: 2,
});
export default pool;

View File

@ -1,4 +1,4 @@
import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */