.gitlab-ci.yml 2.91 KB
Newer Older
Yori Fournier's avatar
Yori Fournier committed
1 2 3
image: openshift/origin-cli

default:
Yori Fournier's avatar
Yori Fournier committed
4
    tags:
Yori Fournier's avatar
Yori Fournier committed
5
       - debian
Yori Fournier's avatar
Yori Fournier committed
6
    timeout: 1h 00m
Yori Fournier's avatar
Yori Fournier committed
7 8

stages:
Yori Fournier's avatar
Yori Fournier committed
9 10 11 12 13 14 15
    - build  # dummy stage to follow the template guidelines
    - test
    - deploy  # dummy stage to follow the template guidelines
    - review
    - staging
    - production
    - cleanup
Yori Fournier's avatar
Yori Fournier committed
16 17

variables:
Yori Fournier's avatar
Yori Fournier committed
18 19
    OPENSHIFT_SERVER: https://${OPENSHIFT_IP}:${OPENSHIFT_PORT}/
    OPENSHIFT_DOMAIN: apps.okd.aip.de
Yori Fournier's avatar
Yori Fournier committed
20 21 22 23 24
# Configure this variable in Secure Variables:
#OPENSHIFT_TOKEN:
#OPENSHIFT_PROJECT: python

test1:
Yori Fournier's avatar
Yori Fournier committed
25 26 27 28 29
    stage: test
    before_script: []
    script:
      - echo run tests
  
Yori Fournier's avatar
Yori Fournier committed
30
test2:
Yori Fournier's avatar
Yori Fournier committed
31 32 33 34
    stage: test
    before_script: []
    script:
      - echo run tests
Yori Fournier's avatar
Yori Fournier committed
35 36

.deploy: &deploy
Yori Fournier's avatar
Yori Fournier committed
37 38 39 40 41 42 43
    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 create route edge $APP --service $APP --insecure-policy Redirect"
Yori Fournier's avatar
Yori Fournier committed
44 45

review:
Yori Fournier's avatar
Yori Fournier committed
46 47
    <<: *deploy
    stage: review
Yori Fournier's avatar
Yori Fournier committed
48 49
    script:
      - echo "send test to staging instance"
Yori Fournier's avatar
Yori Fournier committed
50 51 52 53 54 55 56 57 58 59 60
    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: https://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
      on_stop: stop-review
    only:
      - branches
    except:
      - master
Yori Fournier's avatar
Yori Fournier committed
61 62

stop-review:
Yori Fournier's avatar
Yori Fournier committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    <<: *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
Yori Fournier's avatar
Yori Fournier committed
78 79

staging:
Yori Fournier's avatar
Yori Fournier committed
80 81 82 83 84 85 86 87 88 89 90
    <<: *deploy
    stage: staging
    variables:
      APP: staging
      APP_HOST: $CI_PROJECT_NAME-staging.$OPENSHIFT_DOMAIN
    environment:
      name: staging
      url: https://$CI_PROJECT_NAME-staging.$OPENSHIFT_DOMAIN
    only:
      - master

Yori Fournier's avatar
Yori Fournier committed
91
production:
Yori Fournier's avatar
Yori Fournier committed
92 93 94 95 96 97 98 99 100
    <<: *deploy
    stage: production
    variables:
      APP: production
      APP_HOST: $CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
    environment:
      name: production
      url: https://$CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
    only:
Yori Fournier's avatar
Yori Fournier committed
101
      - prod
Yori Fournier's avatar
Yori Fournier committed
102
    
Yori Fournier's avatar
Yori Fournier committed
103
stop-project:
Yori Fournier's avatar
Yori Fournier committed
104 105 106 107 108 109 110 111 112 113 114 115
    <<: *deploy
    stage: cleanup
    script:
      - oc delete all -l "app=$APP"
    when:
      manual
    variables:
      APP: production
    environment:
      name: production
      action: stop
    only:
Yori Fournier's avatar
Yori Fournier committed
116
      - prod
Yori Fournier's avatar
Yori Fournier committed
117
    
Yori Fournier's avatar
Yori Fournier committed
118
stop-staging:
Yori Fournier's avatar
Yori Fournier committed
119 120 121 122 123 124 125 126 127 128 129 130
    <<: *deploy
    stage: cleanup
    script:
      - oc delete all -l "app=$APP"
    when: manual
    variables:
      APP: staging
    environment:
      name: staging
      action: stop
    only:
      - master