diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c2afd89 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.env +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.idea +.svelte-kit +build +.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6075489 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM oven/bun:alpine AS base + +WORKDIR /app + +COPY package.json bun.lock ./ + +RUN bun install -p + +FROM base AS build + +WORKDIR /app + +ARG DATABASE_URL + +COPY --from=base /app/node_modules ./node_modules + +COPY . . + +RUN bun install +RUN bun run build + +FROM base AS production + +ENV NODE_ENV production + +COPY --from=build /app/build . + +EXPOSE 3000 +ENV PORT 3000 +CMD ["bun", "run", "./index.js"] diff --git a/docker-compose.yml b/docker-compose.yml index e611e22..384cc13 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,5 +10,15 @@ services: POSTGRES_DB: local volumes: - pgdata:/var/lib/postgresql/data + server: + build: . + pull_policy: always + restart: always + ports: + - 127.0.0.1:3000:3000 + environment: + DATABASE_URL: postgres://root:mysecretpassword@db:5432/local + depends_on: + - db volumes: pgdata: diff --git a/drizzle.config.ts b/drizzle.config.ts index c736582..3c45840 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -1,12 +1,10 @@ import { defineConfig } from 'drizzle-kit'; -if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set'); - export default defineConfig({ out: './drizzle', schema: './src/lib/server/db/schema', dialect: 'postgresql', - dbCredentials: { url: process.env.DATABASE_URL }, + dbCredentials: { url: process.env.DATABASE_URL! || ' ' }, verbose: true, strict: true }); diff --git a/src/lib/server/db/index.ts b/src/lib/server/db/index.ts index 48bf1d1..6849d42 100644 --- a/src/lib/server/db/index.ts +++ b/src/lib/server/db/index.ts @@ -13,10 +13,8 @@ import * as teams from './schema/teams'; import * as users from './schema/users'; import { Pool } from 'pg'; -if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set'); - const pool = new Pool({ - connectionString: env.DATABASE_URL + connectionString: env.DATABASE_URL! }); export const schema = {