Skip to content

Commit d034f62

Browse files
authored
Build and tests fixes
- Fix poetry config, clean requirements files - Revert to docker-compose - Tune poetry build, adjust project naming/versioning - Make tests run in own container - Fix pytest runtime - Setup newman(postman) tests in container - Fix main/environmental tests issues, make use of profiles - Cleanup Makefile - Github actions/workflow initial fix
1 parent 2334660 commit d034f62

Some content is hidden

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

61 files changed

+2874
-2585
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI/CD Pipeline
22

33
on:
44
push:
5-
branches: [ main, dev, test ]
5+
branches: [main, dev, test]
66
pull_request:
7-
branches: [ main, dev, test ]
7+
branches: [main, dev, test]
88

99
jobs:
1010
format:
@@ -14,7 +14,7 @@ jobs:
1414
- name: Set up Python
1515
uses: actions/setup-python@v4
1616
with:
17-
python-version: 3.11
17+
python-version: 3.12
1818
- name: Setup Poetry
1919
run: |
2020
pip install poetry
@@ -24,10 +24,11 @@ jobs:
2424
uses: actions/cache@v2
2525
id: poetry-cache
2626
with:
27-
path: .venv
27+
path: ./backend/.venv
2828
key: poetry-${{ hashFiles('**/poetry.lock') }}
2929
- if: steps.poetry-cache.outputs.cache-hit != 'true'
30-
run: poetry install --no-interaction --no-root
30+
run: |
31+
poetry install --only main --no-root -C ./backend
3132
- name: Check Poetry configuration
3233
run: make check-toml
3334
- name: Run formatting
@@ -41,7 +42,7 @@ jobs:
4142
- name: Set up Python
4243
uses: actions/setup-python@v4
4344
with:
44-
python-version: 3.11
45+
python-version: 3.12
4546
- name: Setup Poetry
4647
run: |
4748
pip install poetry
@@ -68,9 +69,9 @@ jobs:
6869
- name: Set up Python
6970
uses: actions/setup-python@v4
7071
with:
71-
python-version: 3.11
72+
python-version: 3.12
7273
- name: Setup Poetry
73-
run: |
74+
run: |
7475
pip install poetry
7576
poetry config virtualenvs.create true
7677
poetry config virtualenvs.in-project true
@@ -93,9 +94,9 @@ jobs:
9394
- name: Set up Python
9495
uses: actions/setup-python@v4
9596
with:
96-
python-version: 3.11
97+
python-version: 3.12
9798
- name: Setup Poetry
98-
run: |
99+
run: |
99100
pip install poetry
100101
poetry config virtualenvs.create true
101102
poetry config virtualenvs.in-project true
@@ -127,4 +128,4 @@ jobs:
127128
- name: Deploy to production
128129
run: |
129130
# Add your deployment steps here
130-
echo "Deploying to production"
131+
echo "Deploying to production"

Makefile

Lines changed: 71 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,73 @@ export $(shell sed 's/=.*//' .env)
66
export PYTHONPATH=$(pwd):$(pwd)/vectordbs:$(pwd)/rag_solution
77

88
# Directories
9-
SOURCE_DIR := rag_solution
10-
TEST_DIR := tests
9+
SOURCE_DIR := ./backend/rag_solution
10+
TEST_DIR := ./backend/tests
1111
PROJECT_DIRS := $(SOURCE_DIR) $(TEST_DIR)
1212

1313
# Project info
14-
PROJECT_NAME ?= rag_modulo
14+
PROJECT_NAME ?= rag-modulo
1515
PYTHON_VERSION ?= 3.11
16-
PROJECT_VERSION ?= v$(shell poetry version -s)
16+
PROJECT_VERSION ?= 1.0.0
1717

1818
# Tools
19-
DOCKER_COMPOSE := podman-compose
19+
DOCKER_COMPOSE := docker-compose
2020

2121
# Set a default value for VECTOR_DB if not already set
2222
VECTOR_DB ?= milvus
2323

2424
.DEFAULT_GOAL := help
2525

26-
.PHONY: init-env init check-toml format lint audit test run-services build-app run-app clean all info help api-test install-deps newman-test run-backend run-frontend
26+
.PHONY: init-env build-frontend build-backend build-tests build-all test api-test newman-test all-test run-app run-backend run-frontend run-services stop-containers clean create-volumes logs info help
2727

28+
# Init
2829
init-env:
2930
@touch .env
3031
@echo "PROJECT_NAME=${PROJECT_NAME}" >> .env
3132
@echo "PYTHON_VERSION=${PYTHON_VERSION}" >> .env
3233
@echo "VECTOR_DB=${VECTOR_DB}" >> .env
3334

34-
install-deps:
35-
pip install -r requirements.txt
35+
# Build
36+
build-frontend:
37+
$(DOCKER_COMPOSE) build frontend
3638

