Skip to content

Commit c254bf0

Browse files
committed
test: add coverage to docker
1 parent dbbf2de commit c254bf0

File tree

9 files changed

+81
-28
lines changed

9 files changed

+81
-28
lines changed

.env-example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
OPENAI_API_KEY=ADD-YOUR-OPENAI_API_KEY-HERE
2-
ENVIRONMENT=dev
2+
ENVIRONMENT=local
33
DOCKERHUB_USERNAME=ADD-YOUR-DOCKERHUB_USERNAME-HERE
44
DOCKERHUB_ACCESS_TOKEN=ADD-YOUR-DOCKERHUB_ACCESS_TOKEN-HERE
55
LLM_TOOL_CHOICE=required

.github/actions/tests/pre-commit/action.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,40 @@ runs:
2222
- name: Check for pre-commit in requirements
2323
shell: bash
2424
run: |
25-
if ! grep -q "pre-commit" ./requirements/dev.txt; then
26-
echo "pre-commit not found in requirements/dev.txt" >&2
25+
if ! grep -q "pre-commit" ./requirements/local.txt; then
26+
echo "pre-commit not found in requirements/local.txt" >&2
2727
exit 1
2828
fi
2929
3030
- name: Check for black in requirements
3131
shell: bash
3232
run: |
33-
if ! grep -q "black" ./requirements/dev.txt; then
34-
echo "black not found in requirements/dev.txt" >&2
33+
if ! grep -q "black" ./requirements/local.txt; then
34+
echo "black not found in requirements/local.txt" >&2
3535
exit 1
3636
fi
3737
3838
- name: Check for flake8 in requirements
3939
shell: bash
4040
run: |
41-
if ! grep -q "flake8" ./requirements/dev.txt; then
42-
echo "flake8 not found in requirements/dev.txt" >&2
41+
if ! grep -q "flake8" ./requirements/local.txt; then
42+
echo "flake8 not found in requirements/local.txt" >&2
4343
exit 1
4444
fi
4545
4646
- name: Check for flake8-coding in requirements
4747
shell: bash
4848
run: |
49-
if ! grep -q "flake8-coding" ./requirements/dev.txt; then
50-
echo "flake8-coding not found in requirements/dev.txt" >&2
49+
if ! grep -q "flake8-coding" ./requirements/local.txt; then
50+
echo "flake8-coding not found in requirements/local.txt" >&2
5151
exit 1
5252
fi
5353
5454
- name: Cache Python dependencies
5555
uses: actions/cache@v3
5656
with:
5757
path: ~/.cache/pip
58-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements/dev.txt') }}
58+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements/local.txt') }}
5959
restore-keys: |
6060
${{ runner.os }}-pip
6161
@@ -68,7 +68,7 @@ runs:
6868
shell: bash
6969
run: |
7070
python -m pip install --upgrade pip
71-
pip install -r ./requirements/dev.txt
71+
pip install -r ./requirements/local.txt
7272
7373
# see: https://pre-commit.ci/lite.html
7474
- name: pre-commit ci

.github/workflows/precommitVersionBumps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- name: Install dependencies
6767
shell: bash
6868
run: |
69-
pip install -r ./requirements/dev.txt
69+
pip install -r ./requirements/local.txt
7070
pip install -r ./requirements/prod.txt
7171
env:
7272
SITE_PACKAGES_PATH: ${{ env.SITE_PACKAGES_PATH }}

Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,31 @@ LABEL maintainer="Lawrence McDaniel <lpm0073@gmail.com>" \
1414
org.opencontainers.image.documentation="https://FullStackWithLawrence.github.io/agentic-ai-workflow/"
1515

1616

17+
# Environment: local, alpha, beta, next, or production
18+
ARG ENVIRONMENT=local
19+
ENV ENVIRONMENT=$ENVIRONMENT
20+
RUN echo "ENVIRONMENT: $ENVIRONMENT"
21+
1722
FROM base AS requirements
1823

1924
# Set the working directory to /app
2025
WORKDIR /dist
2126

2227
# Copy the current directory contents into the container at /app
2328
COPY requirements/prod.txt requirements.txt
29+
COPY requirements/local.txt local.txt
2430

