# This file is a template, and might need editing before it works on your project.
# Official docker image.
image: docker:latest

stages:
  - build
  - cleanup
  - publish
  - deploy

before_script:
  - export IMAGE_TAG="$(echo -en $CI_COMMIT_REF_NAME | tr -c '[:alnum:]_.-' '-')-$(date +%Y%m%d)"
  - uname -a
  - docker version

build:test:
  stage: build
  except:
    - master
  script:
    - docker build -f Dockerfile -t "huygens/test/unifi:$IMAGE_TAG" .
  tags:
    - docker

build:master:
  stage: build
  only:
    - master
  script:
    - docker build -f Dockerfile --pull --no-cache -t "${CI_REGISTRY_IMAGE}/unifi:x86_64-$IMAGE_TAG" .
  tags:
    - docker


clean:test:
  stage: cleanup
  except:
    - master
  script:
    - docker rmi "huygens/test/unifi:$IMAGE_TAG"
  when: manual
  tags:
    - docker


push:
  stage: publish
  only:
    - master
  script:
    - docker tag "${CI_REGISTRY_IMAGE}/unifi:x86_64-$IMAGE_TAG" "${CI_REGISTRY_IMAGE}/unifi:latest"
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
    - docker push "${CI_REGISTRY_IMAGE}/unifi:x86_64-$IMAGE_TAG"
    - docker push "${CI_REGISTRY_IMAGE}/unifi:latest"
  tags:
    - docker

# To be run on your own runner where you want to deploy
# Replace the tags to match your specific runner
deploy_example:
  stage: deploy
  only:
    - master
  script:
    - apk add --no-cache py2-pip
    - pip install docker-compose
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
    - docker pull "${CI_REGISTRY_IMAGE}/unifi:x86_64-$IMAGE_TAG"
    - docker pull "${CI_REGISTRY_IMAGE}/unifi:latest"
    - IMAGE_TAG=x86_64-$IMAGE_TAG docker-compose -f docker-compose.yml up -d
  tags:
    - docker
    - deploy
    - huygens


Add support for GitLab CI
Add support for GitLab CI
