Skip to content

Commit

Permalink
feature(package): Docker Compose Refactor.
Browse files Browse the repository at this point in the history
Decided that working with volumes is a pain, decided to use ``extends``
to build off of base.
Added coverage reports.
Added compose down.
Updated coverage report configuration.
  • Loading branch information
acederberg committed Aug 19, 2024
1 parent 4dabfd7 commit 195548e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 58 deletions.
55 changes: 27 additions & 28 deletions .github/workflows/commit_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ jobs:
# More about interpolation: https://docs.docker.com/compose/environment-variables/variable-interpolation/
- name: Setup.
run: |
mkdir --parent docker/.venv
docker_config_path='/home/captura/app/tests/assets/act.yaml'
echo "CAPTURA_CONFIG_CLIENT_TEST=$docker_config_path" > .env
Expand All @@ -129,39 +128,22 @@ jobs:
- name: Start Docker Compose Project.
run: |
docker compose \
--file docker/compose.yaml \
--file docker/compose.ci.yaml \
--env-file .env \
up --detach --quiet-pull
# echo -e "## Permissions on \`.venv\`.\n\n" >> $GITHUB_STEP_SUMMARY
#
# echo -e "In container:\n\n~~~" >> $GITHUB_STEP_SUMMARY
# docker compose \
# --file docker/compose.yaml \
# exec server \
# bash -c "ls -lah ~" >> $GITHUB_STEP_SUMMARY
#
# echo -e "~~~\n\nWithin container venv~~~\n\n" >> $GITHUB_STEP_SUMMARY
# docker compose \
# --file docker/compose.yaml \
# exec server \
# bash -c "ls -lah ~/.venv" >> $GITHUB_STEP_SUMMARY
#
# echo -e "~~~\n\nOn host\n\n~~~" >> $GITHUB_STEP_SUMMARY
# ls -lah docker >> $GITHUB_STEP_SUMMARY
# echo "~~~" >> $GITHUB_STEP_SUMMARY
docker compose \
--file docker/compose.yaml \
--file docker/compose.ci.yaml \
exec server \
bash -c 'mkdir ~/app/.venv && python -m venv ~/app/.venv'
bash -c ' \
mkdir --parents ~/app/.venv \
&& python -m venv ~/app/.venv'
# NOTE: ``act.yaml`` defined everything necessary for the client and server.
- name: Install Dependencies In Server.
run: |
docker compose \
--file docker/compose.yaml \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
Expand All @@ -171,15 +153,16 @@ jobs:
- name: Generate Dummy Data In Server.
run: |
docker compose \
--file docker/compose.yaml \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& poetry run simulatus initialize \
&& poetry run simulatus apply'
echo -e "# Dummy Data Report\n\n~~~" >> $GITHUB_STEP_SUMMARY
docker compose \
--file docker/compose.yaml \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
Expand All @@ -190,9 +173,25 @@ jobs:
- name: Run Tests.
run: |
docker compose \
--file docker/compose.yaml \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& pip install poetry \
&& poetry run pytest --count 1'
&& poetry run coverage run -m pytest --count 1'
continue-on-error: true

- name: Create Coverage Report.
run: |
docker compose \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& poetry run coverage html'
- name: Stop Compose Project.
if: always()
run: docker compose --file docker/compose.ci.yaml down


30 changes: 30 additions & 0 deletions docker/compose.base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# version: '3.9'
name: captura
services:
server:
build:
context: '..'
dockerfile: './docker/dockerfile'
target: development
# NOTE: Should not include shell variables, only those from ``.env``.
environment:
CAPTURA_CONFIG_CLIENT_TEST: "${CAPTURA_CONFIG_CLIENT_TEST-/home/captura/app/configs/client.test.yaml}"
CAPTURA_CONFIG_CLIENT: "${CAPTURA_CONFIG_CLIENT-/home/captura/app/configs/client.yaml}"
CAPTURA_CONFIG_APP: "${CAPTURA_CONFIG_APP-/home/captura/app/configs/app.yaml}"
CAPTURA_CONFIG_APP_TEST: "${CAPTURA_CONFIG_APP_TEST-/home/captura/app/configs/app.test.yaml}"
CAPTURA_FLAKEY: "${CAPTURA_FLAKEY-/home/captura/app/configs/flakey.yaml}"
CAPTURA_PLUGINS_USE: "${CAPTURA_PLUGINS_USE-0}"
ports:
- target: 8080
published: 8080
tty: true
db:
image: mysql:8
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: captura
MYSQL_USER: captura
MYSQL_PASSWORD: changeme


