# Abuse YAML notation to make a heredoc. This will be ignored by the CI. .__doc__: &__doc__ - | This CI file is a manually maintained variant of .gitlab-ci.yml The key differences are that this has no tags, and the base images are different. # Abuse YAML notation to make a heredoc. This will be ignored by the CI. stages: - build - test - docker - data - run ### Conditionals ### .if-merge-request: &if-merge-request if: >- $CI_MERGE_REQUEST_IID .if-merged-into-default: &if-merged-into-default if: >- $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" ### TEMPLATES ### # Define common templates using YAML anchors .common_template: &common_template variables: PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" CONDA_PKGS_DIRS: "$CI_PROJECT_DIR/.cache/conda/pkgs" CONDA_ENVS_PATH: "$CI_PROJECT_DIR/.cache/conda/envs" XDG_CACHE_HOME: "$CI_PROJECT_DIR/.cache/xdg_cache" .common_template_docker: &common_template_docker before_script: - docker info - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY .test_loose_template: &test_loose_template <<: *common_template stage: test before_script: - conda init bash - source ~/.bashrc - ls -al - conda env create -f conda_env.yml --prefix ".cache/conda/envs/loose-watch-env" - conda activate ".cache/conda/envs/loose-watch-env" - pip install -e . script: - ./run_tests.py --network watch tests scripts after_script: - du -sh .cache/* - du -sh .cache/xdg_cache/* - du -sh .cache/conda/* - du -sh .cache/pip/* # Coverage is a regex that will parse the coverage from the test stdout coverage: '/TOTAL.+ ([0-9]{1,3}%)/' cache: key: loose-cache-v1 paths: #- .cache/conda/envs/loose-watch-env # better with or without this? - .cache/xdg_cache/watch .test_strict_template: &test_strict_template <<: *common_template stage: test before_script: - conda init bash - source ~/.bashrc - ls -al - ./dev/make_strict_req.sh - conda env create -f conda_env_strict.yml --prefix ".cache/conda/envs/strict-watch-env" - conda activate ".cache/conda/envs/strict-watch-env" - pip install -e . script: - ./run_tests.py --network watch tests scripts after_script: - du -sh .cache/* - du -sh .cache/xdg_cache/* - du -sh .cache/conda/* - du -sh .cache/pip/* # Coverage is a regex that will parse the coverage from the test stdout coverage: '/TOTAL.+ ([0-9]{1,3}%)/' cache: key: strict-cache-v1 paths: #- .cache/conda/envs/strict-watch-env # better with or without this? - .cache/xdg_cache/watch #### JOBS ### test_full_loose/conda-linux: <<: *test_loose_template rules: - <<: *if-merged-into-default image: registry.smartgitlab.com/kitware/watch/miniconda3 test_full_strict/conda-linux: <<: *test_strict_template rules: - <<: *if-merged-into-default image: registry.smartgitlab.com/kitware/watch/miniconda3 build_docker_and_upload_strict: <<: *common_template_docker rules: - <<: *if-merged-into-default stage: docker script: # Note: # CI_REGISTRY_IMAGE is set by gitlab CI - docker build --build-arg BUILD_STRICT=1 -t $CI_REGISTRY_IMAGE/watch:$IMAGE_TAG . - docker run --rm $CI_REGISTRY_IMAGE/watch:$IMAGE_TAG /bin/bash -c "source /opt/conda/etc/profile.d/conda.sh && conda activate watch && cd /watch && python run_tests.py watch tests scripts" # Pushing container only if merging into default branch (i.e. "master") - echo "docker push $CI_REGISTRY_IMAGE/watch:$IMAGE_TAG" - docker push $CI_REGISTRY_IMAGE/watch:$IMAGE_TAG image: docker:19.03.12 variables: IMAGE_TAG: latest data: # This stage will download one image from the SMART STAC API and persist it for 5 minutes as an artifact (please no caching here) <<: *common_template rules: - <<: *if-merged-into-default image: python:3.8 stage: data before_script: - apt-get update && apt-get install jq -y - pip install awscli pystac-client script: - mkdir -p $CI_PROJECT_DIR/imagery - stac-client search --url https://api.smart-stac.com/ -c worldview-nitf --max-items 1 --bbox 124 37 131 43 --header x-api-key=${STAC_API_KEY} --save $CI_PROJECT_DIR/imagery/stac_output.json - FILENAME=$(cat $CI_PROJECT_DIR/imagery/stac_output.json | jq -r '.features[0] .assets .data .href') - aws s3 cp $FILENAME $CI_PROJECT_DIR/imagery/ artifacts: name: "Input Imagery" paths: - imagery/ expire_in: 5 minutes run: # Fun Part: Run the container you built here and import artifacts from the previous stage <<: *common_template rules: - <<: *if-merged-into-default image: name: $CI_REGISTRY_IMAGE/watch:latest stage: run script: - echo "Is there any imagery here?" - ls -lah $CI_PROJECT_DIR/imagery/ dependencies: - data artifacts: name: "Output Imagery" paths: - imagery/ expire_in: 1 day