@@ -73,8 +73,8 @@ The OpenShift template uses some global configuration used throughout all jobs.
| `OS_BASE_APP_NAME` | Base application name | `$CI_PROJECT_NAME` ([see GitLab doc](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)) |
| `OS_SCRIPTS_DIR` | directory where OpenShift scripts (templates, hook scripts) are located | `.` _(root project dir)_ |
| `OS_BASE_TEMPLATE_NAME` | Base OpenShift template name | `openshift` |
| `OS_APP_LABEL` | The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$appname`[dynamic variable](#environment-variables) value. _Advanced usage_ | `app` |
| `OS_ENV_LABEL` | The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$env`[dynamic variable](#environment-variables) value (`review`, `integration`, `staging` or `prod`). _Advanced usage_ | `env` |
| `OS_APP_LABEL` | The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$environment_name`[dynamic variable](#environment-variables) value. _Advanced usage_ | `app` |
| `OS_ENV_LABEL` | The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$environment_type`[dynamic variable](#environment-variables) value (`review`, `integration`, `staging` or `prod`). _Advanced usage_ | `env` |
### Secrets management
@@ -200,7 +200,7 @@ In this mode, you only have to provide a shell script that fully implements the
The deployment script is searched as follows:
1. look for a specific `os-deploy-$env.sh` in the `$OS_SCRIPTS_DIR` directory in your project (e.g. `os-deploy-staging.sh` for staging environment),
1. look for a specific `os-deploy-$environment_type.sh` in the `$OS_SCRIPTS_DIR` directory in your project (e.g. `os-deploy-staging.sh` for staging environment),
2. if not found: look for a default `os-deploy.sh` in the `$OS_SCRIPTS_DIR` directory in your project,
3. if not found: the GitLab CI template assumes you're using the template-based deployment policy.
@@ -216,7 +216,7 @@ The template processes the following steps:
1. _optionally_ executes the `os-pre-apply.sh` script in your project to perform specific environment pre-initialization (for e.g. create required services),
2. looks for your OpenShift [template](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html) file,
[substitutes variables](#environment-variables) and `oc apply` it,
1. look for a specific `openshift-$env.yml` in your project (e.g. `openshift-staging.yml` for staging environment),
1. look for a specific `openshift-$environment_type.yml` in your project (e.g. `openshift-staging.yml` for staging environment),
2. fallbacks to default `openshift.yml`.
3. _optionally_ executes the `os-post-apply.sh` script in your project to perform specific environment post-initialization stuff,
4. _optionally_ executes the `os-readiness-check` to wait & check for the application to be ready (if not found, the template assumes the application was successfully started).
@@ -243,15 +243,15 @@ In this mode, you only have to provide a shell script that fully implements the
The a deployment script is searched as follows:
1. look for a specific `os-cleanup-$env.sh` in the `$OS_SCRIPTS_DIR` directory in your project (e.g. `os-cleanup-staging.sh` for staging environment),
1. look for a specific `os-cleanup-$environment_type.sh` in the `$OS_SCRIPTS_DIR` directory in your project (e.g. `os-cleanup-staging.sh` for staging environment),
2. if not found: look for a default `os-cleanup.sh` in the `$OS_SCRIPTS_DIR` directory in your project,
3. if not found: the GitLab CI template assumes you're using the template-based cleanup policy.
Your script(s) may/shall use [variables](#environment-variables).
> TIP: a nice way to implement environment cleanup is to declare the label `app=${appname}` on every OpenShift
> TIP: a nice way to implement environment cleanup is to declare the label `app=${environment_name}` on every OpenShift
> object associated to your environment.
> Then environment cleanup can be implemented very easily with command `oc delete all,pvc,is,secret -l "app=${appname}"`
> Then environment cleanup can be implemented very easily with command `oc delete all,pvc,is,secret -l "app=${environment_name}"`
#### 2: template-based cleanup
@@ -260,7 +260,7 @@ In this mode, you mainly let OpenShift delete all objects from your OpenShift de
The template processes the following steps:
1. _optionally_ executes the `os-pre-cleanup.sh` script in your project to perform specific environment pre-cleanup stuff,
2. deletes **all** objects with label `app=${appname}`<br/>
2. deletes **all** objects with label `app=${environment_name}`<br/>
_works well with template-based deployment as this label is forced during `oc apply`_
3. _optionally_ executes the `os-post-cleanup.sh` script in your project to perform specific environment post-cleanup (for e.g. delete bound services).
@@ -276,7 +276,7 @@ This is pretty annoying, but as you may see above, deleting an env _may_ require
So, what can be done about that?
1. if your project doesn't require any delete script (in other words deleting all objects with label `app=${appname}` is
1. if your project doesn't require any delete script (in other words deleting all objects with label `app=${environment_name}` is
enough to clean-up everything): you could simply override the cleanup job Git strategy to prevent from fetching the
branch code:
```yaml
@@ -297,16 +297,16 @@ Part of this complexity can be handled by the lookup policies described above (e
In order to be able to implement some **genericity** in your scripts and templates, you should use environment variables:
1. any [GitLab CI variable](https://docs.gitlab.com/ee/ci/variables/#predefined-environment-variables)
1. any [GitLab CI variable](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)
(ex: `${CI_ENVIRONMENT_URL}` to retrieve the actual environment exposed route)
2. any [custom variable](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables)
2. any [custom variable](https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project)
(ex: `${SECRET_TOKEN}` that you have set in your project CI/CD variables)
3.**dynamic variables** set by the template:
*`${project}`: the OpenShift project in which application is deployed (ex: `my-openshift-project`)
*`${appname}`: the application target name to use in this environment (ex: `myproject-review-fix-bug-12` or `myproject-staging`)
*`${appname_ssc}`: the application target name in [SCREAMING_SNAKE_CASE](https://en.wikipedia.org/wiki/Snake_case) format
*`${environment_name}`: the application target name to use in this environment (ex: `myproject-review-fix-bug-12` or `myproject-staging`)
*`${environment_name_ssc}`: the application target name in [SCREAMING_SNAKE_CASE](https://en.wikipedia.org/wiki/Snake_case) format
(ex: `MYPROJECT_REVIEW_FIX_BUG_12` or `MYPROJECT_STAGING`)
*`${env}`: the environment type (`review`, `integration`, `staging` or `production`)
*`${environment_type}`: the environment type (`review`, `integration`, `staging` or `production`)
*`${hostname}`: the environment hostname, extracted from `${CI_ENVIRONMENT_URL}` (got from [`environment:url`](https://docs.gitlab.com/ee/ci/yaml/#environmenturl) - see `OS_REVIEW_ENVIRONMENT_SCHEME`, `OS_REVIEW_ENVIRONMENT_DOMAIN`, `OS_STAGING_ENVIRONMENT_URL` and `OS_PROD_ENVIRONMENT_URL`)
#### OpenShift template parameters evaluation
@@ -316,7 +316,7 @@ shall be variabilized using [parameters](https://docs.openshift.com/container-pl
Parameters are evaluated in the following order:
1. from a (optional) specific `openshift-$env.env` file found in the `$OS_SCRIPTS_DIR` directory of your project,
1. from a (optional) specific `openshift-$environment_type.env` file found in the `$OS_SCRIPTS_DIR` directory of your project,
2. from the (optional) default `openshift.env` file found in the `$OS_SCRIPTS_DIR` directory of your project,
3. from the [environment](#environment-variables)(either predefined GitLab CI, custom or dynamic variables).
@@ -324,7 +324,7 @@ For example, with the following parameters in your template:
"description":"The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$appname` dynamic variable.",
"description":"The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$environment_name` dynamic variable.",
"default":"app",
"advanced":true
},
{
"name":"OS_ENV_LABEL",
"description":"The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$env` dynamic variable.",
"description":"The OpenShift [label](https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html#writing-labels) set with the `$environment_type` dynamic variable.",
# export project as it may be usefull to build image name based on internal registry (ex: docker-registry.default.svc:5000/${project}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_LABEL} )
project=$(oc project -q)
export project
export env=$1
# for backward compatibility
export stage=$1
export appname=$2
# also export appname in SCREAMING_SNAKE_CASE format (may be useful with OpenShift env variables)
appname_ssc=$(to_ssc "$2")
export appname_ssc
export environment_type=$1
export environment_name=$2
# also export environment_name in SCREAMING_SNAKE_CASE format (may be useful with OpenShift env variables)