stages:
  - build
  - deploy

.default_settings_docker: &default_settings_docker
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  only:
    - master
    - chat
  except:
    - schedules

.default_settings_cron: &default_settings_cron
  stage: deploy
  tags:
    - ansible
  variables:
    GIT_STRATEGY: none
  only:
    refs:
      - chat
      - schedules
    variables:
      - $ANSIBLE_JOB_NAME
      - $ANSIBLE_EXTRA_ARGS

BuildDockerImage:
  <<: *default_settings_docker
  stage: build
  script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" .
    - docker push "$CI_REGISTRY_IMAGE"

UpdateDockerImage:
  <<: *default_settings_docker
  stage: deploy
  tags:
    - ansible-update
  variables:
    GIT_STRATEGY: none
  script:
    - docker pull "$CI_REGISTRY_IMAGE"

RenewLetsEncrypt:
  <<: *default_settings_cron
  script:
    - ascr role letsencrypt --tags=renew ${CHAT_INPUT} ${ANSIBLE_EXTRA_ARGS}
