Skip to content
.gitlab-ci.yml 2.93 KiB
Newer Older
variables:
    GIT_SUBMODULE_STRATEGY: recursive

stages:
    - build
    - push

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__ = '${CI_PROJECT_URL}/commit/${CI_COMMIT_SHA}'"                >> ./web/app/version.py
        - echo "__treeurl__ = '${CI_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
    only:
        - master
        - eval $(ssh-agent -s)
        - echo "$SSH_CONFIGURATION_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - git config --global user.name "$(git show -s --format=%an $CI_COMMIT_SHA)"
        - git config --global user.email "$(git show -s --format=%ae $CI_COMMIT_SHA)"
        - PRODDIR=$(mktemp -d)
        - git clone ${PROD_REPO} $PRODDIR
        - cd $PRODDIR
        - sed -i "s/cr.unil.ch\/icnml_web.*$/cr.unil.ch\/icnml_web\:${CI_COMMIT_SHORT_SHA}/g" docker-compose.yml
        - git add docker-compose.yml
Marco De Donno's avatar
Marco De Donno committed
        - git commit -m "Container update" -m "Update the docker image of ICNML to the commit ${CI_COMMIT_SHORT_SHA} (${CI_PROJECT_URL}/commit/${CI_COMMIT_SHA})" -m "Regards, the CICD"

deploy_develop:
    stage: deploy
    only:
        - develop
    script:
        - eval $(ssh-agent -s)
        - echo "$SSH_CONFIGURATION_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - git config --global user.name "$(git show -s --format=%an $CI_COMMIT_SHA)"
        - git config --global user.email "$(git show -s --format=%ae $CI_COMMIT_SHA)"
        - DEVDIR=$(mktemp -d)
        - git clone ${DEV_REPO} $DEVDIR 
        - cd $DEVDIR
        - sed -i "s/cr.unil.ch\/icnml_web.*$/cr.unil.ch\/icnml_web\:${CI_COMMIT_SHORT_SHA}/g" docker-compose.yml
        - git add docker-compose.yml
Marco De Donno's avatar
Marco De Donno committed
        - git commit -m "Container update" -m "Update the docker image of ICNML to the commit ${CI_COMMIT_SHORT_SHA} (${CI_PROJECT_URL}/commit/${CI_COMMIT_SHA})" -m "Regards, the CICD"