stages:
  - build
  - test
  - container

before_script:
  - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf 'git@gitlab.com:'

build:
  stage: build
  image: devuan:chimaera
  artifacts:
    untracked: true
    paths:
      - _build
  script:
    # Prepare environmental variables
    - 

check:
  stage: test
  image: devuan:chimaera
  dependencies:
    - build
  artifacts:
    when: always
    untracked: true
    paths:
      - _build
  script:
    - 

docker:
  image: docker:git
  stage: container
  services:
    - docker:dind
  script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -f Dockerfile .
    - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
    - if [ $CI_COMMIT_REF_NAME == "master" ] ; then docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest ; docker push $CI_REGISTRY_IMAGE:latest ; fi
  when: always
