From 4591383f875b1184100f7e676b529fe5cc06fc1e Mon Sep 17 00:00:00 2001 From: Andres Date: Mon, 28 Jul 2025 12:44:19 +0200 Subject: [PATCH] add dockerfile --- .dockerignore | 31 +++++++++++++++++++++++++++++++ Dockerfile | 33 +++++++++++++++++++++++++++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ bun.lock | 2 -- 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..86b07cf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# Dependencies +node_modules +**/node_modules + +# Build outputs +**/dist +**/build +**/.next +**/.turbo + +# Development files +.git +.github +.vscode +.idea +**/.env.local +**/.env.development + +# Logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +**/*.log + +# Misc +.DS_Store +**/.DS_Store +Dockerfile +.dockerignore +README.md +**/README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2fec6ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM oven/bun:1.2.15 as base + +# Set working directory +WORKDIR /app + +# Copy package.json files for all workspaces +COPY package.json bun.lock ./ +COPY apps/server/package.json ./apps/server/ +COPY apps/web/package.json ./apps/web/ + +# Install dependencies +RUN bun install --frozen-lockfile + +# Copy the rest of the application +COPY . . + +# Build the server application +RUN bun run build --filter server + +# Expose ports for API and WebSocket servers +EXPOSE 3000 4000 + +# Set environment variables +ENV NODE_ENV=production + +# Use a non-root user for better security +USER bun + +# Set the working directory to the server app +WORKDIR /app/apps/server + +# Start the server +CMD ["bun", "run", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 3e23dae..8dd399e 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,49 @@ mlb-overlay-server/ - `bun check-types`: Check TypeScript types across all apps - `bun db:push`: Push schema changes to database - `bun db:studio`: Open database studio UI + +## Docker + +This project includes a Dockerfile to build and run the server application in a containerized environment. + +### Building the Docker Image + +To build the Docker image, run the following command from the project root: + +```bash +docker build -t mlb-overlay-server . +``` + +### Running the Docker Container + +To run the Docker container: + +```bash +docker run -p 3000:3000 -p 4000:4000 --env-file ./apps/server/.env mlb-overlay-server +``` + +This will: +- Map port 3000 (API server) from the container to port 3000 on your host machine +- Map port 4000 (WebSocket server) from the container to port 4000 on your host machine +- Use the environment variables from your local .env file + +### Environment Variables + +The Docker container requires the following environment variables: + +- `DATABASE_URL`: PostgreSQL connection string +- `CORS_ORIGIN`: CORS origin setting +- `BETTER_AUTH_SECRET`: Secret key for authentication +- `BETTER_AUTH_URL`: URL for authentication service + +You can provide these variables in several ways: +1. Using an env file with `--env-file` as shown above +2. Setting them directly with `-e` flags: + ```bash + docker run -p 3000:3000 -p 4000:4000 -e DATABASE_URL=postgres://... -e CORS_ORIGIN=* mlb-overlay-server + ``` +3. Creating a custom .env file specifically for Docker + +### Docker Compose (Optional) + +For a more complete setup, you can create a docker-compose.yml file to manage the application and its dependencies. diff --git a/bun.lock b/bun.lock index b27dbd3..ebc47d3 100644 --- a/bun.lock +++ b/bun.lock @@ -924,8 +924,6 @@ "anymatch/picomatch": ["picomatch@2.3.1", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="], - "esbuild-register/debug": ["debug@4.4.1", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ=="], - "lru-cache/yallist": ["yallist@3.1.1", "", {}, "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="], "recast/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="],