image: docker:latest

# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables:
  DOCKER_DRIVER: overlay2
  IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
  IMAGE_LATEST: $CI_REGISTRY_IMAGE:latest

services:
  - docker:dind

stages:
  - test
  - deploy

before_script:
  - docker info
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

test:
  stage: test
  script:
    - docker build -t $IMAGE_NAME .
    - docker run -v `pwd`:/git $IMAGE_NAME /bin/sh -c "wget -qO- https://fedoraproject.org/static/hotspot.txt | grep OK && cd /git && hugo"
  except:
    - schedules

deploy:
  stage: deploy
  script:
    - docker build -t $IMAGE_NAME -t $IMAGE_LATEST .
    - docker push $IMAGE_NAME
    - docker push $IMAGE_LATEST
  only:
    - tags

update:
  image: python:3.6
  before_script: []
  services: []
  script:
    - pip install requests
    - ./update.py $API_TOKEN $CI_PROJECT_PATH
  only:
    - schedules
