add dockerfile

This commit is contained in:
2025-07-28 12:44:19 +02:00
parent 6344142fdd
commit 4591383f87
4 changed files with 110 additions and 2 deletions

31
.dockerignore Normal file
View File

@@ -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

33
Dockerfile Normal file
View File

@@ -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"]

View File

@@ -64,3 +64,49 @@ mlb-overlay-server/
- `bun check-types`: Check TypeScript types across all apps - `bun check-types`: Check TypeScript types across all apps
- `bun db:push`: Push schema changes to database - `bun db:push`: Push schema changes to database
- `bun db:studio`: Open database studio UI - `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.

View File

@@ -924,8 +924,6 @@
"anymatch/picomatch": ["picomatch@2.3.1", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="], "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=="], "lru-cache/yallist": ["yallist@3.1.1", "", {}, "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="],
"recast/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="], "recast/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="],