2022-07-19 05:08:45 -04:00
|
|
|
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
|
|
|
|
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
|
|
|
|
#
|
2021-06-28 02:07:45 -04:00
|
|
|
# To contribute improvements to CI/CD templates, please follow the Development guide at:
|
|
|
|
# https://docs.gitlab.com/ee/development/cicd/templates.html
|
|
|
|
# This specific template is located at:
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml
|
|
|
|
|
2020-11-18 07:09:16 -05:00
|
|
|
image: openshift/origin-cli
|
2017-01-09 09:24:25 -05:00
|
|
|
|
|
|
|
stages:
|
2019-06-05 12:31:35 -04:00
|
|
|
- build # dummy stage to follow the template guidelines
|
2017-01-09 09:24:25 -05:00
|
|
|
- test
|
2019-06-05 12:31:35 -04:00
|
|
|
- deploy # dummy stage to follow the template guidelines
|
2017-01-09 09:24:25 -05:00
|
|
|
- review
|
|
|
|
- staging
|
|
|
|
- production
|
2017-03-08 18:16:47 -05:00
|
|
|
- cleanup
|
2017-01-09 09:24:25 -05:00
|
|
|
|
|
|
|
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
|
2017-03-08 18:16:47 -05:00
|
|
|
- oc project "$CI_PROJECT_NAME-$CI_PROJECT_ID" 2> /dev/null || oc new-project "$CI_PROJECT_NAME-$CI_PROJECT_ID"
|
2017-01-09 09:24:25 -05:00
|
|
|
script:
|
|
|
|
- "oc get services $APP 2> /dev/null || oc new-app . --name=$APP --strategy=docker"
|
2017-11-07 14:07:28 -05:00
|
|
|
- "oc start-build $APP --from-dir=. --follow || sleep 3s && oc start-build $APP --from-dir=. --follow"
|
2017-01-09 09:24:25 -05:00
|
|
|
- "oc get routes $APP 2> /dev/null || oc expose service $APP --hostname=$APP_HOST"
|
|
|
|
|
|
|
|
review:
|
|
|
|
<<: *deploy
|
|
|
|
stage: review
|
|
|
|
variables:
|
2017-11-07 14:07:28 -05:00
|
|
|
APP: review-$CI_COMMIT_REF_NAME
|
2017-03-10 05:41:37 -05:00
|
|
|
APP_HOST: $CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
|
2017-01-09 09:24:25 -05:00
|
|
|
environment:
|
2017-04-20 17:30:01 -04:00
|
|
|
name: review/$CI_COMMIT_REF_NAME
|
2017-03-10 05:41:37 -05:00
|
|
|
url: http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
|
2017-01-09 09:24:25 -05:00
|
|
|
on_stop: stop-review
|
2021-05-06 08:10:38 -04:00
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
|
2017-01-09 09:24:25 -05:00
|
|
|
|
|
|
|
stop-review:
|
|
|
|
<<: *deploy
|
2017-03-08 18:16:47 -05:00
|
|
|
stage: cleanup
|
2017-01-09 09:24:25 -05:00
|
|
|
script:
|
|
|
|
- oc delete all -l "app=$APP"
|
|
|
|
variables:
|
2017-11-07 14:07:28 -05:00
|
|
|
APP: review-$CI_COMMIT_REF_NAME
|
2017-01-09 09:24:25 -05:00
|
|
|
GIT_STRATEGY: none
|
|
|
|
environment:
|
2017-04-20 17:30:01 -04:00
|
|
|
name: review/$CI_COMMIT_REF_NAME
|
2017-01-09 09:24:25 -05:00
|
|
|
action: stop
|
2021-05-06 08:10:38 -04:00
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
|
|
|
|
when: manual
|
2017-01-09 09:24:25 -05:00
|
|
|
|
|
|
|
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
|
2021-05-06 08:10:38 -04:00
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
2017-01-09 09:24:25 -05:00
|
|
|
|
|
|
|
production:
|
|
|
|
<<: *deploy
|
|
|
|
stage: production
|
|
|
|
variables:
|
|
|
|
APP: production
|
|
|
|
APP_HOST: $CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
|
|
|
|
environment:
|
|
|
|
name: production
|
|
|
|
url: http://$CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
|
2021-05-06 08:10:38 -04:00
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
|
|
when: manual
|