.gitlab-ci.yml 2.27 KB
Newer Older
Arman Khalatyan's avatar
Arman Khalatyan committed
1
# This file is a template, and might need editing before it works on your project.
Arman Khalatyan's avatar
Arman Khalatyan committed
2
image: openshift/origin-cli
Arman Khalatyan's avatar
Arman Khalatyan committed
3 4 5 6 7 8 9 10 11 12 13

stages:
  - build  # dummy stage to follow the template guidelines
  - test
  - deploy  # dummy stage to follow the template guidelines
  - review
  - staging
  - production
  - cleanup

variables:
Arman Khalatyan's avatar
Arman Khalatyan committed
14 15
  OPENSHIFT_SERVER: https://${OPENSHIFT_IP}:${OPENSHIFT_PORT}/
  OPENSHIFT_DOMAIN: apps.okd.aip.de
Arman Khalatyan's avatar
Arman Khalatyan committed
16
  # Configure this variable in Secure Variables:
Arman Khalatyan's avatar
Arman Khalatyan committed
17
  #OPENSHIFT_TOKEN: 
Arman Khalatyan's avatar
Arman Khalatyan committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  #OPENSHIFT_PROJECT: python

test1:
  stage: test
  before_script: []
  script:
    - echo run tests

test2:
  stage: test
  before_script: []
  script:
    - echo run tests

.deploy: &deploy
  before_script:
    - oc login "$OPENSHIFT_SERVER" --token="$OPENSHIFT_TOKEN" --insecure-skip-tls-verify
    - oc project "$CI_PROJECT_NAME-$CI_PROJECT_ID" 2> /dev/null || oc new-project "$CI_PROJECT_NAME-$CI_PROJECT_ID"
  script:
    - "oc get services $APP 2> /dev/null || oc new-app . --name=$APP --strategy=docker"
    - "oc start-build $APP --from-dir=. --follow || sleep 3s && oc start-build $APP --from-dir=. --follow"
    - "oc get routes $APP 2> /dev/null || oc expose service $APP --hostname=$APP_HOST"

review:
  <<: *deploy
  stage: review
  variables:
    APP: review-$CI_COMMIT_REF_NAME
    APP_HOST: $CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
    on_stop: stop-review
  only:
    - branches
  except:
    - master

stop-review:
  <<: *deploy
  stage: cleanup
  script:
    - oc delete all -l "app=$APP"
  when: manual
  variables:
    APP: review-$CI_COMMIT_REF_NAME
    GIT_STRATEGY: none
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  only:
    - branches
  except:
    - master

staging:
  <<: *deploy
  stage: staging
  variables:
    APP: staging
    APP_HOST: $CI_PROJECT_NAME-staging.$OPENSHIFT_DOMAIN
  environment:
    name: staging
    url: http://$CI_PROJECT_NAME-staging.$OPENSHIFT_DOMAIN
  only:
    - master

production:
  <<: *deploy
  stage: production
  variables:
    APP: production
    APP_HOST: $CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
  when: manual
  environment:
    name: production
    url: http://$CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
  only:
    - master