image: "clarinpl/python:3.8"

cache:
  paths:
    - .tox

stages:
  - check_style
  - build_develop
  - build_master

pep8:
  stage: check_style
  before_script:
    - pip install tox==3.18.1
  script:
    - tox -v -e pep8

build_develop:
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /build-cpu/
  stage: build_develop
  image: docker:18.09.7
  services:
    - 'docker:18.09.7-dind'
  script:
    - docker build -t $CI_REGISTRY_IMAGE:develop .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:develop

build_develop_both:
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /build-both/
  stage: build_develop
  image: docker:18.09.7
  services:
    - 'docker:18.09.7-dind'
  script:
    - docker build -t $CI_REGISTRY_IMAGE:develop .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:develop
    - docker build -t $CI_REGISTRY_IMAGE:gpu -f Dockerfile.gpu .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:gpu
  
build_master:
  stage: build_master
  image: 'docker:18.09.7'
  only:
    - master
  services:
    - 'docker:18.09.7-dind'
  script:
    - docker build -t $CI_REGISTRY_IMAGE:latest .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:latest
    - docker build -t $CI_REGISTRY_IMAGE:gpu -f Dockerfile.gpu .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:gpu
