From ae6a96d73be0e01dcf9a1e3395b96a89afe4b8cc Mon Sep 17 00:00:00 2001 From: zias Date: Tue, 16 Dec 2025 12:59:43 +0100 Subject: [PATCH] feat:use selfhosted docker --- .dockerignore | 33 +++++++++++++++++++++++++++++ Dockerfile | 46 ++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + svelte.config.js | 2 +- 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5b6189a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,33 @@ +node_modules +.svelte-kit +build +.env +.env.* +!.env.example +!.env.docker +.git +.gitignore +.prettierrc +.prettierignore +.eslintrc +.editorconfig +npm-debug.log +yarn-error.log +pnpm-debug.log +.DS_Store +Thumbs.db +*.log +.vscode +.idea +*.swp +*.swo +*.swn +coverage +.nyc_output +dist +logs +drizzle +docker-compose.yml +Dockerfile +README.md +AGENTS.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4d4ca56 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +# Build stage +FROM node:20-alpine AS builder + +# Install pnpm +RUN npm install -g pnpm + +WORKDIR /app + +# Copy package files +COPY package.json pnpm-lock.yaml ./ + +# Install dependencies +RUN pnpm install --frozen-lockfile + +# Copy source code +COPY . . + +# Build the app +RUN pnpm run build + +# Production stage +FROM node:20-alpine + +# Install pnpm +RUN npm install -g pnpm + +WORKDIR /app + +# Copy package files +COPY package.json pnpm-lock.yaml ./ + +# Install production dependencies only +RUN pnpm install --prod --frozen-lockfile + +# Copy built app from builder +COPY --from=builder /app/build ./build + +# Expose port +EXPOSE 3000 + +# Set environment variables +ENV NODE_ENV=production +ENV ORIGIN=http://localhost:3000 + +# Start the app +CMD ["node", "build"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7b87f98 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,52 @@ +services: + postgres: + image: postgres:16-alpine + container_name: serengo-postgres + restart: unless-stopped + environment: + POSTGRES_USER: serengo + POSTGRES_PASSWORD: serengo_password + POSTGRES_DB: serengo + ports: + - '5432:5432' + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U serengo'] + interval: 10s + timeout: 5s + retries: 5 + + app: + build: + context: . + dockerfile: Dockerfile + container_name: serengo-app + restart: unless-stopped + ports: + - '3000:3000' + environment: + - NODE_ENV=production + - DATABASE_URL=postgresql://serengo:serengo_password@postgres:5432/serengo + - ORIGIN=http://localhost:3000 + # Add your environment variables here or use env_file + - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID} + - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET} + - R2_ACCOUNT_ID=${R2_ACCOUNT_ID} + - R2_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID} + - R2_SECRET_ACCESS_KEY=${R2_SECRET_ACCESS_KEY} + - R2_BUCKET_NAME=${R2_BUCKET_NAME} + - GOOGLE_MAPS_API_KEY=${GOOGLE_MAPS_API_KEY} + - VAPID_PUBLIC_KEY=${VAPID_PUBLIC_KEY} + - VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY} + - VAPID_SUBJECT=${VAPID_SUBJECT} + depends_on: + postgres: + condition: service_healthy + # Uncomment to use .env file + # env_file: + # - .env + +volumes: + postgres_data: + driver: local diff --git a/package.json b/package.json index df063f4..9272d4c 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@lucide/svelte": "^0.544.0", "@oslojs/crypto": "^1.0.1", "@oslojs/encoding": "^1.1.0", + "@sveltejs/adapter-node": "^5.4.0", "@sveltejs/kit": "^2.22.0", "@sveltejs/vite-plugin-svelte": "^6.0.0", "@tailwindcss/vite": "^4.1.13", diff --git a/svelte.config.js b/svelte.config.js index d791a53..5cdc093 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,4 +1,4 @@ -import adapter from '@sveltejs/adapter-vercel'; +import adapter from '@sveltejs/adapter-node'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; /** @type {import('@sveltejs/kit').Config} */