24 changes: 24 additions & 0 deletions docker/compose.ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: captura-ci
services:
server:
# Base should give compose minus volumes and networks (and any references to
# outside).
build:
context: '..'
target: ci
extends:
file: ./compose.base.yaml
service: server
networks:
captura: {}
db:
extends:
file: ./compose.base.yaml
service: db
networks:
captura: {}
networks:
captura:
driver: bridge

32 changes: 7 additions & 25 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,22 @@
name: captura
services:
server:
build:
context: '..'
dockerfile: './docker/dockerfile'
target: development
# NOTE: Should not include shell variables.
environment:
CAPTURA_CONFIG_CLIENT_TEST: "${CAPTURA_CONFIG_CLIENT_TEST-/home/captura/app/config/client.test.yaml}"
CAPTURA_CONFIG_CLIENT: "${CAPTURA_CONFIG_CLIENT-/home/captura/app/config/client.yaml}"
CAPTURA_CONFIG_APP: "${CAPTURA_CONFIG_APP-/home/captura/app/config/app.yaml}"
CAPTURA_CONFIG_APP_TEST: "${CAPTURA_CONFIG_APP_TEST-/home/captura/app/config/app.test.yaml}"
CAPTURA_FLAKEY: "${CAPTURA_FLAKEY-/home/captura/app/config/flakey.yaml}"
CAPTURA_PLUGINS_USE: "${CAPTURA_PLUGINS_USE-0}"
image: acederberg/captura-development:0.1.5
# container_name: captura-server
ports:
- target: 8080
published: 8080
extends:
file: ./compose.base.yaml
service: server
image: acederberg/captura-ci:0.1.5
networks:
captura: {}
tty: true
volumes:
- '.venv:/home/captura/.venv'
- '..:/home/captura/app'
# NOTE: Overwrite the data volumes since they slow down refresh.
- /home/captura/app/docker/.data
- /home/captura/app/docker/.venv
db:
image: mysql:8
# container_name: captura-db
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: captura
MYSQL_USER: captura
MYSQL_PASSWORD: changeme
extends:
file: ./compose.base.yaml
service: db
networks:
captura: {}
volumes:
Expand Down
7 changes: 6 additions & 1 deletion docker/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ COPY ./docker/docker.sh /home/captura/.bashrc

# --------------------------------------------------------------------------- #

FROM base AS production
FROM base AS ci

# NOTE: Assumes that build is occuring at the project root.
COPY --chown=captura:captura ./ /home/captura/app


# --------------------------------------------------------------------------- #

FROM ci AS production

RUN mkdir /home/captura/.captura /home/captura/.captura/logs
COPY ./docker/logging.yaml /home/captura/.captura
COPY ./docker/docker.sh /home/captura/docker.sh
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ push = false
# NOTE: Look at this later: https://docs.pytest.org/en/6.2.x/usage.html#dropping-to-pdb-python-debugger-on-failures
[tool.pytest.ini_options]
testpaths = "tests"
addopts = "--ignore tests/junk --ignore-glob ./tests/test_controllers/test_delete.py --ignore ./tests/test_controllers/test_upsert.py --last-failed --last-failed-no-failures all"
addopts = "--ignore tests/junk --ignore-glob ./tests/test_controllers/test_delete.py --ignore ./tests/test_controllers/test_upsert.py" # --last-failed --last-failed-no-failures all"
count = 10
flakey_ignore = [
"test_not_found_404",
Expand All @@ -164,14 +164,14 @@ flakey_ignore_err = [
# NOTE: Reference https://coverage.readthedocs.io/en/latest/config.html#sample-file
[tool.coverage.run]
branch = true
include = ["./src/app/**/*.py"]
include = ["./src/captura/**/*.py", "./src/legere/**/*.py"]
omit = ["./tests/**/*.py"]


[tool.coverage.report]
fail_under = 75
format = "html"
include = ["./src/app/**/*.py"]
# format = "html"
include = ["./src/captura/**/*.py", "./src/legere/**/*.py"]
omit = ["./tests/**/*.py"]
skip_covered = true
skip_empty = true
Expand Down

0 comments on commit 195548e

Please sign in to comment.