diff --git a/.env.travis b/.env.ci similarity index 100% rename from .env.travis rename to .env.ci diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 236c3540d39b97e7d2238b3a317bfe1b2ec7372c..0a6defaedbae865472c47ef2de2e7b35d018d06b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,22 +1,25 @@ variables: INSTALL_DIR: "/opt/django_remote_submission" - IMAGE_NAMETAG: "code.ornl.gov:4567/reflectometry/django-remote-submission/${CI_COMMIT_REF_NAME}" + IMAGE_NAMETAG: "code.ornl.gov:4567/reflectometry/django-remote-submission/${CI_COMMIT_REF_SLUG}" stages: - build - static_analysis + - test -before_script: - - docker system prune -f -a --volumes # remove containers, images, volumes, and networks left over from previous pipelines -# get access to the Container Registry (https://code.ornl.gov/reflectometry/django-remote-submission/container_registry) - - docker login --username=${CI_REGISTRY_USER} --password=${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} - -after_script: - - sudo chown -R gitlab-runner . # allows "docker system prune" next time the pipeline runs +# "setup" and "teardown" for all jobs +default: + before_script: + - docker system prune -f -a --volumes # remove containers, images, volumes, and networks left over from previous pipelines + # get access to the Container Registry (https://code.ornl.gov/reflectometry/django-remote-submission/container_registry) + - docker login --username=${CI_REGISTRY_USER} --password=${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + after_script: + - sudo chown -R gitlab-runner . # allows "docker system prune" next time the pipeline runs dockerbuild: stage: build script: + - mv .env.ci .env - docker build -t ${IMAGE_NAMETAG} . # create image with default Dockerfile - docker push ${IMAGE_NAMETAG} # upload to the Container Registry tags: @@ -29,3 +32,19 @@ flake8: - docker run ${IMAGE_NAMETAG} bash -c "flake8 ./django_remote_submission ./tests" # entrypoint is ${INSTALL_DIR} tags: - dev + +# Tests that do not require a remote worker +noremote: + stage: test + script: + - docker pull ${IMAGE_NAMETAG} # pull from the Container Registry + # pytest with coverage, creating a volume to retrieve the coverage output from the container + - docker run -v $PWD/artifacts:${INSTALL_DIR}/artifacts ${IMAGE_NAMETAG} bash -c "make test-noremote" + artifacts: + paths: + - artifacts/htmlcov/ # detailed coverage report htmlcov/index.html + reports: + cobertura: artifacts/coverage.xml # show coverage changes in GitLab's merge-request diff view + expire_in: 1 week # remove artifacts for this Job after one week + tags: + - dev diff --git a/Dockerfile b/Dockerfile index 0471cf61eedc1601f59961a28f420a91c598f9e4..27c954664610b9d4b54a4d8e709b02e26cc8e7ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ COPY . . # This line will throw error if using an old miniconda3 image. # To correct, one must build a miniconda3 image while piling all apt-get statements together into one # https://hub.docker.com/r/continuumio/miniconda3/dockerfile -RUN apt-get update && apt-get install -y vim emacs less mlocate iputils-ping net-tools openssh-client openssh-server +RUN apt-get update && apt-get install -y emacs iputils-ping less make mlocate net-tools openssh-client openssh-server vim RUN conda install --name base -c conda-forge mamba RUN mamba env update --name base --file conda.environment/environment-dev.yml diff --git a/Makefile b/Makefile index a68202f436858a917ef496a83cf797f2a2b41d65..27d7dfd72589c05e878cb3fc3e170e4a86756302 100644 --- a/Makefile +++ b/Makefile @@ -34,8 +34,8 @@ doclint: ## check documentation style with flake8 test: ## run tests quickly with the default Python pytest -v -test-ci: ## run tests skipping those requiring a remote worker - pytest -m "not remote_required" -v +test-noremote: ## run tests skipping those requiring a remote worker + pytest -v -m "not remote_required" --cov-report html:artifacts/htmlcov --cov-report term --cov-report xml:artifacts/coverage.xml --cov=django_remote_submission tests/ test-all: ## run tests on every Python version with tox tox diff --git a/conda.environment/environment-dev.yml b/conda.environment/environment-dev.yml index 85f3c428a0bfaaabc1c57ab4908214362b810d0a..2b2454afad6ba383732621ea97e87b374ee72adb 100644 --- a/conda.environment/environment-dev.yml +++ b/conda.environment/environment-dev.yml @@ -7,7 +7,7 @@ dependencies: - python=3.8 - asgiref - celery - - django + - django=3.2 - django-channels - django-environ - django-filter @@ -24,7 +24,6 @@ dependencies: # from here on packages strictly for testing - black - bumpversion - - coverage - flake8 - mock - mypy diff --git a/conda.environment/environment.yml b/conda.environment/environment.yml index fb57c4b180a0b76cb42e11ed6c6af768da128e94..b6f7a51ed6382eba41a9a9e29edcd8033fe3bcf4 100644 --- a/conda.environment/environment.yml +++ b/conda.environment/environment.yml @@ -9,7 +9,7 @@ dependencies: - six - paramiko - celery - - django + - django=3.2 - django-filter - django-model-utils - djangorestframework diff --git a/pytest.ini b/pytest.ini index 5c60171a8d0b4d77686bd93b0fcd57941bbde0dd..85be8d50ef5ee952139c666f409d92e7d7d9cad1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,10 @@ [pytest] +markers = + remote_required: test requiring a remote worker for fitting + job_program: script to be run remotely (as a string) testpaths = tests - -# Avoid reading-in django_remote_submission/migrations/0001_initial.py when we're modifying/adding models +# Avoid reading-in migrations/ when modifying or adding models # https://pytest-django.readthedocs.io/en/latest/database.html#no-migrations-disable-django-migrations addopts = --no-migrations +filterwarnings = + ignore::django.utils.deprecation.RemovedInDjango40Warning