Skip to content

Commit

Permalink
Run unit tests in CI only (#362)
Browse files Browse the repository at this point in the history
* Avoid running tests on DEV start

* Run tests on CI

* Update REAMDE
  • Loading branch information
minottic authored Nov 13, 2024
1 parent 87653f1 commit c69952c
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 17 deletions.
13 changes: 13 additions & 0 deletions .github/compose.dev.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
frontend:
volumes:
- ./entrypoints/npm_tests.sh:/docker-entrypoints/9.sh
searchapi:
volumes:
- ./entrypoints/npm_tests.sh:/docker-entrypoints/9.sh
landingpage:
volumes:
- ./entrypoints/npm_tests.sh:/docker-entrypoints/9.sh
backend:
volumes:
- ./services/backend/services/${BE_VERSION}/entrypoints/tests.sh:/docker-entrypoints/9.sh
4 changes: 3 additions & 1 deletion .github/workflows/compose_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,6 @@ jobs:
export OIDC_ENABLED=${{ matrix.OIDC_ENABLED }}
export BE_VERSION=${{ matrix.BE_VERSION }}
export DEV=${{ matrix.DEV }}
docker compose --profile '*' up --wait --wait-timeout 600
docker compose --profile '*' \
-f compose.yaml ${DEV:+-f .github/compose.dev.test.yaml} \
up --wait --wait-timeout 600
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ After optionally setting any configuration option, one can still select the serv

To provide a consistent environment where developers can work, the `DEV=true` option creates the SciCat services (see DEV from [here](#docker-compose-env-variables) for the list), but instead of running them, it just creates the base environment that each service requires. For example, for the `backend`, instead of running the web server, it creates a NODE environment with `git` where one can develop and run the unit tests. This is useful as often differences in environments create collaboration problems. It should also provide an example of the configuration for running tests. Please refer to the services' README for additional information, or to the Dockerfile `CMD` of the components' GitHub repo if not specified otherwise. The `DEV=true` affects the SciCat services only.

Please be patient when using DEV as each container runs unit tests as part of the init, which might take a little to finish. This is done to test the compatibility of upstream/latest with the `docker compose` (see warning). To see if any special precaution is required to run the tests, refer to the `entrypoints/tests.sh` mounted by the volumes. To disable test execution, just comment the `entrypoints/tests.sh` mount on the respective service.
Please be patient when using DEV as each container sets the env for dev, including the requirements for testing, which might take a little to finish. To see if any special precaution is required to run the tests, refer to the [compose.dev.test.yaml](.github/compose.dev.test.yaml) file where tests files are referenced and refer to their content. **When DEV=true**, if you want to run tests when the containers start, you can do so by including the `compose.dev.test.yaml` compose file.
```bash
docker compose -f compose.yaml -f .github/compose.dev.test.yaml ...
```


It is very convenient if using [VSCode](https://code.visualstudio.com/docs/devcontainers/attach-container), as, after the docker services are running, one can attach to it and start developing using all VSCode features, including version control and debugging.

:warning: To prevent git unpushed changes from being lost when a container is restarted, the work folder of each service, when in DEV mode, is mounted to a docker volume, with naming convention `${COMPOSE_PROJECT_NAME}_<service>_dev`. Make sure, before removing docker volumes to push the relevant changes.
:warning: To prevent git unpushed changes from being lost when a container is restarted, the work folder of each service, when in DEV mode, is mounted to a docker volume, with naming convention `${COMPOSE_PROJECT_NAME}_<service>_dev`. Make sure, to commit and push frequently, especially before removing docker volumes to push the relevant changes.

:warning: As the DEV containers pull from upstream/latest, there is no guarantee of their functioning outside of releases. If they fail to start, try, as a first option, to build the image from a tag (e.g. [build context](./services/frontend/compose.dev.yaml)) using the [TAG](https://docs.docker.com/reference/cli/docker/image/build/#git-repositories) and then git checkout to that tag (e.g. set [GITHUB_REPO](./services/frontend/compose.dev.yaml) including the branch using the same syntax and value as the build context).

Expand Down
2 changes: 0 additions & 2 deletions entrypoints/karma_tests.sh → entrypoints/add_chrome.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/sh

apk update && apk add chromium

npm run test
3 changes: 3 additions & 0 deletions entrypoints/npm_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

npm run test
1 change: 0 additions & 1 deletion services/backend/services/v3/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ services:
- ./config/datasources.dev.json:/config/datasources.1.json
- v3_dev:/home/node/app
- ${PWD}/entrypoints/npm_ci.sh:/docker-entrypoints/1.sh
- ./entrypoints/tests.sh:/docker-entrypoints/2.sh

volumes:
v3_dev:
Expand Down
3 changes: 0 additions & 3 deletions services/backend/services/v3/entrypoints/tests.sh

This file was deleted.

1 change: 1 addition & 0 deletions services/backend/services/v3/entrypoints/tests.sh
1 change: 0 additions & 1 deletion services/backend/services/v4/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ services:
- v4_dev:/home/node/app
- ${PWD}/entrypoints/setup_git.sh:/docker-entrypoints/2.sh
- ./config/functionalAccounts.dev.json:/home/node/app/functionalAccounts.json
- ./entrypoints/tests.sh:/docker-entrypoints/3.sh
env_file:
- ./config/.dev.env
healthcheck:
Expand Down
2 changes: 1 addition & 1 deletion services/frontend/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- frontend_dev:/frontend
- ${PWD}/entrypoints/infinite_loop.sh:/usr/local/bin/infinite_loop.sh
- ${PWD}/entrypoints/setup_git.sh:/docker-entrypoints/0.sh
- ${PWD}/entrypoints/karma_tests.sh:/docker-entrypoints/2.sh
- ${PWD}/entrypoints/add_chrome.sh:/docker-entrypoints/2.sh
labels:
- traefik.http.services.frontend.loadbalancer.server.port=4200
healthcheck:
Expand Down
2 changes: 1 addition & 1 deletion services/landingpage/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- ${PWD}/entrypoints/infinite_loop.sh:/usr/local/bin/infinite_loop.sh
- ${PWD}/entrypoints/setup_git.sh:/docker-entrypoints/0.sh
- ${PWD}/entrypoints/merge_json.sh:/docker-entrypoints/1.sh
- ${PWD}/entrypoints/karma_tests.sh:/docker-entrypoints/2.sh
- ${PWD}/entrypoints/add_chrome.sh:/docker-entrypoints/2.sh
entrypoint: loop_entrypoints.sh
command: infinite_loop.sh
labels:
Expand Down
4 changes: 2 additions & 2 deletions services/searchapi/compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
services:
searchapi:
environment:
NODE_ENV: development
GITHUB_REPO: https://github.com/SciCatProject/panosc-search-api.git
volumes:
# These prevents git unpushed changes from being lost on container restart
Expand All @@ -11,7 +10,6 @@ services:
- ${PWD}/entrypoints/infinite_loop.sh:/usr/local/bin/infinite_loop.sh
- ${PWD}/entrypoints/setup_git.sh:/docker-entrypoints/0.sh
- ${PWD}/entrypoints/npm_ci.sh:/docker-entrypoints/1.sh
- ./entrypoints/tests.sh:/docker-entrypoints/2.sh
entrypoint:
- loop_entrypoints.sh
# This is the NODE original entrypoint
Expand All @@ -22,6 +20,8 @@ services:
healthcheck:
test: pgrep -f "/bin/sh /usr/local/bin/infinite_loop.sh"
user: root
env_file:
- ./config/.dev.env

volumes:
searchapi_dev:
Expand Down
5 changes: 2 additions & 3 deletions services/searchapi/entrypoints/tests.sh → services/searchapi/config/.dev.env
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh

NODE_ENV=development
## Setting an empty FACILITY makes the test pass as the mock implementation
## in the tests is not compatible with newer nodes versions
FACILITY="" npm run test
FACILITY=

0 comments on commit c69952c

Please sign in to comment.