-
Notifications
You must be signed in to change notification settings - Fork 623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/docker support #90
Open
dbsectrainer
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
dbsectrainer:feature/docker-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+347
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Version control | ||
.git | ||
.gitignore | ||
|
||
# Environment files | ||
.env | ||
config/api-keys.env | ||
|
||
# Python | ||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
.Python | ||
env/ | ||
venv/ | ||
.env/ | ||
.venv/ | ||
|
||
# IDE | ||
.idea/ | ||
.vscode/ | ||
*.swp | ||
*.swo | ||
|
||
# OS | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Stage 1: Development environment | ||
FROM python:3.11-slim as development | ||
|
||
# Install system dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
curl \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Node.js and yarn | ||
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | ||
&& apt-get install -y nodejs \ | ||
&& npm install -g yarn | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Create directory for API keys | ||
RUN mkdir -p /app/config | ||
|
||
# Copy entrypoint script | ||
COPY docker-entrypoint.sh /app/ | ||
RUN chmod +x /app/docker-entrypoint.sh | ||
|
||
# Install Python dependencies | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Install Node.js dependencies | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install | ||
|
||
# Copy source code | ||
COPY . . | ||
|
||
# Expose ports for both backend and frontend development | ||
EXPOSE 5000 5173 | ||
|
||
# Set environment variables | ||
ENV PORT=5000 | ||
ENV CONFIG_DIR=/app/config | ||
ENV NODE_ENV=development | ||
|
||
# Use entrypoint script | ||
ENTRYPOINT ["/app/docker-entrypoint.sh"] | ||
|
||
# Stage 2: Production environment | ||
FROM python:3.11-slim as production | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Create directory for API keys | ||
RUN mkdir -p /app/config | ||
|
||
# Copy entrypoint script | ||
COPY docker-entrypoint.sh /app/ | ||
RUN chmod +x /app/docker-entrypoint.sh | ||
|
||
# Install data_formulator package | ||
RUN pip install --no-cache-dir data_formulator | ||
|
||
# Expose backend port | ||
EXPOSE 5000 | ||
|
||
# Set environment variables | ||
ENV PORT=5000 | ||
ENV CONFIG_DIR=/app/config | ||
ENV NODE_ENV=production | ||
|
||
# Use entrypoint script | ||
ENTRYPOINT ["/app/docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# Docker Support for Data Formulator | ||
|
||
This directory contains Docker configuration for running Data Formulator in both development and production environments. | ||
|
||
## Quick Start | ||
|
||
1. Clone the repository: | ||
```bash | ||
git clone https://github.com/microsoft/data-formulator.git | ||
cd data-formulator | ||
``` | ||
|
||
2. Configure your API keys: | ||
- Copy the template: `cp docker/config/api-keys.env.template docker/config/api-keys.env` | ||
- Edit `docker/config/api-keys.env` with your API keys: | ||
```env | ||
OPENAI_API_KEY=your_openai_key | ||
AZURE_API_KEY=your_azure_key | ||
ANTHROPIC_API_KEY=your_anthropic_key | ||
``` | ||
|
||
## Development Mode | ||
|
||
Development mode provides hot-reloading for both frontend and backend changes. | ||
|
||
1. Start the development environment: | ||
```bash | ||
docker compose -f docker/docker-compose.yml up data-formulator-dev | ||
``` | ||
|
||
2. Access the development servers: | ||
- Frontend: http://localhost:5173 (with hot-reloading) | ||
- Backend: http://localhost:5000 | ||
|
||
3. Development Features: | ||
- Live reload on frontend changes | ||
- Source code mounted from host | ||
- Node modules persisted in Docker volume | ||
- Both frontend and backend servers running | ||
|
||
## Production Mode | ||
|
||
Production mode runs the optimized build for deployment. | ||
|
||
1. Start the production environment: | ||
```bash | ||
docker compose -f docker/docker-compose.yml up data-formulator | ||
``` | ||
|
||
2. Access Data Formulator at http://localhost:5000 | ||
|
||
## Configuration | ||
|
||
### Environment Variables | ||
|
||
- `PORT`: The port to run Data Formulator on (default: 5000) | ||
- `NODE_ENV`: Environment mode ('development' or 'production') | ||
- `OPENAI_API_KEY`: Your OpenAI API key | ||
- `AZURE_API_KEY`: Your Azure API key | ||
- `ANTHROPIC_API_KEY`: Your Anthropic API key | ||
|
||
### Custom Port Configuration | ||
|
||
1. Update ports in docker-compose.yml: | ||
```yaml | ||
ports: | ||
- "8080:5000" # For production | ||
# For development: | ||
- "8080:5000" # Backend | ||
- "5173:5173" # Frontend dev server | ||
``` | ||
|
||
2. Or use environment variable: | ||
```bash | ||
PORT=8080 docker compose -f docker/docker-compose.yml up data-formulator | ||
``` | ||
|
||
## Building | ||
|
||
### Development Build | ||
```bash | ||
docker compose -f docker/docker-compose.yml build data-formulator-dev | ||
``` | ||
|
||
### Production Build | ||
```bash | ||
docker compose -f docker/docker-compose.yml build data-formulator | ||
``` | ||
|
||
## Testing | ||
|
||
1. Run tests in development container: | ||
```bash | ||
docker compose -f docker/docker-compose.yml run --rm data-formulator-dev yarn test | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
1. Permission Issues: | ||
- Ensure the config directory exists: `mkdir -p docker/config` | ||
- Set proper permissions: `chmod 644 docker/config/api-keys.env` | ||
|
||
2. Container Startup Issues: | ||
- Check logs: `docker compose -f docker/docker-compose.yml logs` | ||
- Verify API keys in docker/config/api-keys.env | ||
- Ensure no conflicting services on ports 5000 or 5173 | ||
|
||
3. Development Mode Issues: | ||
- Clear node_modules volume: `docker compose -f docker/docker-compose.yml down -v` | ||
- Rebuild development container: `docker compose -f docker/docker-compose.yml build --no-cache data-formulator-dev` | ||
|
||
4. Hot Reload Not Working: | ||
- Ensure proper volume mounts in docker-compose.yml | ||
- Check frontend console for errors | ||
- Verify file permissions on mounted directories | ||
|
||
## Contributing | ||
|
||
When contributing Docker-related changes: | ||
1. Test both development and production builds | ||
2. Verify hot-reloading functionality | ||
3. Update documentation for any new features or changes | ||
4. Follow the project's coding standards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Data Formulator API Keys | ||
# Rename this file to api-keys.env and replace with your actual keys | ||
|
||
# OpenAI API Key | ||
OPENAI_API_KEY=your_openai_key_here | ||
|
||
# Azure API Key | ||
AZURE_API_KEY=your_azure_key_here | ||
|
||
# Anthropic API Key | ||
ANTHROPIC_API_KEY=your_anthropic_key_here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
version: '3.8' | ||
|
||
services: | ||
# Development service with hot-reloading | ||
data-formulator-dev: | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile | ||
target: development | ||
ports: | ||
- "5000:5000" # Backend port | ||
- "5173:5173" # Frontend development port | ||
volumes: | ||
- ..:/app # Mount source code for development | ||
- ./config:/app/config # Mount config directory | ||
- node_modules:/app/node_modules # Persist node_modules | ||
environment: | ||
- PORT=5000 | ||
- NODE_ENV=development | ||
# Uncomment and set your API keys as needed: | ||
# - OPENAI_API_KEY=your_key_here | ||
# - AZURE_API_KEY=your_key_here | ||
# - ANTHROPIC_API_KEY=your_key_here | ||
command: sh -c "yarn && yarn start" # Start in development mode | ||
restart: unless-stopped | ||
|
||
# Production service | ||
data-formulator: | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile | ||
target: production | ||
ports: | ||
- "5000:5000" | ||
volumes: | ||
- ./config:/app/config | ||
environment: | ||
- PORT=5000 | ||
- NODE_ENV=production | ||
# Uncomment and set your API keys as needed: | ||
# - OPENAI_API_KEY=your_key_here | ||
# - AZURE_API_KEY=your_key_here | ||
# - ANTHROPIC_API_KEY=your_key_here | ||
restart: unless-stopped | ||
|
||
volumes: | ||
node_modules: # Named volume for node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Create api-keys.env if it doesn't exist | ||
if [ ! -f "$CONFIG_DIR/api-keys.env" ]; then | ||
touch "$CONFIG_DIR/api-keys.env" | ||
fi | ||
|
||
# Export environment variables from api-keys.env | ||
if [ -f "$CONFIG_DIR/api-keys.env" ]; then | ||
export $(cat "$CONFIG_DIR/api-keys.env" | xargs) | ||
fi | ||
|
||
# Function to start the development server | ||
start_dev() { | ||
echo "Starting Data Formulator in development mode..." | ||
# Start the backend server | ||
python -m data_formulator --port $PORT & | ||
# Start the frontend development server | ||
yarn start | ||
} | ||
|
||
# Function to start the production server | ||
start_prod() { | ||
echo "Starting Data Formulator in production mode..." | ||
exec python -m data_formulator --port $PORT | ||
} | ||
|
||
# Check environment and start appropriate server | ||
if [ "$NODE_ENV" = "development" ]; then | ||
start_dev | ||
else | ||
start_prod | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why you use Node v18 here? How about using the more recent v20 (maintenance LTS) or v22 (active LTS)? https://nodejs.org/en/about/previous-releases