-
Notifications
You must be signed in to change notification settings - Fork 24
feat:Dockerized ml model #125
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Include any files or directories that you don't want to be copied to your | ||
| # container here (e.g., local build artifacts, temporary files, etc.). | ||
| # | ||
| # For more help, visit the .dockerignore file reference guide at | ||
| # https://docs.docker.com/go/build-context-dockerignore/ | ||
|
|
||
| **/.DS_Store | ||
| **/__pycache__ | ||
| **/.venv | ||
| **/.classpath | ||
| **/.dockerignore | ||
| **/.env | ||
| **/.git | ||
| **/.gitignore | ||
| **/.project | ||
| **/.settings | ||
| **/.toolstarget | ||
| **/.vs | ||
| **/.vscode | ||
| **/*.*proj.user | ||
| **/*.dbmdl | ||
| **/*.jfm | ||
| **/bin | ||
| **/charts | ||
| **/docker-compose* | ||
| **/compose.y*ml | ||
| **/Dockerfile* | ||
| **/node_modules | ||
| **/npm-debug.log | ||
| **/obj | ||
| **/secrets.dev.yaml | ||
| **/values.dev.yaml | ||
| LICENSE | ||
| README.md | ||
|
|
||
| __pycache__/ | ||
| *.pyc | ||
| .venv/ | ||
| venv/ | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| data/ | ||
| train_model.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Python cache | ||
| __pycache__/ | ||
| *.py[cod] | ||
|
|
||
| # Virtual environments | ||
| .venv/ | ||
| venv/ | ||
| env/ | ||
|
|
||
| # Dataset | ||
| data/*.csv | ||
|
|
||
| # Trained ML models / artifacts | ||
| *.pkl | ||
|
|
||
| # OS/editor files | ||
| .DS_Store | ||
| .vscode/ | ||
| .idea/ |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||||
| # syntax=docker/dockerfile:1 | ||||||
|
|
||||||
| # Comments are provided throughout this file to help you get started. | ||||||
| # If you need more help, visit the Dockerfile reference guide at | ||||||
| # https://docs.docker.com/go/dockerfile-reference/ | ||||||
|
|
||||||
| # Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 | ||||||
|
|
||||||
| ARG PYTHON_VERSION=3.12 | ||||||
| FROM python:${PYTHON_VERSION}-slim as base | ||||||
|
|
||||||
| # Prevents Python from writing pyc files. | ||||||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||||||
|
|
||||||
| # Keeps Python from buffering stdout and stderr to avoid situations where | ||||||
| # the application crashes without emitting any logs due to buffering. | ||||||
| ENV PYTHONUNBUFFERED=1 | ||||||
|
|
||||||
| WORKDIR /app | ||||||
|
|
||||||
| # Create a non-privileged user that the app will run under. | ||||||
| # See https://docs.docker.com/go/dockerfile-user-best-practices/ | ||||||
| ARG UID=10001 | ||||||
| RUN adduser \ | ||||||
| --disabled-password \ | ||||||
| --gecos "" \ | ||||||
| --home "/nonexistent" \ | ||||||
| --shell "/sbin/nologin" \ | ||||||
| --no-create-home \ | ||||||
| --uid "${UID}" \ | ||||||
| appuser | ||||||
|
|
||||||
| # Download dependencies as a separate step to take advantage of Docker's caching. | ||||||
| # Leverage a cache mount to /root/.cache/pip to speed up subsequent builds. | ||||||
| # Leverage a bind mount to requirements.txt to avoid having to copy them into | ||||||
| # into this layer. | ||||||
| RUN --mount=type=cache,target=/root/.cache/pip \ | ||||||
| --mount=type=bind,source=requirements.txt,target=requirements.txt \ | ||||||
| python -m pip install -r requirements.txt | ||||||
|
|
||||||
| # Switch to the non-privileged user to run the application. | ||||||
| USER appuser | ||||||
|
|
||||||
| # Copy the source code into the container. | ||||||
| COPY api.py . | ||||||
| COPY models ./models | ||||||
|
|
||||||
| # Expose the port that the application listens on. | ||||||
| EXPOSE 8000 | ||||||
|
|
||||||
| # Run the application. | ||||||
| CMD uvicorn 'api:app' --host=0.0.0.0 --port=8000 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,80p' ML/DockerfileRepository: Harsh-vardhan09/AthLead Length of output: 1832 Use exec-form This image has no Proposed fix-CMD uvicorn 'api:app' --host=0.0.0.0 --port=8000
+CMD ["uvicorn", "api:app", "--host=0.0.0.0", "--port=8000"]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ### Building and running your application | ||
|
|
||
| When you're ready, start your application by running: | ||
| `docker compose up --build`. | ||
|
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
for file in \
ML/models/athlete_rank_model.pkl \
ML/models/scaler.pkl \
ML/models/label_encoders.pkl
do
test -f "$file"
git ls-files --error-unmatch "$file" >/dev/null
doneRepository: Harsh-vardhan09/AthLead Length of output: 161 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- tracked model files ---'
git ls-files -- ML/models ML/.gitignore ML/.dockerignore ML/README.Docker.md
printf '%s\n' '--- relevant files ---'
for file in ML/Dockerfile ML/docker-compose.yml ML/README.Docker.md ML/.gitignore ML/.dockerignore ML/train_model.py; do
if test -f "$file"; then
printf '\n--- %s ---\n' "$file"
cat -n "$file"
fi
done
printf '%s\n' '--- Docker and compose references ---'
rg -n --glob '!node_modules' --glob '!dist' \
'COPY|models|athlete_rank_model|scaler\.pkl|label_encoders\.pkl|train_model|download|artifact|compose up' \
ML README.md 2>/dev/null || trueRepository: Harsh-vardhan09/AthLead Length of output: 7038 Document how the model artifacts are supplied before the build. A fresh checkout has none of the three model files. 🤖 Prompt for AI Agents🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
printf '%s\n' '--- ML/README.Docker.md ---'
sed -n '1,20p' ML/README.Docker.md
printf '%s\n' '--- ML/compose.yaml ---'
sed -n '1,220p' ML/compose.yamlRepository: Harsh-vardhan09/AthLead Length of output: 1292 🌐 Web query:
💡 Result: The Docker Compose Citations:
Enable Compose Watch in the documented command.
🤖 Prompt for AI Agents |
||
|
|
||
| Your application will be available at http://localhost:8000. | ||
|
|
||
| ### Deploying your application to the cloud | ||
|
|
||
| First, build your image, e.g.: `docker build -t myapp .`. | ||
| If your cloud uses a different CPU architecture than your development | ||
| machine (e.g., you are on a Mac M1 and your cloud provider is amd64), | ||
| you'll want to build the image for that platform, e.g.: | ||
| `docker build --platform=linux/amd64 -t myapp .`. | ||
|
|
||
| Then, push it to your registry, e.g. `docker push myregistry.com/myapp`. | ||
|
|
||
| Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/) | ||
| docs for more detail on building and pushing. | ||
|
|
||
| ### References | ||
| * [Docker's Python guide](https://docs.docker.com/language/python/) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
|
|
||
| services: | ||
| server: | ||
| build: | ||
| context: . | ||
| ports: | ||
| - 8000:8000 | ||
|
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: printf '%s\n' '--- ML/compose.yaml ---'
sed -n '1,40p' ML/compose.yaml
printf '%s\n' '--- README references to port 8000 ---'
rg -n -C 3 '8000|compose|local service' README.md ML 2>/dev/null | head -120Repository: Harsh-vardhan09/AthLead Length of output: 1519 Security Misconfiguration (CWE-16) Reachability: External · Exploitability: Moderate Bind the development port to loopback. The README documents this as a local service, but 🤖 Prompt for AI Agents |
||
|
|
||
| develop: | ||
| # specify the files to watch for changes | ||
| watch: | ||
|
|
||
| # it'll watch for changes in the backend directory and sync the changes with the container real time | ||
| - path: . | ||
| target: /app | ||
| action: sync | ||
|
Comment on lines
+9
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- ML/compose.yaml ---'
cat -n ML/compose.yaml | sed -n '1,80p'
printf '%s\n' '--- Dockerfiles under ML ---'
fd -i -t f 'Dockerfile' ML -x sh -c 'echo "--- $1"; cat -n "$1" | sed -n "1,160p"' sh {}
printf '%s\n' '--- compose watch-related configuration ---'
rg -n -C 3 'watch:|action:|requirements\.txt|uvicorn|reload' MLRepository: Harsh-vardhan09/AthLead Length of output: 4274 🌐 Web query:
💡 Result: In Docker Compose, the "watch" functionality (configured under the Citations:
🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- ML/api.py ---'
cat -n ML/api.py | sed -n '1,220p'
printf '%s\n' '--- model references ---'
rg -n -C 2 'models|joblib|pickle|torch|load|from |import ' ML/api.py ML/modelsRepository: Harsh-vardhan09/AthLead Length of output: 2184 🌐 Web query:
💡 Result: There is no universal standard for how file monitoring tools handle multiple rules for the same file path, as behavior depends entirely on the specific implementation or software being used. When multiple rules are defined for the same path in file monitoring or synchronization systems—such as Docker Compose watch—the system typically evaluates rules based on the specific configuration structure provided [1]. In configurations like Docker Compose, watch rules are defined as a list, and each entry functions independently based on its path and ignore patterns [1]. Ignore patterns in this context are applied relative to the specific path defined in that rule, meaning they do not necessarily conflict with global rules or rules in other sections unless explicitly nested or defined [1]. If you are encountering a situation where you believe a first-matching rule is ignoring subsequent rules, consider the following: 1. Rule Order: Some systems process lists of rules in the order they appear (sequentially). If a rule matches and triggers an ignore or an action, the system may stop processing further rules for that specific file event. 2. Scope: Check if your ignore rules are scoped globally or to a specific path. As seen in tools like Docker, ignore rules are often defined per-action or per-path [1]. 3. Specific Documentation: Because behavior is not standardized, you must consult the configuration manual for the specific tool you are using (e.g., rsync, inotify-tools, or a CI/CD pipeline) to determine if it employs a "first-match-wins" or "last-match-wins" logic. Citations: Restart the API after source and model changes.
🤖 Prompt for AI Agents |
||
|
|
||
This file was deleted.
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Harsh-vardhan09/AthLead
Length of output: 4271
🌐 Web query:
Docker Compose Watch action sync target directory must be writable by container user documentation💡 Result:
Yes, when using the Docker Compose
watchaction withsync(or variations likesync+restartandsync+exec), the container's user must have write permissions for the specifiedtargetdirectory [1][2][3]. Docker Compose requires this write access so that it can successfully update files within the container's filesystem as changes are detected on the host [1][2]. If the container user lacks the necessary permissions, the synchronization process will fail [3]. To ensure your configuration works correctly, official documentation recommends the following best practices: 1. UseCOPY --chownin yourDockerfileto ensure that the initial content placed into the target directory is owned by the appropriate, non-privileged user that the container will run as [1][2]. 2. If you are running the container as a non-privileged user, verify that both the directory exists and that the user has explicit write permissions to that location [1][2]. If the container user cannot write to the target directory, Compose will be unable to reflect the file synchronization, and you may encounter errors [3]. Whileignorerules are useful for excluding files from being watched, they do not bypass filesystem permission requirements for the directories being scanned or targeted [4][5].Citations:
Make
/appwritable byappuserbefore using Compose Watch.ML/compose.yamlsyncs changes into/app. The Dockerfile switches toappuserbefore copying files, so/appand its contents remain root-owned. Compose Watchsyncrequires a writable target and can fail without it. MoveUSER appuserafter the copies and useCOPY --chown=appuser:appuser, or explicitly change/appownership.🤖 Prompt for AI Agents