---
image: adarnimrod/ci-images:docker

stages:
  - test
  - build
  - run

pre-commit:
  stage: test
  image: adarnimrod/ci-images:pre-commit
  variables:
    XDG_CACHE_HOME: "$CI_PROJECT_DIR/.cache"
  script:
    - pre-commit run --all-files
  cache:
    paths:
      - .cache/

build:
  stage: build
  tags: ["ns4.shore.co.il"]
  script:
    - docker-compose build --no-cache --pull

run:
  stage: run
  tags: ["ns4.shore.co.il"]
  when: manual
  script:
    - docker-compose up --detach --quiet-pull --remove-orphans
    # yamllint disable rule:line-length
    - |
        for i in $(seq 12)
        do
            docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' || break
            sleep 10
        done
        ! docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$'
