From c8a401d603d87e474bf93a6701e54e13e6ff5517 Mon Sep 17 00:00:00 2001 From: Vasek Sraier <git@vakabus.cz> Date: Thu, 22 Apr 2021 19:55:39 +0200 Subject: [PATCH] ci: changed the way CI works Squashed commit of the following: commit b439b895b4ea18fc63124fb66b55b439f7b10fef Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 19:47:48 2021 +0200 ci: npm global install in dev container commit c3a896269b222a8d23af54910ed2fe98193fa496 Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 19:12:12 2021 +0200 ci: installing npm dependencies globally commit 473fbf4878c40f859b4bb2eb25c9ccd2ac5a427d Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 18:56:57 2021 +0200 scripts: virtual env or ci detection commit fcf1d0e8035825fc1bd236b9c84bf792198c2aab Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 18:48:41 2021 +0200 scripts: fixed bash options commit aa96cf925ac0cd6ad36b89f011e449006dd6d8e9 Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 18:45:49 2021 +0200 ci: updated check stage definition commit 40a00e1261cf51c8a15e237e73d9a1dd2ffd3e61 Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 18:33:51 2021 +0200 ci: fix dev container definition commit ccedf3e18aead5097bec11384c2fd08c783129cd Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 18:30:37 2021 +0200 ci: fixed typo in .gitlab-ci.yml commit eaada4a0cfe1282fd90af838f6d2dade0129c47e Author: Vasek Sraier <git@vakabus.cz> Date: Thu Apr 22 18:06:39 2021 +0200 ci: use different container and always build it --- manager/.gitlab-ci.yml | 22 +++++++--------------- manager/README.md | 2 +- manager/containers/dev/Containerfile | 6 +++--- manager/pyproject.toml | 2 +- manager/scripts/_env.sh | 12 +++++++++--- manager/scripts/codecheck | 2 +- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/manager/.gitlab-ci.yml b/manager/.gitlab-ci.yml index f427e0b1e..fe8018653 100644 --- a/manager/.gitlab-ci.yml +++ b/manager/.gitlab-ci.yml @@ -13,7 +13,6 @@ image: registry.nic.cz/knot/knot-resolver-manager/devenv:latest build: image: docker:20-dind stage: image - when: manual tags: - dind variables: @@ -22,23 +21,16 @@ build: - docker info script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker build -t $IMAGE_TAG ci/devenv + - docker build -t $IMAGE_TAG -f containers/dev/Containerfile . - docker push $IMAGE_TAG -# agressively cache Poetry's and NPM's data -cache: - key: "always-the-same-cache" - paths: - - node_modules/ - - .venv/ - policy: pull-push - lint: stage: check script: - # run the actual tests - - poetry env use $(pyenv which python) - - poetry install - - npm install - - ./poe check + - poe check + +test: + stage: check + script: + - poe test diff --git a/manager/README.md b/manager/README.md index 06ee147bb..5cde56cf9 100644 --- a/manager/README.md +++ b/manager/README.md @@ -23,7 +23,7 @@ pyenv install 3.8.7 pyenv install 3.9.1 poetry env use $(pyenv which python) poetry install -yarn install # or "npm install" +npm install # or "yarn install" ``` With this environment, **everything else should just work**. You can run the same checks the CI runs, all commands listed bellow should pass. diff --git a/manager/containers/dev/Containerfile b/manager/containers/dev/Containerfile index d29d7e6af..9bbd9b8df 100644 --- a/manager/containers/dev/Containerfile +++ b/manager/containers/dev/Containerfile @@ -52,7 +52,6 @@ RUN apt-get update \ && echo "deb https://deb.nodesource.com/$NODE_VERSION $(lsb_release -s -c) main" | tee /etc/apt/sources.list.d/nodesource.list \ && echo "deb-src https://deb.nodesource.com/$NODE_VERSION $(lsb_release -s -c) main" | tee -a /etc/apt/sources.list.d/nodesource.list \ && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y nodejs \ - && npm install -g yarn \ # Installing `poetry` package manager: # https://github.com/python-poetry/poetry && curl -sSL 'https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py' | python \ @@ -70,7 +69,7 @@ COPY ./config/knot-resolver-manager.service /etc/systemd/system COPY ./config/kres-manager.yaml /etc/knot-resolver # Copy only requirements, to cache them in docker layer -COPY ./poetry.lock ./pyproject.toml ./yarn.lock ./package.json /code/ +COPY ./poetry.lock ./pyproject.toml ./package.json /code/ WORKDIR /code @@ -79,7 +78,8 @@ RUN echo "Running in $KNOT_ENV" \ && poetry install \ $(if [ "$KNOT_ENV" != 'dev' ]; then echo '--no-dev'; fi) \ --no-interaction --no-ansi \ - && if test "$KNOT_ENV" = "dev"; then yarn install; fi + && if test "$KNOT_ENV" = "dev"; then \ + npm install -g $(python -c "import json; print(*(k for k in json.loads(open('package.json').read())['dependencies']))"); fi # Here, we would copy the remaining code if we wanted to permanently keep it in the container. We don't do that, we use read-only bind mounts # COPY . /code diff --git a/manager/pyproject.toml b/manager/pyproject.toml index 598a40189..63aceecab 100644 --- a/manager/pyproject.toml +++ b/manager/pyproject.toml @@ -39,7 +39,7 @@ run-debug = { cmd = "scripts/run-debug", help = "Run the manager under debugger" test = { cmd = "pytest --cov=knot_resolver_manager --show-capture=all tests/", help = "Run tests" } check = { cmd = "scripts/codecheck", help = "Run static code analysis" } format = { shell = "poetry run black knot_resolver_manager/ tests/; isort -rc .", help = "Run code formatter" } -fixdeps = { shell = "poetry install; yarn install", help = "Install/update dependencies according to configuration files"} +fixdeps = { shell = "poetry install; npm install", help = "Install/update dependencies according to configuration files"} commit = { shell = "scripts/commit", help = "Invoke every single check before commiting" } container-build = { cmd = "scripts/container-build", help = "Build containers (no arguments = all, otherwise arguments are tags that should be built)" } container-run = { cmd = "scripts/container-run.py", help = "Run a container" } diff --git a/manager/scripts/_env.sh b/manager/scripts/_env.sh index 3bcbf4e46..f5ec18abb 100644 --- a/manager/scripts/_env.sh +++ b/manager/scripts/_env.sh @@ -1,5 +1,5 @@ # fail on errors -set -o errexit -o nounset +set -o errexit # define color codes red="\033[0;31m" @@ -17,7 +17,7 @@ fi cd $gitroot # ensure consistent environment with virtualenv -if test -z "$VIRTUAL_ENV"; then +if test -z "$VIRTUAL_ENV" -a "$CI" != "true"; then echo -e "${yellow}You are NOT running the script within the project's virtual environment.${reset}" echo -e "Do you want to continue regardless? [yN]" read cont @@ -25,4 +25,10 @@ if test -z "$VIRTUAL_ENV"; then echo -e "${red}Exiting early...${reset}" exit 1 fi -fi \ No newline at end of file +fi + +# update PATH with node_modules +PATH="$PATH:$gitroot/node_modules/.bin" + +# fail even on unbound variables +set -o nounset \ No newline at end of file diff --git a/manager/scripts/codecheck b/manager/scripts/codecheck index 882bee874..883e9dd9f 100755 --- a/manager/scripts/codecheck +++ b/manager/scripts/codecheck @@ -36,7 +36,7 @@ echo # check types with pyright echo -e "${yellow}Type checking using pyright...${reset}" -node_modules/.bin/pyright knot_resolver_manager +pyright knot_resolver_manager check_rv $? echo -- GitLab