variables:
    GIT_SUBMODULE_STRATEGY: recursive

stages:
    - build
    - push
    - deploy
    - clean

before_script:
    - docker --version
    - docker-compose --version

build:
    stage: build
    script:
        - echo "__branch__ = '${CI_COMMIT_REF_NAME}'" > ./web/app/version.py
        - echo "__commit__ = '${CI_COMMIT_SHA}'" >> ./web/app/version.py
        - echo "__commiturl__ = '${GIT_PROJECT_URL}/commit/${CI_COMMIT_SHA}'" >> ./web/app/version.py
        - echo "__treeurl__ = '${GIT_PROJECT_URL}/tree/${CI_COMMIT_SHA}'" >> ./web/app/version.py
        - echo "__date__ = '$(git show -s --format=%ci $CI_COMMIT_SHA)'" >> ./web/app/version.py
        - echo "__version__ = __branch__ + ' - ' + __commit__[ 0:8 ] + ' - ' + __date__ " >> ./web/app/version.py
        - echo "__author_name__ = '$(git show -s --format=%an $CI_COMMIT_SHA)'" >> ./web/app/version.py
        - echo "__author_email__ = '$(git show -s --format=%ae $CI_COMMIT_SHA)'" >> ./web/app/version.py
        - echo "__author__ = __author_name__ + ' <' + __author_email__ + '>'" >> ./web/app/version.py
        - make build

push:
    stage: push
    only:
        - master
    script:
        - make push

clean:
    stage: clean
    script:
        - make clean

deploy:
    stage: deploy
    script:
        - echo Deploying production on ${PROD_HOST}...
        - docker -H ${PROD_HOST} service update --force --detach --image=$(docker inspect --format='{{index .RepoDigests 0}}' ${REGISTRY}/icnml_web) ${PROD_SERVICE_NAME}
    only:
        - master