-
Notifications
You must be signed in to change notification settings - Fork 14
dsf deployment dsf4openshift
In this section you will see how you can create a new environment instance in OpenShift and the things that you must add to the Jenkinsfiles of your repository to deploy a branch in this new environment. To conclude you are going to see how to add config files for environment in the source code of the applications.
To have your deployment environment with OpenShift you need to have an OpenShift Cluster.
First of all you need to download the OpenShift client, you can find it here.
Remember that what you need to download oc Client Tools and not OKD Server.
Note
|
This tutorial has been made with the version 3.10.0 of the client, it is recommended to use the most current client, but if it does not work, it is possible that the instructions have become obsolete or that the OpenShift used needs another older/newer version of the client. To download a specific version of the client you can find here the older versions and the version 3.10.0. |
Once you have downloaded the client you have to add it to the PATH environment variable.
You can log using a terminal and executing the next instructions:
oc login $OpenShiftUrl
Note
|
You need a valid user to log in. |
For example, to create a secret for a nexus repository you should execute the next commands:
oc create secret docker-registry $nameForSecret --docker-server=${dockerRegistry} --docker-username=${user} --docker-password=${pass} --docker-email=no-reply@email.com
oc secrets link default $nameForSecret --for=pull
If you need to use that secret, you need to add the next code to the instruction:
--source-secret=$nameForSecret
If you need to create docker images of your projects you could use OpenShift to do it (Off course only if you have enough rights).
To do it, follow the next steps.
The first thing you need to do for create a new environment is prepare the builds for the front and for the middleware and rise default memory limits for the middleware. You can do it using a terminal and executing the next instructions:
These are a summary about the parameters used in our commands:
-
${dockerRegistry}: The url of the docker repository.
-
${props.name}: The name of the project (for example could be find on package.json)
-
${dockerTag}: The tag of the image
Note
|
From now on you will refer to the name that you are going to give to the environment as $enviroment. Remember to modify it for the correct value in all instructions. |
You need to create nginx build config with docker.
oc new-build --strategy docker --binary --docker-image nginx:alpine-perl --name=${props.name}-$environment --to=${dockerRegistry}/${props.name}:${dockerTag} --to-docker=true
Note
|
You need nginx:alpine-perl to read the environment config file in openshift, if you are not going to use it, devonfw recommend you to use nginx:latest instead. |
oc new-build --strategy docker --binary --docker-image node:lts --name=${props.name}-$environment --to=${dockerRegistry}/${props.name}:${dockerTag} --to-docker=true
oc new-build --strategy docker --binary --docker-image openjdk:<version> --name=${props.name}-$environment --to=${dockerRegistry}/${props.name}:${dockerTag} --to-docker=true
Note
|
You need to specify the <version> of java used for your project. Also you can use the -alpine image. This image is based on the popular Alpine Linux project. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general. More information on docker hub. |
In this step is where you will build a docker image from a compiled application.
To build the source in OpenShift, first of all you need to compile your source and obtain the artifacts "dist folder" or download it from a repository. Normally the artifacts have been built on Jenkins and have been stored in Nexus.
To download it, you can access to your registry, select the last version and download the ".tar". The next image show an example of where is the link to download it, marked in yellow:
When you have the artifacts, you can send them to your openshift and build them using your buildconfig that you created on the previous step. This is going to create a new docker image and push it to your registry. To do it you need to use a terminal and execute the following:
oc start-build ${props.name}-$environment --from-dir=${artifactsPath} --follow
Note
|
${artifactsPath} is the path where you have the artifacts of the prerequisite (On jenkins is the dist folder generated by the build). |
Note
|
Maybe you need to raise your memory or CPU limits. |
Now it is time to configure the environment.
You need a docker image of your application. You could created it using OpenShift as you see in the last step.
To create new app you need to use the next command.
oc new-app --docker-image=${artifactsPath} --name=${props.name}-$environment
Note
|
You could add environment variables using -e $name=$value
|
Finally, you need add a route to access the service.
Add http route
If tou want to create an http reoute execute the following command in a terminal:
oc expose svc/${props.name}-$environment
Add https route
If you want to create an https route you can do it executing the following command:
oc create route edge --service=${props.name}-$environment
If you want to change the default route path you can use the command --hostname=$url. For example:
oc expose svc/${props.name}-$environment --hostname=$url
oc create route edge --service=${props.name}-$environment --hostname=$url
When you have new images in the registry you must import them to OpenShift. You could do it executing the next commands:
oc import-image ${props.name}-$environment --from=${dockerRegistry}/${props.name}:${dockerTag} --confirm
Note
|
Maybe you need to raise your memory or CPU limits. It is explained below. |
If you need to raise (or decrease) the memory or CPU limits that you need, you could do it in OpenShift using the user interface. To do it you should enter in OpenShift and go to deployments.
At the right top, you could see a drop down actions, click on it and you could edit the resource limits of the container.
Maybe you should modify the resource limits of the pod too. To do it you should click on drop down actions and go to edit YAML. Then you could see something like the next image.
In the image, you could see that appear resources two times. One at the bottom of the image, this are the container resources that you modified on the previous paragraph and another one at the top of the image. The resources of the top are for the pod, you should give to it at least the same of the sum for all containers that the pod use.
To integrate it, you need to have installed the plugin OpenShift Client. To install it go to Manage Jenkins clicking on left menu and enter in Manage Plugins. Go to Available tab and search it using the filter textbox in the top right corner and install it.
Now it is time to add/upgrade the next stages in to your Jenkinsfile
Add create docker image stage.
Add deploy docker image stage.
Add check status stage.
This documentation is licensed under the Creative Commons License (Attribution-NoDerivatives 4.0 International).
-
cicd configuration
-
Manual configuration
-
Automatic configuration
-
-
Custom Services
-
Azure DevOps