OpenShift.gitlab-ci.yml 2.17 KB
Newer Older
James Lopez's avatar
James Lopez committed
1 2 3
image: ayufan/openshift-cli

stages:
Will Hall's avatar
Will Hall committed
4
  - build  # dummy stage to follow the template guidelines
James Lopez's avatar
James Lopez committed
5
  - test
Will Hall's avatar
Will Hall committed
6
  - deploy  # dummy stage to follow the template guidelines
James Lopez's avatar
James Lopez committed
7 8 9
  - review
  - staging
  - production
10
  - cleanup
James Lopez's avatar
James Lopez committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

variables:
  OPENSHIFT_SERVER: openshift.default.svc.cluster.local
  # OPENSHIFT_DOMAIN: apps.example.com
  # Configure this variable in Secure Variables:
  # OPENSHIFT_TOKEN: my.openshift.token

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
33
    - oc project "$CI_PROJECT_NAME-$CI_PROJECT_ID" 2> /dev/null || oc new-project "$CI_PROJECT_NAME-$CI_PROJECT_ID"
James Lopez's avatar
James Lopez committed
34 35
  script:
    - "oc get services $APP 2> /dev/null || oc new-app . --name=$APP --strategy=docker"
Alessio Caiazza's avatar
Alessio Caiazza committed
36
    - "oc start-build $APP --from-dir=. --follow || sleep 3s && oc start-build $APP --from-dir=. --follow"
James Lopez's avatar
James Lopez committed
37 38 39 40 41 42
    - "oc get routes $APP 2> /dev/null || oc expose service $APP --hostname=$APP_HOST"

review:
  <<: *deploy
  stage: review
  variables:
Alessio Caiazza's avatar
Alessio Caiazza committed
43
    APP: review-$CI_COMMIT_REF_NAME
44
    APP_HOST: $CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
James Lopez's avatar
James Lopez committed
45
  environment:
46
    name: review/$CI_COMMIT_REF_NAME
47
    url: http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
James Lopez's avatar
James Lopez committed
48 49 50 51
    on_stop: stop-review
  only:
    - branches
  except:
52
    - master
James Lopez's avatar
James Lopez committed
53 54 55

stop-review:
  <<: *deploy
56
  stage: cleanup
James Lopez's avatar
James Lopez committed
57 58 59 60
  script:
    - oc delete all -l "app=$APP"
  when: manual
  variables:
Alessio Caiazza's avatar
Alessio Caiazza committed
61
    APP: review-$CI_COMMIT_REF_NAME
James Lopez's avatar
James Lopez committed
62 63
    GIT_STRATEGY: none
  environment:
64
    name: review/$CI_COMMIT_REF_NAME
James Lopez's avatar
James Lopez committed
65 66 67 68
    action: stop
  only:
    - branches
  except:
69
    - master
James Lopez's avatar
James Lopez committed
70 71 72 73 74 75 76 77 78 79 80

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:
81
    - master
James Lopez's avatar
James Lopez committed
82 83 84 85 86 87 88 89 90 91 92 93

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:
94
    - master