37-
init: init-env install-deps
39+
build-backend:
40+
$(DOCKER_COMPOSE) build backend
3841

39-
check-toml:
40-
# No equivalent for pip, so this can be left empty or removed
42+
build-tests:
43+
$(DOCKER_COMPOSE) build test
4144

42-
format:
43-
ruff check $(SOURCE_DIR) && black $(PROJECT_DIRS) && isort $(PROJECT_DIRS)
45+
build-all:
46+
@echo "Building application containers..."
47+
$(DOCKER_COMPOSE) --profile default --profile test build
4448

45-
lint:
46-
ruff check $(SOURCE_DIR)
47-
mypy --install-types --show-error-codes --non-interactive $(SOURCE_DIR)
49+
# Test
50+
test: build-all run-app
51+
$(DOCKER_COMPOSE) run test pytest -v -s -m "not (chromadb or elasticsearch or pinecone or weaviate)" || { echo "Tests failed"; $(MAKE) stop-containers; exit 1; }
4852

49-
audit:
50-
bandit -r $(SOURCE_DIR) -x $(TEST_DIR)
53+
api-test: build-all run-app
54+
$(DOCKER_COMPOSE) run test pytest -v -s -m "api and not (chromadb or elasticsearch or pinecone or weaviate)" || { echo "API Tests failed"; $(MAKE) stop-containers; exit 1; }
5155

52-
test: run-services
53-
pytest $(TEST_DIR) || { echo "Tests failed"; exit 1; }
54-
@trap '$(DOCKER_COMPOSE) down' EXIT; \
55-
echo "Waiting for Docker containers to stop..."
56-
@while docker ps | grep -q "milvus-standalone"; do sleep 1; done
56+
newman-test: build-all run-app
57+
$(DOCKER_COMPOSE) run test newman run tests/postman/rag_modulo_api_collection.json --env-var "backend_base_url=${REACT_APP_API_URL}" || { echo "Postman Tests failed"; $(MAKE) stop-containers; exit 1; }
5758

58-
api-test: run-services
59-
pytest $(TEST_DIR)/api -v -m api || { echo "API Tests failed"; exit 1; }
60-
@trap '$(DOCKER_COMPOSE) down' EXIT; \
61-
echo "Waiting for Docker containers to stop..."
62-
@while docker ps | grep -q "milvus-standalone"; do sleep 1; done
59+
all-test: build-all run-app
60+
$(DOCKER_COMPOSE) run test pytest -v -s -m "not (chromadb or elasticsearch or pinecone or weaviate)" || { echo "Tests failed"; $(MAKE) stop-containers; exit 1; }
61+
$(DOCKER_COMPOSE) run test newman run tests/postman/rag_modulo_api_collection.json --env-var "backend_base_url=${REACT_APP_API_URL}" || { echo "Postman Tests failed"; $(MAKE) stop-containers; exit 1; }
6362

64-
newman-test: run-services
65-
newman run postman/rag_modulo_api_collection.json
66-
@trap '$(DOCKER_COMPOSE) down' EXIT; \
67-
echo "Waiting for Docker containers to stop..."
68-
@while docker ps | grep -q "milvus-standalone"; do sleep 1; done
63+
# Run
64+
run-app: build-all run-backend run-frontend
65+
@echo "All application containers are now running."
6966

70-
create-volumes:
71-
@echo "Creating volume directories with correct permissions..."
72-
@mkdir -p ./volumes/postgres ./volumes/etcd ./volumes/minio ./volumes/milvus
73-
@chmod -R 777 ./volumes
74-
@echo "Volume directories created and permissions set."
67+
run-backend: run-services
68+
@echo "Starting backend..."
69+
$(DOCKER_COMPOSE) up -d backend
70+
@echo "Backend is now running."
71+
72+
run-frontend: run-services
73+
@echo "Starting frontend..."
74+
$(DOCKER_COMPOSE) up -d frontend
75+
@echo "Frontend is now running."
7576

7677
run-services: create-volumes
7778
@if [ -z "$(VECTOR_DB)" ]; then \
@@ -128,34 +129,10 @@ run-services: create-volumes
128129
@echo "Milvus logs saved to milvus.log:"
129130
@$(DOCKER_COMPOSE) logs milvus-standalone > milvus.log
130131

