Skip to content
.gitlab-ci.yml 4.29 KiB
Newer Older
image:
  name: gcr.io/kaniko-project/executor:debug
  entrypoint: [ "" ]

variables:
    GIT_SUBMODULE_STRATEGY: recursive

stages:
    - build
        - echo "__branch__ = '${CI_COMMIT_REF_NAME}'"                                       >  ./web/app/version.py
        - echo "__commit__ = '${CI_COMMIT_SHA}'"                                            >> ./web/app/version.py
        - echo "__commitshort__ = '${CI_COMMIT_SHORT_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__ = ' - '.join( [ __branch__, __commitshort__, __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
        - cp -r ./config/keys ./web
        - mkdir -p /kaniko/.docker
        - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD | base64)\"}}}" > /kaniko/.docker/config.json
        - /kaniko/executor --context $CI_PROJECT_DIR/web --dockerfile $CI_PROJECT_DIR/web/Dockerfile --destination $CI_REGISTRY_IMAGE/web:${CI_COMMIT_SHORT_SHA} --destination $CI_REGISTRY_IMAGE/web:latest
        
redis:
    stage: build
        - echo "__branch__ = '${CI_COMMIT_REF_NAME}'"                                       >  ./web/app/version.py
        - echo "__commit__ = '${CI_COMMIT_SHA}'"                                            >> ./web/app/version.py
        - echo "__commitshort__ = '${CI_COMMIT_SHORT_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__ = ' - '.join( [ __branch__, __commitshort__, __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
        - cp -r ./config/keys ./web
        - mkdir -p /kaniko/.docker
        - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD | base64)\"}}}" > /kaniko/.docker/config.json
        - /kaniko/executor --context $CI_PROJECT_DIR/redis --dockerfile $CI_PROJECT_DIR/redis/Dockerfile --destination $CI_REGISTRY_IMAGE/redis:${CI_COMMIT_SHORT_SHA} --destination $CI_REGISTRY_IMAGE/redis:latest
        
deploy:
    only:
        - master
    image:
        name: cr.unil.ch/icnml/base:latest
        - 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.template
        - git add docker-compose.yml.template
        - git commit -m "Container update to version ${CI_COMMIT_SHORT_SHA}" -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"
        - ssh-add -D || true
        - ssh-agent -k || true