-
Notifications
You must be signed in to change notification settings - Fork 7
Add dockerfiles to change hosting #268
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d39cd76
add dockerfiles
jmccand d5f0562
ignore root on pip install
jmccand dbfd760
use customizable base url
jmccand e019519
support CORS
jmccand 7658d96
get docker working with env vars
jmccand d97dbdb
add production env example
williamschen23 2814497
support running test in docker as well
jmccand da655be
create profiles
jmccand 48aa023
move nginx config to conf files
jmccand e14fa9a
improve docs
jmccand 4d85a01
Merge branch 'main' into change-hosting
jmccand 28464a4
update system requirements
williamschen23 10f4e1b
update test version
williamschen23 e1c7314
test server as well...
williamschen23 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Git | ||
| .git | ||
| .gitignore | ||
| .github | ||
|
|
||
| # Python | ||
| __pycache__ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| .venv | ||
| *.egg-info/ | ||
| .eggs/ | ||
| dist/ | ||
| build/ | ||
| .pytest_cache/ | ||
| .python-version | ||
|
|
||
| # Node | ||
| node_modules/ | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .npm | ||
| .yarn | ||
| client/node_modules/ | ||
| client/dist/ | ||
| client/.vite/ | ||
| test-client/ | ||
|
|
||
| # Environment | ||
| .env | ||
| .env.local | ||
| .env.*.local | ||
| .flaskenv | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
| .DS_Store | ||
|
|
||
| # Logs | ||
| *.log | ||
| logs/ | ||
|
|
||
| # Database | ||
| *.db | ||
| *.sqlite | ||
| *.sqlite3 | ||
| instance/ | ||
|
|
||
| # Testing | ||
| .coverage | ||
| htmlcov/ | ||
| .tox/ | ||
|
|
||
| # Documentation | ||
| *.md | ||
| !README.md | ||
|
|
||
| # Misc | ||
| *.bak | ||
| *.tmp | ||
| .yamllint |
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
|
|
||
| __pycache__/ | ||
| **__pycache__/ | ||
| node_modules/ | ||
| .env | ||
| client/dist | ||
|
|
||
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
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
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,90 @@ | ||
| services: | ||
| postgres: | ||
| image: postgres:16-alpine | ||
| environment: | ||
| POSTGRES_DB: ${POSTGRES_DB:-shubble} | ||
| POSTGRES_USER: ${POSTGRES_USER:-shubble} | ||
| POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-shubble} | ||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data | ||
| ports: | ||
| - "${POSTGRES_PORT:-5432}:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U shubble"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| redis: | ||
| image: redis:7-alpine | ||
| command: redis-server --appendonly yes | ||
| volumes: | ||
| - redis_data:/data | ||
| ports: | ||
| - "${REDIS_PORT:-6379}:6379" | ||
| healthcheck: | ||
| test: ["CMD", "redis-cli", "ping"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| backend: | ||
| build: | ||
| context: . | ||
| dockerfile: docker/Dockerfile.backend | ||
| ports: | ||
| - "${BACKEND_PORT:-8000}:8000" | ||
| extra_hosts: | ||
| - "localhost:host-gateway" | ||
| environment: | ||
| FRONTEND_URL: ${FRONTEND_URL:-http://localhost:3000} | ||
| DATABASE_URL: ${DATABASE_URL:-postgresql://shubble:shubble@postgres:5432/shubble} | ||
| REDIS_URL: ${REDIS_URL:-redis://redis:6379/0} | ||
| FLASK_ENV: ${FLASK_ENV:-development} | ||
| FLASK_DEBUG: ${FLASK_DEBUG:-true} | ||
| LOG_LEVEL: ${LOG_LEVEL:-INFO} | ||
| API_KEY: ${API_KEY:-} | ||
| SAMSARA_SECRET: ${SAMSARA_SECRET:-} | ||
| depends_on: | ||
| postgres: | ||
| condition: service_healthy | ||
| redis: | ||
| condition: service_healthy | ||
| restart: unless-stopped | ||
|
|
||
| worker: | ||
| build: | ||
| context: . | ||
| dockerfile: docker/Dockerfile.worker | ||
| extra_hosts: | ||
| - "localhost:host-gateway" | ||
| environment: | ||
| DATABASE_URL: ${DATABASE_URL:-postgresql://shubble:shubble@postgres:5432/shubble} | ||
| REDIS_URL: ${REDIS_URL:-redis://redis:6379/0} | ||
| FLASK_ENV: ${FLASK_ENV:-development} | ||
| LOG_LEVEL: ${LOG_LEVEL:-INFO} | ||
| API_KEY: ${API_KEY:-} | ||
| depends_on: | ||
| postgres: | ||
| condition: service_healthy | ||
| redis: | ||
| condition: service_healthy | ||
| backend: | ||
| condition: service_started | ||
| restart: unless-stopped | ||
|
|
||
| frontend: | ||
| build: | ||
| context: . | ||
| dockerfile: docker/Dockerfile.frontend | ||
| ports: | ||
| - "${FRONTEND_PORT:-3000}:80" | ||
| environment: | ||
| VITE_BACKEND_URL: ${VITE_BACKEND_URL:-http://localhost:8000} | ||
| depends_on: | ||
| - backend | ||
| restart: unless-stopped | ||
|
|
||
| volumes: | ||
| postgres_data: | ||
| redis_data: |
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,42 @@ | ||
| # Backend Dockerfile for Shubble Flask API | ||
| FROM python:3.12-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install system dependencies | ||
| RUN apt-get update && apt-get install -y \ | ||
| gcc \ | ||
| postgresql-client \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Copy requirements and install Python dependencies | ||
| COPY requirements.txt . | ||
| RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt | ||
|
|
||
| # Copy application code | ||
| COPY server/ ./server/ | ||
| COPY data/ ./data/ | ||
| COPY migrations/ ./migrations/ | ||
| COPY shubble.py . | ||
|
|
||
| # Create non-root user | ||
| RUN useradd -m -u 1000 shubble && chown -R shubble:shubble /app | ||
| USER shubble | ||
|
|
||
| # Expose port | ||
| EXPOSE 8000 | ||
|
|
||
| # Health check | ||
| HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ | ||
| CMD python -c "import requests; requests.get('http://localhost:8000/api/locations', timeout=5)" | ||
|
|
||
| # Run database migrations and start gunicorn | ||
| CMD flask --app server:create_app db upgrade && \ | ||
| gunicorn shubble:app \ | ||
| --bind 0.0.0.0:8000 \ | ||
| --workers 2 \ | ||
| --threads 4 \ | ||
| --timeout 120 \ | ||
| --log-level ${LOG_LEVEL:-info} \ | ||
| --access-logfile - \ | ||
| --error-logfile - |
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,79 @@ | ||
| # Frontend Dockerfile for Shubble | ||
| FROM node:20-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy package files | ||
| COPY package*.json ./ | ||
| COPY client/package*.json ./client/ | ||
|
|
||
| # Install dependencies | ||
| RUN npm ci | ||
|
|
||
| # Copy source files and data | ||
| COPY client/ ./client/ | ||
| COPY data/ ./data/ | ||
| COPY vite.config.ts ./ | ||
| COPY tsconfig*.json ./ | ||
|
|
||
| # Build the application with a placeholder that will be replaced at runtime | ||
| # This allows the backend URL to be configured via environment variable | ||
| ENV VITE_BACKEND_URL=__VITE_BACKEND_URL__ | ||
| RUN npm run build | ||
|
|
||
| # Production stage with nginx | ||
| FROM nginx:alpine | ||
|
|
||
| # Install gettext for envsubst | ||
| RUN apk add --no-cache gettext | ||
|
|
||
| # Copy built files to nginx | ||
| COPY --from=builder /app/client/dist /usr/share/nginx/html | ||
|
|
||
| # Copy nginx configuration | ||
| COPY <<EOF /etc/nginx/conf.d/default.conf | ||
| server { | ||
| listen 80; | ||
| server_name _; | ||
| root /usr/share/nginx/html; | ||
| index index.html; | ||
|
|
||
| # Enable gzip compression | ||
| gzip on; | ||
| gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; | ||
|
|
||
| # Handle SPA routing | ||
| location / { | ||
| try_files \$uri \$uri/ /index.html; | ||
| } | ||
|
|
||
| # Cache static assets | ||
| location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { | ||
| expires 1y; | ||
| add_header Cache-Control "public, immutable"; | ||
| } | ||
|
|
||
| # Security headers | ||
| add_header X-Frame-Options "SAMEORIGIN" always; | ||
| add_header X-Content-Type-Options "nosniff" always; | ||
| add_header X-XSS-Protection "1; mode=block" always; | ||
| } | ||
| EOF | ||
|
|
||
| # Create entrypoint script to substitute environment variables at runtime | ||
| COPY <<'EOF' /docker-entrypoint.sh | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| # Replace __VITE_BACKEND_URL__ placeholder with actual environment variable value | ||
| find /usr/share/nginx/html -type f -name "*.js" -exec sed -i "s|__VITE_BACKEND_URL__|${VITE_BACKEND_URL:-http://localhost:8000}|g" {} \; | ||
|
|
||
| # Start nginx | ||
| exec nginx -g "daemon off;" | ||
| EOF | ||
|
|
||
| RUN chmod +x /docker-entrypoint.sh | ||
|
|
||
| EXPOSE 80 | ||
|
|
||
| CMD ["/docker-entrypoint.sh"] | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.