build:
image: docker:20-dind
stage: image
- when: manual
tags:
- dind
variables:
- 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
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.
&& 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 \
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
&& 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
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" }
# fail on errors
-set -o errexit -o nounset
+set -o errexit
# define color codes
red="\033[0;31m"
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
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
# 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