-
Notifications
You must be signed in to change notification settings - Fork 3
Dockerize smallfactory #5
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
Open
reinauer
wants to merge
1
commit into
yusufm:main
Choose a base branch
from
reinauer:docker
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.
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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 @@ | ||
| # SmallFactory Docker Configuration | ||
|
|
||
| # Path to your local data repository (will be mounted into container) | ||
| SF_DATAREPO_PATH=./data | ||
|
|
||
| # Optional: Git repository URL for automatic cloning/syncing | ||
| # SF_GIT_REPO_URL=https://github.com/yourusername/your-plm-data.git | ||
|
|
||
| # Git configuration for commits made from within the container | ||
| SF_GIT_USER_NAME=Your Name | ||
| SF_GIT_USER_EMAIL=your.email@example.com | ||
This file contains hidden or 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,58 @@ | ||
| # Multi-stage build for smallfactory PLM/BOM management tool | ||
| FROM python:3.11-slim as base | ||
|
|
||
| # Install system dependencies including curl for Ollama | ||
| RUN apt-get update && apt-get install -y \ | ||
| git \ | ||
| curl \ | ||
| su-exec \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install Ollama | ||
| RUN curl -fsSL https://ollama.com/install.sh | sh | ||
|
|
||
| # Pre-download the vision model during build to avoid runtime download | ||
| RUN ollama serve & \ | ||
| server_pid=$! && \ | ||
| sleep 5 && \ | ||
| ollama pull qwen2.5vl:3b && \ | ||
| kill $server_pid && \ | ||
| wait | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy requirements and install Python dependencies | ||
| COPY requirements.txt ./ | ||
| COPY web/requirements.txt ./web/ | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
| RUN pip install --no-cache-dir -r web/requirements.txt | ||
| RUN pip install --no-cache-dir gunicorn | ||
|
|
||
| # Copy application code | ||
| COPY . . | ||
|
|
||
| # Copy and set permissions for entrypoint script | ||
| COPY docker-entrypoint.sh /usr/local/bin/ | ||
| RUN chmod +x /usr/local/bin/docker-entrypoint.sh | ||
|
|
||
| # Create a non-root user for security (but don't switch to it yet, Ollama needs root) | ||
| RUN groupadd -r appuser && useradd -r -g appuser appuser | ||
| RUN chown -R appuser:appuser /app | ||
|
|
||
| # Expose port for web interface only (Ollama is internal) | ||
| EXPOSE 8080 | ||
|
|
||
| # Environment variables | ||
| ENV PYTHONPATH=/app | ||
| ENV FLASK_ENV=production | ||
| ENV SF_OLLAMA_BASE_URL=http://localhost:11434 | ||
| ENV SF_VISION_MODEL=qwen2.5vl:3b | ||
|
|
||
| # Health check | ||
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | ||
| CMD python -c "import requests; requests.get('http://localhost:8080')" || exit 1 | ||
|
|
||
| # Set entrypoint to start Ollama and then run Gunicorn | ||
| ENTRYPOINT ["docker-entrypoint.sh"] | ||
| CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--workers", "4", "--timeout", "120", "web.app:app"] |
This file contains hidden or 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,19 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| smallfactory: | ||
| build: . | ||
| ports: | ||
| - "8080:8080" | ||
| volumes: | ||
| # Mount external data repository directory | ||
| - "${SF_DATAREPO_PATH:-./data}:/app/data" | ||
| environment: | ||
| # Git repository URL (optional - for cloning/syncing) | ||
| - SF_GIT_REPO_URL=${SF_GIT_REPO_URL:-} | ||
| # Data repository path inside container | ||
| - SF_DATAREPO_PATH=/app/data | ||
| # Git configuration for commits | ||
| - SF_GIT_USER_NAME=${SF_GIT_USER_NAME:-SmallFactory Docker} | ||
| - SF_GIT_USER_EMAIL=${SF_GIT_USER_EMAIL:-docker@smallfactory.local} | ||
| restart: unless-stopped |
This file contains hidden or 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,41 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Start Ollama in the background as root (required) | ||
| echo "Starting Ollama server..." | ||
| ollama serve & | ||
|
|
||
| # Wait for Ollama to be ready | ||
| echo "Waiting for Ollama to be ready..." | ||
| max_attempts=15 | ||
| attempt=0 | ||
| while ! curl -s http://localhost:11434/api/tags > /dev/null; do | ||
| if [ $attempt -ge $max_attempts ]; then | ||
| echo "ERROR: Ollama failed to start within 30 seconds" | ||
| exit 1 | ||
| fi | ||
| sleep 2 | ||
| attempt=$((attempt + 1)) | ||
| done | ||
|
|
||
| echo "Ollama is ready! Model ${SF_VISION_MODEL} is available." | ||
|
|
||
| # Handle git repository setup | ||
| if [ ! -z "$SF_GIT_REPO_URL" ] && [ ! -d "/app/data/.git" ]; then | ||
| echo "Cloning git repository from $SF_GIT_REPO_URL..." | ||
| git clone "$SF_GIT_REPO_URL" /app/data | ||
| elif [ -d "/app/data" ] && [ ! -d "/app/data/.git" ]; then | ||
| echo "No git repository found in /app/data. You may want to initialize one or set SF_GIT_REPO_URL." | ||
| fi | ||
|
|
||
| # Set git configuration if provided | ||
| if [ ! -z "$SF_GIT_USER_NAME" ] && [ ! -z "$SF_GIT_USER_EMAIL" ]; then | ||
| echo "Configuring git user..." | ||
| git config --global user.name "$SF_GIT_USER_NAME" | ||
| git config --global user.email "$SF_GIT_USER_EMAIL" | ||
| fi | ||
|
|
||
| echo "Starting smallFactory web application as appuser..." | ||
| # Switch to non-root user for the web application | ||
| cd /app | ||
| exec su-exec appuser "$@" |
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.
should we have ability to add a ssh key for git access?