2531
# Set environment variables
26-
ENV ENVIRONMENT=dev
2732
ENV PYTHONPATH=/dist
2833

2934
# Install any needed packages specified in requirements.txt
3035
RUN pip install --no-cache-dir -r requirements.txt
3136

37+
# Install Python dependencies for the local environment for cases where
38+
# we're going to run python unit tests in the Docker container.
39+
RUN if [ "$ENVIRONMENT" = "local" ] ; then pip install -r local.txt ; fi
40+
41+
3242
FROM requirements AS app
3343

3444
WORKDIR /dist

Makefile

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ init-dev:
5454
make init && \
5555
npm install && \
5656
$(ACTIVATE_VENV) && \
57-
$(PIP) install -r requirements/dev.txt && \
57+
$(PIP) install -r requirements/local.txt && \
5858
deactivate && \
5959
pre-commit install
6060

@@ -72,7 +72,7 @@ clean:
7272
rm -rf venv node_modules app/__pycache__ package-lock.json
7373

7474
docker-build:
75-
docker build -t ${DOCKERHUB_USERNAME}/${REPO_NAME} .
75+
docker build -t ${DOCKERHUB_USERNAME}/${REPO_NAME} . --build-arg ENVIRONMENT=${ENVIRONMENT}
7676

7777
docker-push:
7878
source .env && \
@@ -81,7 +81,46 @@ docker-push:
8181
docker push ${DOCKERHUB_USERNAME}/${REPO_NAME}:latest
8282

8383
docker-run:
84-
docker run -it -e OPENAI_API_KEY=${OPENAI_API_KEY} -e ENVIRONMENT=prod -e MYSQL_HOST=${MYSQL_HOST} -e MYSQL_PORT=${MYSQL_PORT} -e MYSQL_USER=${MYSQL_USER} -e MYSQL_PASSWORD=${MYSQL_PASSWORD} -e MYSQL_DATABASE=${MYSQL_DATABASE} -e MYSQL_CHARSET=${MYSQL_CHARSET} -e LOGGING_LEVEL=${LOGGING_LEVEL} -e LLM_TOOL_CHOICE=${LLM_TOOL_CHOICE} ${DOCKERHUB_USERNAME}/${REPO_NAME}:latest
84+
docker run -it -e OPENAI_API_KEY=${OPENAI_API_KEY} \
85+
-e ENVIRONMENT=prod \
86+
-e MYSQL_HOST=${MYSQL_HOST} \
87+
-e MYSQL_PORT=${MYSQL_PORT} \
88+
-e MYSQL_USER=${MYSQL_USER} \
89+
-e MYSQL_PASSWORD=${MYSQL_PASSWORD} \
90+
-e MYSQL_DATABASE=${MYSQL_DATABASE} \
91+
-e MYSQL_CHARSET=${MYSQL_CHARSET} \
92+
-e LOGGING_LEVEL=${LOGGING_LEVEL} \
93+
-e LLM_TOOL_CHOICE=${LLM_TOOL_CHOICE} ${DOCKERHUB_USERNAME}/${REPO_NAME}:latest
94+
95+
docker-test:
96+
docker run --rm \
97+
-e OPENAI_API_KEY=${OPENAI_API_KEY} \
98+
-e ENVIRONMENT=local \
99+
-e MYSQL_HOST=${MYSQL_HOST} \
100+
-e MYSQL_PORT=${MYSQL_PORT} \
101+
-e MYSQL_USER=${MYSQL_USER} \
102+
-e MYSQL_PASSWORD=${MYSQL_PASSWORD} \
103+
-e MYSQL_DATABASE=${MYSQL_DATABASE} \
104+
-e MYSQL_CHARSET=${MYSQL_CHARSET} \
105+
-e LOGGING_LEVEL=${LOGGING_LEVEL} \
106+
-e LLM_TOOL_CHOICE=${LLM_TOOL_CHOICE} \
107+
${DOCKERHUB_USERNAME}/${REPO_NAME}:latest \
108+
python -m unittest discover -s app/
109+
110+
docker-coverage:
111+
docker run --rm \
112+
-e OPENAI_API_KEY=${OPENAI_API_KEY} \
113+
-e ENVIRONMENT=local \
114+
-e MYSQL_HOST=${MYSQL_HOST} \
115+
-e MYSQL_PORT=${MYSQL_PORT} \
116+
-e MYSQL_USER=${MYSQL_USER} \
117+
-e MYSQL_PASSWORD=${MYSQL_PASSWORD} \
118+
-e MYSQL_DATABASE=${MYSQL_DATABASE} \
119+
-e MYSQL_CHARSET=${MYSQL_CHARSET} \
120+
-e LOGGING_LEVEL=${LOGGING_LEVEL} \
121+
-e LLM_TOOL_CHOICE=${LLM_TOOL_CHOICE} \
122+
${DOCKERHUB_USERNAME}/${REPO_NAME}:latest \
123+
/bin/bash -c "python -m coverage run --source=app -m unittest discover -s app/tests && python -m coverage report && python -m coverage xml"
85124

