Skip to content

Commit 1442533

Browse files
Merge pull request #22 from agile-learning-institute/v2_refactor
V2 refactor
2 parents 2aca870 + ce25a42 commit 1442533

File tree

436 files changed

+22388
-10776
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

436 files changed

+22388
-10776
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Thumbs.db
5151

5252
# Project specific
5353
tests/
54-
docs/
5554
*.egg-info/
5655
.pytest_cache/
5756
.coverage

.github/workflows/docker-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
context: .
3636
platforms: linux/amd64,linux/arm64
3737
push: true
38-
tags: ghcr.io/agile-learning-institute/stage0_mongodb_api:latest
38+
tags: ghcr.io/agile-learning-institute/mongodb_configurator_api:latest

CONTRIBUTING.md

Lines changed: 0 additions & 199 deletions
This file was deleted.

Dockerfile

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
1-
# Stage 1: Build stage
2-
FROM python:3.12-slim as build
1+
# Use Python 3.12 slim image
2+
FROM python:3.12-slim
33

4-
# Set the working directory in the container
5-
WORKDIR /app
4+
# Set the working directory
5+
WORKDIR /opt/mongo_configurator
66

7-
# Copy the entire context to the container
8-
COPY . .
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
gcc \
10+
&& rm -rf /var/lib/apt/lists/*
911

10-
# Get the current Git branch and build time
11-
RUN DATE=$(date +'%Y%m%d-%H%M%S') && \
12-
echo "${DATE}" > /app/BUILT_AT
12+
# Copy dependency files first for better caching
13+
COPY Pipfile Pipfile.lock ./
1314

14-
# Stage 2: Production stage
15-
FROM python:3.12-slim
15+
# Install pipenv
16+
RUN pip install pipenv
1617

17-
# Set the working directory in the container
18-
WORKDIR /opt/stage0_mongodb_api
18+
# Copy application code
19+
COPY . .
1920

20-
# Copy the entire source code and the BUILT_AT file from the build stage
21-
COPY --from=build /app/ /opt/stage0_mongodb_api/
21+
# Install dependencies
22+
RUN pipenv install --deploy --system
2223

23-
# Install pipenv and dependencies
24-
COPY Pipfile Pipfile.lock /opt/stage0_mongodb_api/
25-
RUN pip install pipenv && pipenv install --deploy --system
24+
# Create build timestamp
25+
RUN echo $(date +'%Y%m%d-%H%M%S') > /opt/mongo_configurator/BUILT_AT
2626

27-
# Install Gunicorn for running the Flask app in production
27+
# Install Gunicorn for production
2828
RUN pip install gunicorn
2929

30-
# Expose the port the app will run on
30+
# Create non-root user for security
31+
RUN useradd --create-home --shell /bin/bash app && \
32+
chown -R app:app /opt/mongo_configurator
33+
34+
# Switch to non-root user
35+
USER app
36+
37+
# Expose the port
3138
EXPOSE 8081
3239

33-
# Set Environment Variables
34-
ENV PYTHONPATH=/opt/stage0_mongodb_api/stage0_mongodb_api
35-
ENV MONGODB_API_PORT=8081
40+
# Set environment variables
41+
ENV PYTHONPATH=/opt/mongo_configurator/configurator
42+
ENV API_PORT=8081
3643

37-
# Command to run the application using Gunicorn
38-
CMD exec gunicorn --bind 0.0.0.0:${MONGODB_API_PORT} --timeout 120 --preload stage0_mongodb_api.server:app
44+
# Command to run the application
45+
CMD ["gunicorn", "--bind", "0.0.0.0:8081", "--timeout", "10", "--preload", "configurator.server:app"]

Pipfile

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,27 @@ verify_ssl = true
44
name = "pypi"
55

66
[scripts]
7-
local = "sh -c 'PYTHONPATH=$(pwd)/stage0_mongodb_api python3 -m server'"
8-
debug = "sh -c 'PYTHONPATH=$(pwd)/stage0_mongodb_api LOGGING_LEVEL=DEBUG python3 -m server'"
9-
batch = "sh -c 'PYTHONPATH=$(pwd)/stage0_mongodb_api AUTO_PROCESS=True EXIT_AFTER_PROCESSING=True LOAD_TEST_DATA=True python3 -m server'"
10-
test = "sh -c 'PYTHONPATH=$(pwd)/stage0_mongodb_api LOGGING_LEVEL=CRITICAL coverage run -m unittest discover -s ./tests -p \"test_*.py\" -v && echo \"\\n=== COVERAGE REPORT ===\" && coverage report && coverage html'"
11-
stepci-observability = "stepci run ./tests/stepci/observability.yaml"
12-
stepci-small = "stepci run ./tests/stepci/small_sample.yaml"
13-
stepci-large = "stepci run ./tests/stepci/large_sample.yaml"
14-
db-drop = "python tests/db_util.py drop"
15-
db-drop-silent = "python tests/db_util.py drop --passphrase DROP_DROWSSAP_YEK"
16-
db-compare = "python tests/db_util.py compare"
17-
db-harvest = "python tests/db_util.py harvest"
18-
build = "docker build --tag ghcr.io/agile-learning-institute/stage0_mongodb_api:latest ."
19-
service = "sh -c 'pipenv run down && docker compose --profile mongodb up --detach && echo `Visit http://localhost:8082/`'"
20-
database = "sh -c 'pipenv run down && docker compose --profile mongodb-only up --detach'"
21-
down = "docker compose down mongodb_spa mongodb_api mongodb"
7+
local = "sh -c 'PYTHONPATH=$(pwd)/configurator BUILT_AT=Local LOAD_TEST_DATA=True python3 -m server'"
8+
debug = "sh -c 'PYTHONPATH=$(pwd)/configurator BUILT_AT=Local LOAD_TEST_DATA=True LOGGING_LEVEL=DEBUG python3 -m server'"
9+
batch = "sh -c 'PYTHONPATH=$(pwd)/configurator AUTO_PROCESS=True EXIT_AFTER_PROCESSING=True LOAD_TEST_DATA=True python3 -m server'"
10+
test = "sh -c 'PYTHONPATH=$(pwd)/configurator LOGGING_LEVEL=CRITICAL coverage run -m unittest discover -s ./tests -p \"test_*.py\" -v && echo \"\\n=== COVERAGE REPORT ===\" && coverage report && coverage html'"
11+
stepci = "stepci run ./tests/stepci/workflow.yaml"
12+
container = "docker build --tag ghcr.io/agile-learning-institute/mongodb_configurator_api:latest ."
13+
database = "sh -c 'pipenv run down && docker compose --profile mongodb up --detach'"
14+
api = "sh -c 'pipenv run down && docker compose --profile configurator-api up --detach'"
15+
service = "sh -c 'pipenv run down && docker compose --profile configurator up --detach && echo `Visit http://localhost:8082/`'"
16+
down = "docker compose down mongodb configurator_api configurator_spa"
2217

2318
[packages]
2419
python-dotenv = "*"
2520
flask = "*"
2621
prometheus-flask-exporter = "*"
2722
pymongo = "*"
28-
stage0-py-utils = "*"
2923
pyyaml = ">=6.0.1"
30-
stage0-mongodb-api = {file = ".", editable = true}
3124

3225
[dev-packages]
3326
coverage = "*"
27+
pytest = "*"
3428

3529
[requires]
3630
python_version = "3.12"

0 commit comments

Comments
 (0)