Table of Contents |
---|
From the platform, you can create microservices and manage their entire life cycle, from code compilation to the deployment in CaaS.
1.Creation
From the microservices screen https://development.onesaitplatform.com/controlpanel/microservices/list we can create a new microservice.
...
Introduction
The platform offers integration with the systems responsible for the CI/CD cycle.
For this purpose, the platform provides a tool to create and administrate the lifecycle of web applications and microservices from the control panel, following the standards of the CI/CD circle: creation, compilation, tests execution, generation of Docker images and deployment in CaaS.
The features that provides this lifecycle from the platform are:
Microservice creation.
Download code and development.
Compilation of the code and Docker image generation from Jenkins.
Deployment of the docker images in CaaS platform.
Updating a Microservice.
Microservice creation
Creating a a microservice in the platform, a developer registers a new deployable artifact. Automatically the platform generates all the infrastructure to support the full lifecycle:
Project in GIT repository based in Maven and Spring Boot, with a predefined skeleton according to the purpose of the artifact, and including the APIs of the platform to make easier for developers the interaction with the different modules of the platform.
Jenkins Pipeline in charge of downloading the code from a stable branch of the GIT repository, and launching tasks of compilation, unitary and integration tests execution, quality assurance, docker images generation and publishing of images in Docker registry.
Deployment and execution en CaaS platform of the microservice in charge of downloading the image from a Docker registry and deploy it containerized in an enviroment where it is exposed as service and can consume services from the platform and other microservices.
Creating a new Gitlab project
If we are creating the project from scratch, we can choose an archetype select a template and a Gitlab project will be generated in Gitlab with a code base code to start working work on it.
...
Depending on the type of project, we will select an archetype or another. Each template provides a different archetype with a skeleton of code to start development, which may or may not add dependencies to the project, including those that are platform APIs such as the broker. For example, the IoT Client archetype is configured to communicate with the platform broker to and perform query operations on an ontology.
...
In addition to the templates loaded by default, we can create our own templates by following the guide below (NEW) Templates in Microservices Platform
...
Creating from an existing Git project
If the code already exists in a Git repository and we only just want to manage the entire life cycle whole lifecycle from the platform, then we can indicate that we do not don't want to create the Git repository (by unchecking uncheck the box 'CREATE GIT REPOSITORY' box) , and configure the existing Git repository, specifying the directory where the project resources and the Docker file are located, as well as the repository.
...
We will need a valid token that has permissions to access the specific project.
...
Context and port
It is important to specify the context path defined in our application, as well as the port, to so that we can later generate the correct paths routes in the microservice gateway.
...
1.4 Settings
We must set up the credentials of Git, Jenkins, and CaaS (in this case Rancher).
...
Now that microservices gateway. If we do not have the server.servlet.contextPath defined in our project's properties file, we need to check the "Strip context path" box.
...
Jenkins and CaaS container configurations
To create the microservice, you need to configure the credentials of Jenkins and the CaaS container (Rancher, Openshift, Rancher 2 or Kubernetes).
...
To configure Jenkins, we need to specify the URL, the user and the user token. If we want the microservice to connect to an existing pipeline in Jenkins, we will have to specify its name in Existing pipeline name, this way we will not create our own pipeline for the microservice and we will be able to use the one we have configured, whether it is our own or a generic one for the project.
For the CaaS configuration, we need to select the one we need and specify its URL, user and access token.
Once everything is configured, we can create the microservice (if by clicking on the Create button at the top right. If we have selected the option to create a repository in Git, then it this may take a few seconds).
We can now will be able to see and manage our microservice from the previous list above:
...
If we have created a Git project from scratch, we can access the URL and, using the developer's IDE tools, clone the repository and to start working on the project and download the code generated by the platform.
...
...
Once downloaded, the project can be imported into Eclipse to start development, where you will see that the skeleton provides a number of packages and code snippets to make the work easier. Before compiling the code and generating the images, you will need to upload the changes to Git.
Info |
---|
DisclaimerThe user token for both GitLab and Jenkins needs to must have the necessary permissions to be able to create git Git projects and continuous integration pipelines. |
...
Compiling and building Docker images
At any pointtime, through the Jenkins selfwe can use the auto-generated pipeline , we can in Jenkins to compile any Git branch of in the repository and generate new Docker images.We just have to . This pipeline also takes care of running unit and integration tests and quality assurance rules.
Just click on the hammer ('Build service' hammer.
...
A pop-up window will appear, asking us for the input parameters of the pipeline:
...
Once those are inserted, we click 'Generate' and we will have to wait for it to finish.
...
Once finished, the spinner will disappear, and we can deploy it.
3.Deployment in CaaS
Once the images are button) and fill in the necessary fields, selecting the source branch in the Git repository you want to compile.
...
Once entered, click on 'Generate' and wait for the spinner to disappear, indicating that it has finished. Now it is time to deploy it.
CaaS Deployment
Once the images have been generated, we can proceed to deploy the microservice . To do this, we click by clicking on the 'Deploy' rocket:
...
A pop-up window will open, opens where we will have to select the environment and the host from a drop-down , along with menu the environment in the CaaS platform, the host where the CaaS will create the container and the DNS where the microservice services will be deployed:
...
Besidesexposed. In addition, once the environment is and host have been selected, a dropdown will appear in which we can choose the stack in which to deploy the microservice. This is quite useful should we want to group several microservices within the same Rancher 1.6 stack.
...
We click Deploy, it will take a few seconds...
...
Once deployed, the microservice the available stacks will appear, for example to group multiple microservices within a stack.
...
Info |
---|
The Docker image will be informed with the name of the image generated when doing the Build. If you have selected an existing pipeline you will probably have to go to Jenkins and get the name of the image from the console output of the build itself. |
Once we click on Deploy, after a few seconds a message will appear indicating that the service has been created, and you will be able to access Rancher or Openshift to see the deployment. In addition, it will be automatically available from the outside . If and if it is a web application with visual components, then we can navigate to the microservice through the Eye by copying the URL in the link icon:
...
If it is a purely pure REST service, then we can copy the generated URL (in this case https://development.onesaitplatform.com/restaurants/) and make calls and call it from any REST client, or if it has the Swagger view built in, we can access it by adding /swagger-ui/index.html to the generated URL.
...
Updating the deployed
...
service
If we want to update upgrade the version of the deployed microservice deployed, or overwrite some an environment variable, all we just have to do is click on the arrow key 'Upgrade' arrow button.
...
A window , similar to that of the deployment , will open, but in this one we can will be able to indicate environment variables:
...
, edit them and add new ones:
...
Once we have finished setting up the environment variables and the image to be displayed, click on 'Upgrade' and the process will begin, which will take a few seconds.