131-
run-tests:
132-
$(DOCKER_COMPOSE) run --rm test pytest $(ARGS)
133-
134-
build-frontend:
135-
docker build -t $(PROJECT_NAME)-frontend -f webui/Dockerfile.frontend ./webui
136-
137-
build-backend:
138-
docker build --build-arg CACHEBUST=$(date +%s) -t $(PROJECT_NAME)-backend --no-cache -f Dockerfile.backend .
139-
140-
build-app:
141-
@echo "Building application containers..."
142-
$(DOCKER_COMPOSE) build
143-
144-
run-backend: run-services
145-
@echo "Starting backend..."
146-
$(DOCKER_COMPOSE) up -d backend
147-
@echo "Backend is now running."
148-
149-
run-frontend: run-services
150-
@echo "Starting frontend..."
151-
$(DOCKER_COMPOSE) up -d frontend
152-
@echo "Frontend is now running."
153-
154-
run-app: build-app run-backend run-frontend
155-
@echo "All application containers are now running."
156-
157-
logs:
158-
$(DOCKER_COMPOSE) logs -f
132+
# Stop / clean
133+
stop-containers:
134+
echo "Stopping containers and removing volumes ..."
135+
$(DOCKER_COMPOSE) down -v
159136

160137
clean:
161138
@echo "Cleaning up Docker Compose resources..."
@@ -164,9 +141,18 @@ clean:
164141
-@podman pod rm -f $(podman pod ps -q) || true
165142
-@podman rm -f $(podman ps -a -q) || true
166143
-@podman volume prune -f || true
144+
-@podman container prune -f || true
167145
rm -rf .pytest_cache .mypy_cache data volumes my_chroma_data tests
168146

169-
all: format lint audit test
147+
# Service / reusable targets
148+
create-volumes:
149+
@echo "Creating volume directories with correct permissions..."
150+
@mkdir -p ./volumes/postgres ./volumes/etcd ./volumes/minio ./volumes/milvus
151+
@chmod -R 777 ./volumes
152+
@echo "Volume directories created and permissions set."
153+
154+
logs:
155+
$(DOCKER_COMPOSE) logs -f
170156

171157
info:
172158
@echo "Project name: ${PROJECT_NAME}"
@@ -178,43 +164,22 @@ help:
178164
@echo "Usage: make [target]"
179165
@echo ""
180166
@echo "Targets:"
181-
@echo " init-env Initialize .env file with default values"
182-
@echo " init Initialize environment and install dependencies"
183-
@echo " install-deps Install project dependencies"
184-
@echo " check-toml Check TOML files for syntax errors"
185-
@echo " format Format code using ruff, black, and isort"
186-
@echo " lint Lint code using ruff and mypy"
187-
@echo " audit Audit code using bandit"
188-
@echo " test Run all tests using pytest"
189-
@echo " api-test Run API tests using pytest"
190-
@echo " newman-test Run API tests using Newman"
191-
@echo " run-services Start services using Docker Compose"
192-
@echo " build-app Build app using Docker Compose"
193-
@echo " run-backend Run backend using Docker Compose"
194-
@echo " run-frontend Run frontend using Docker Compose"
195-
@echo " run-app Run both backend and frontend using Docker Compose"
196-
@echo " logs View logs of running containers"
197-
@echo " clean Clean up Docker Compose volumes and cache"
198-
@echo " all Format, lint, audit, and test"
167+
@echo " init-env Initialize .env file with default values"
168+
@echo " build-frontend Build frontend code/container"
169+
@echo " build-backend Build backend code/container"
170+
@echo " build-tests Build test code/container"
171+
@echo " build-all Build frontend/backend/test code/container"
172+
@echo " test Run all tests using pytest"
173+
@echo " api-test Run API tests using pytest"
174+
@echo " newman-test Run API tests using newman"
175+
@echo " all-test Run all tests using pytest and newman"
176+
@echo " run-app Run both backend and frontend using Docker Compose"
177+
@echo " run-backend Run backend using Docker Compose"
178+
@echo " run-frontend Run frontend using Docker Compose"
179+
@echo " run-services Run services using Docker Compose"
180+
@echo " stop-containers Stop all containers using Docker Compose"
181+
@echo " clean Clean up Docker Compose volumes and cache"
182+
@echo " create-volumes Create folders for container volumes"
183+
@echo " logs View logs of running containers"
199184
@echo " info Display project information"
200-
@echo " help Display this help message"
201-
@echo " dev Start development environment"
202-
@echo " dev-build Build development environment"
203-
@echo " dev-down Stop development environment"
204-
@echo " dev-backend Start backend development server"
205-
@echo " dev-frontend Start frontend development server"
206-
207-
dev:
208-
docker-compose -f docker-compose.dev.yml up
209-
210-
dev-build:
211-
docker-compose -f docker-compose.dev.yml build
212-
213-
dev-down:
214-
docker-compose -f docker-compose.dev.yml down
215-
216-
dev-backend:
217-
uvicorn main:app --reload --host 0.0.0.0 --port 8000
218-
219-
dev-frontend:
220-
cd webui && npm start
185+
@echo " help Display this help message"

0 commit comments

Comments
 (0)