diff --git a/.github/compose.dev.test.yaml b/.github/compose.dev.test.yaml new file mode 100644 index 00000000..f625ac45 --- /dev/null +++ b/.github/compose.dev.test.yaml @@ -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 diff --git a/.github/workflows/compose_test.yaml b/.github/workflows/compose_test.yaml index 2ff58ea4..bf9607c2 100644 --- a/.github/workflows/compose_test.yaml +++ b/.github/workflows/compose_test.yaml @@ -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 diff --git a/README.md b/README.md index 8af6a51c..269769f9 100644 --- a/README.md +++ b/README.md @@ -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}__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}__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). diff --git a/entrypoints/karma_tests.sh b/entrypoints/add_chrome.sh old mode 100755 new mode 100644 similarity index 75% rename from entrypoints/karma_tests.sh rename to entrypoints/add_chrome.sh index f31a06c3..94a08dff --- a/entrypoints/karma_tests.sh +++ b/entrypoints/add_chrome.sh @@ -1,5 +1,3 @@ #!/bin/sh apk update && apk add chromium - -npm run test diff --git a/entrypoints/npm_tests.sh b/entrypoints/npm_tests.sh new file mode 100755 index 00000000..6c431660 --- /dev/null +++ b/entrypoints/npm_tests.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +npm run test diff --git a/services/backend/services/v3/compose.dev.yaml b/services/backend/services/v3/compose.dev.yaml index c99090a2..c5ea3ff2 100644 --- a/services/backend/services/v3/compose.dev.yaml +++ b/services/backend/services/v3/compose.dev.yaml @@ -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: diff --git a/services/backend/services/v3/entrypoints/tests.sh b/services/backend/services/v3/entrypoints/tests.sh deleted file mode 100755 index 6c431660..00000000 --- a/services/backend/services/v3/entrypoints/tests.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -npm run test diff --git a/services/backend/services/v3/entrypoints/tests.sh b/services/backend/services/v3/entrypoints/tests.sh new file mode 120000 index 00000000..9499bcfb --- /dev/null +++ b/services/backend/services/v3/entrypoints/tests.sh @@ -0,0 +1 @@ +../../../../../entrypoints/npm_tests.sh \ No newline at end of file diff --git a/services/backend/services/v4/compose.dev.yaml b/services/backend/services/v4/compose.dev.yaml index 00fb1f31..0833aa51 100644 --- a/services/backend/services/v4/compose.dev.yaml +++ b/services/backend/services/v4/compose.dev.yaml @@ -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: diff --git a/services/frontend/compose.dev.yaml b/services/frontend/compose.dev.yaml index 2d18ba39..8fb8e969 100644 --- a/services/frontend/compose.dev.yaml +++ b/services/frontend/compose.dev.yaml @@ -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: diff --git a/services/landingpage/compose.dev.yaml b/services/landingpage/compose.dev.yaml index 4867150f..21d7dc5e 100644 --- a/services/landingpage/compose.dev.yaml +++ b/services/landingpage/compose.dev.yaml @@ -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: diff --git a/services/searchapi/compose.dev.yaml b/services/searchapi/compose.dev.yaml index 6c03f2fe..fb43e4fc 100644 --- a/services/searchapi/compose.dev.yaml +++ b/services/searchapi/compose.dev.yaml @@ -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 @@ -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 @@ -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: diff --git a/services/searchapi/entrypoints/tests.sh b/services/searchapi/config/.dev.env old mode 100755 new mode 100644 similarity index 79% rename from services/searchapi/entrypoints/tests.sh rename to services/searchapi/config/.dev.env index 706b6f4f..6714645d --- a/services/searchapi/entrypoints/tests.sh +++ b/services/searchapi/config/.dev.env @@ -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=