diff --git a/.github/workflows/commit_checks.yaml b/.github/workflows/commit_checks.yaml index 2302bf2..7fba803 100644 --- a/.github/workflows/commit_checks.yaml +++ b/.github/workflows/commit_checks.yaml @@ -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 @@ -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 \ @@ -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 \ @@ -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 + + diff --git a/docker/compose.base.yaml b/docker/compose.base.yaml new file mode 100644 index 0000000..f3a0721 --- /dev/null +++ b/docker/compose.base.yaml @@ -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 + + diff --git a/docker/compose.ci.yaml b/docker/compose.ci.yaml new file mode 100644 index 0000000..4d5c4ac --- /dev/null +++ b/docker/compose.ci.yaml @@ -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 + diff --git a/docker/compose.yaml b/docker/compose.yaml index d0e2bd6..2810674 100644 --- a/docker/compose.yaml +++ b/docker/compose.yaml @@ -3,26 +3,12 @@ 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' @@ -30,13 +16,9 @@ services: - /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: diff --git a/docker/dockerfile b/docker/dockerfile index 061ec96..0ad9620 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -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 diff --git a/pyproject.toml b/pyproject.toml index ca91561..e686e38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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