86125
docker-prune:
87126
@if [ "`docker ps -aq`" ]; then \
@@ -97,13 +136,14 @@ docker-prune:
97136

98137
help:
99138
@echo '===================================================================='
100-
@echo 'analyze - generate code analysis report'
101-
@echo 'release - force a new GitHub release'
102-
@echo 'init - create a Python virtual environment and install prod dependencies'
103-
@echo 'init-dev - install dev dependencies'
104-
@echo 'test - run Python unit tests'
105-
@echo 'lint - run Python linting'
106-
@echo 'clean - destroy the Python virtual environment'
139+
@echo 'analyze - generate code analysis report'
140+
@echo 'release - force a new GitHub release'
141+
@echo 'init - create a Python virtual environment and install prod dependencies'
142+
@echo 'init-dev - install dev dependencies'
143+
@echo 'test - run Python unit tests'
144+
@echo 'lint - run Python linting'
145+
@echo 'clean - destroy the Python virtual environment'
107146
@echo 'docker-build - build the Docker image'
108147
@echo 'docker-push - push the Docker image to DockerHub'
109148
@echo 'docker-run - run the Docker image'
149+
@echo 'docker-test - run the Docker image for testing'

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ python -m app.agent
4444
This application can also run as a Docker container.
4545

4646
```console
47-
make # initializes a .env file for OPENAI_API_KEY and DOCKERHUB_ACCESS_TOKEN
48-
make docker-build # run Docker compose to containerize your application
49-
make docker-run # run the application as a Docker container
47+
make # initializes a .env file for OPENAI_API_KEY and DOCKERHUB_ACCESS_TOKEN
48+
make docker-build # run Docker compose to containerize your application
49+
make docker-test # run all unit tests
50+
make docker-coverage # run coverage analysis
51+
make docker-run # run the application as a Docker container
5052
```
5153

5254
Other Docker commands

doc/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A typical pull request will look like the following:
2727

2828
This project uses pre-commit as a first-pass automated code review / QC process. pre-commit runs a multitude of utilities and checks for code formatting, linting, syntax checking, and ensuring that you don't accidentally push something to GitHub which you'd later regret. Broadly speaking, these checks are aimed at minimizing the extent of commits that contain various kinds of defects and stylistic imperfections that don't belong on the main branch of the project.
2929

30-
Note that many of the pre-commit commands are actually executed by Python which in turn is calling pip-installed packages listed in ./requirements/dev.txt located in the root of the repo. It therefore is important that you first create the Python virtual environment using `make api-init`. It also is a good idea to do a complete 'dry run' of pre-commit, to ensure that your developer environment is correctly setup:
30+
Note that many of the pre-commit commands are actually executed by Python which in turn is calling pip-installed packages listed in ./requirements/local.txt located in the root of the repo. It therefore is important that you first create the Python virtual environment using `make api-init`. It also is a good idea to do a complete 'dry run' of pre-commit, to ensure that your developer environment is correctly setup:
3131

3232
```console
3333
git pull
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ bandit==1.8.6
1919
pydocstringformatter==0.7.5
2020
tox==4.30.2
2121
codespell==2.4.1
22+
coverage==7.11.0

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ python =
1818
3.13: gitlint,py313,flake8,mypy,black,pylint
1919

2020
[testenv]
21-
deps = -rrequirements/dev.txt
21+
deps = -rrequirements/local.txt
2222
commands = pytest
2323

2424
[testenv:flake8]

0 commit comments

Comments
 (0)