1. Context
After having a working Camel application the next step is to deploy it in Red Hat OpenShift possibly in multiple environments from dev to prod. Traditionally this is referred to as CI/CD and we will explore the best practices in the context of an OpenShift environment.
2. Prerequisites
A Red Hat OpenShift cluster with OpenShift Pipelines and OpenShift GitOps operators installed.
Be sure to have the right permissions configured for the OpenShift GitOps users. In particular to which groups they belong see role mapping documentation. |
3. Goal
-
Providing best practices on OpenShift CI/CD applied to Camel applications.
4. Approach
The proposed architecture is to use OpenShift Pipelines for the CI part, to build the Camel application image, push it to an image registry and then update the repository containing the OpenShift deployment yaml resources.
The Push Images step can target the internal OpenShift registry (like in the example repository of this document) or external image registries public or private. |
The Update resources step can be performed manually (like it is assumed in the example repository of this document) or automated as part of the CI pipeline. The automation can be partial by just opening a PR against the Yaml git repository or it can also be automatically merged if necessary. |
The CD part is managed by OpenShift GitOps that combining the yaml resources and the built image would deploy the Camel application in the appropriate environments (for instance dev and prod).
Two repositories are provided as examples, the example app repo camel-cicd-exampleapp and the example gitops repo camel-cicd-gitops.
4.1. Camel-cicd-exampleapp
The camel-cicd-exampleapp repository contains a simple camel application. The maven project has been configured to copy in the etc/
folder the k8s/openshift resources generated during the build process by invoking mvn clean install package
command. The etc/
folder also contains the OpenShift pipelines (Tekton) definitions in the file named pipeline.yaml
as well as an utility script (cleanup-generated-kubernetes-resources.groovy)
useful during 8s/openshift resources generation.
4.2. Camel-cicd-gitops
The camel-cicd-gitops project contains a typical kustomize structure where the k8s/openshift resources are the one generated by camel-cicd-exampleapp project and copied in the k8s`/openshift.yaml` file. Those resources are the ones used by Openshift GitOps (ArgoCD) to deploy the application.
5. OpenShift Pipelines config
The CI tekton pipeline can be created visually through OpenShitf console or its yaml representation can be imported and modified if/as needed. In order to do so run oc apply -f camel-cicd-exampleapp/etc/pipeline.yaml
, then the pipeline should be visible under the pipeline tab of the developer perspective of the OpenShift console.
That pipeline can be edited as needed and then started
6. OpenShift GitOps config
Let’s use Argo CD to create a new application. You can also visit Argo CD from your OpenShift cluster. Within the Developer perspective, navigate to the openshift-gitops project, and visit the Topology page.
Click on the Argo CD route to visit the Argo CD dashboard. You’ll be prompted to log in to Argo CD, and you can use the Login with OpenShift button to do so.
Within the Argo CD web console, click the \+ New App button. This will open the New Application form, where we can fill in the necessary information to create a new application in our development environment.
Fill in the following information, many of which may auto-fill when selected:
-
Application Name: camel-cicd-exampleapp
-
Project Name: default
-
Sync Policy: Automatic
-
Self Heal: Disabled
-
Auto-Create Namespace: Enabled
-
Repository URL: https://github.com/valdar/camel-cicd-gitops
-
Revision: main
-
Path: environments/dev
-
Cluster URL: https://kubernetes.default.svc
-
Namespace: the namespace you want the app deployied into
When finished, click the CREATE button in the top left-hand corner. This will create the application in Argo CD and begin the syncing process.