-
Notifications
You must be signed in to change notification settings - Fork 5
Harden security of the app #32
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
Merged
Merged
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 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,28 +1,62 @@ | ||
| FROM ubuntu:latest | ||
| # Single-stage Dockerfile using slim Python base | ||
| FROM python:3.11-slim | ||
|
|
||
| COPY . ./app | ||
| WORKDIR /app | ||
|
|
||
| RUN apt update; apt install -y wget lsb-release software-properties-common gnupg curl ca-certificates | ||
|
|
||
| RUN wget -qO- https://apt.llvm.org/llvm.sh | bash -s -- 21 | ||
| RUN apt install -y libmlir-21-dev mlir-21-tools | ||
| # Environment variables | ||
| ENV DEBIAN_FRONTEND=noninteractive \ | ||
| PYTHONUNBUFFERED=1 \ | ||
| PIP_NO_CACHE_DIR=1 \ | ||
| PIP_DEFAULT_TIMEOUT=100 \ | ||
| NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - | ||
| RUN apt install -y nodejs | ||
| RUN npm install | ||
| ARG APP_ENV=production | ||
| ENV NODE_ENV=$APP_ENV | ||
|
|
||
| RUN add-apt-repository -y ppa:deadsnakes/ppa; apt install -y python3-pip python3.11-venv | ||
|
|
||
| RUN python3.11 -m venv mlir_venv | ||
| WORKDIR /app | ||
|
|
||
| RUN mlir_venv/bin/pip install --upgrade pip | ||
| RUN mlir_venv/bin/pip install --pre torch-mlir torchvision \ | ||
| --extra-index-url https://download.pytorch.org/whl/nightly/cpu \ | ||
| -f https://github.com/llvm/torch-mlir-release/releases/expanded_assets/dev-wheels | ||
| # Install minimal tooling | ||
| RUN apt-get update && \ | ||
| apt-get install -y --no-install-recommends \ | ||
| ca-certificates wget curl gnupg lsb-release software-properties-common && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN mlir_venv/bin/pip install fastapi uvicorn pytest httpx | ||
| # Add LLVM 21 repository | ||
| RUN wget -qO- https://apt.llvm.org/llvm.sh | bash -s -- 21 | ||
|
|
||
| # Add Node.js 20 repository and install runtime deps | ||
| RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ | ||
| apt-get update && \ | ||
| apt-get install -y --no-install-recommends \ | ||
| libmlir-21-dev mlir-21-tools nodejs && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Copy application code | ||
| COPY --chown=10001:10001 . /app | ||
|
|
||
| # Install JS dependencies, then install 'concurrently' globally | ||
| RUN npm install && \ | ||
| npm install -g concurrently | ||
|
|
||
| # Create Python venv and install Python packages | ||
| RUN python3 -m venv /opt/venv && \ | ||
| /opt/venv/bin/pip install --upgrade pip setuptools wheel && \ | ||
| /opt/venv/bin/pip install --pre torch-mlir torchvision \ | ||
| --extra-index-url=https://download.pytorch.org/whl/nightly/cpu \ | ||
| -f https://github.com/llvm/torch-mlir-release/releases/expanded_assets/dev-wheels && \ | ||
| /opt/venv/bin/pip install fastapi uvicorn pytest httpx | ||
|
|
||
| # Create non-root user and fix permissions | ||
| RUN useradd -u 10001 -m --shell /usr/sbin/nologin appuser && \ | ||
| mkdir -p /home/appuser/.cache && \ | ||
| chown -R appuser:appuser /home/appuser/.cache /app | ||
| USER appuser | ||
|
|
||
| # Update PATH for venv and LLVM | ||
| ENV PATH="/opt/venv/bin:/usr/lib/llvm-21/bin:$PATH" | ||
|
|
||
| # Expose ports and add healthcheck | ||
| EXPOSE 3000 8000 | ||
| HEALTHCHECK --interval=30s --timeout=5s --start-period=5s \ | ||
| CMD curl -f http://localhost:8000/health || exit 1 | ||
|
|
||
| CMD ["npm", "run", "start:all"] | ||
| # Default to interactive shell | ||
| CMD ["/bin/sh"] |
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,11 @@ | ||
| const { execSync } = require("child_process"); | ||
|
|
||
| const mode = process.env.NODE_ENV; | ||
|
|
||
| if (mode === "development") { | ||
| console.log("Running in development mode..."); | ||
| execSync("npm run dev:all", { stdio: "inherit" }); | ||
| } else { | ||
| console.log("Running in production mode..."); | ||
| execSync("npm run start:all", { stdio: "inherit" }); | ||
| } |
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
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.