Fast Track
Develop an example application with a three-tier microservices architecture and deploy it into Red Hat OpenShift on premises, on AWS, Azure or IBM Cloud. This OpenShift development environment has been pre-configured with a sample SDLC (Software Delivery Life Cycle).
Business Need
In this guide, imagine you have completed an Enterprise Design Thinking Workshop and the result is an MVP statement that defines the desired business outcomes. Use the steps below to help deliver this MVP quickly while following Garage Method best practices.
MVP Statement
An MVP is a first hill. Here's the hill statement for the MVP we're going to build:
-
Who: Distribution employees in each of the regional warehouses
-
What: A secure web application that enables easy access to list of product SKU inventory levels and inventory locations
-
Wow: Make the system appealing and easy to use. Develop it quickly as a minimum viable product. Use the latest managed container runtimes and DevOps best practices to enable post MVP feature improvements. Simulate a release to a Test environment.
Architecture
We will build an application that is made up of microservices in three-tier architecture. Each tier encapsulates a clean separation of concerns. Each app microservice component will be modelled using microservices and use a number of polyglot programming languages and frameworks. Data will be stored in a NoSQL Database.
User interface
The user experience for the application has been designed by the design team and this drives the requirements for the development team.
Technical Requirements
The Micro services should adhere to the following technical requirements:
- Microservices
- Stateless
- REST APIs
- Polyglot
- DevOps with CI/CD (continuous integration and continuous delivery)
- Use in cluster CI technology to be efficient and secure
- Use latest GitOps best practices
- Monitoring and logging
- Code analysis
- App security
- Deployed to Red Hat OpenShift cluster which is based on Kubernetes open source technology
- Follow the Carbon Design System user experience
Fast Track Guide
Deploy inventory service
-
Create a new repository for the service from the Inventory Service Solution template. Make the cloned repository public.
Warning
In order to prevent naming collisions if you are running this as part of a workshop, chose the GitHub organization you have been invited to as
Owner
and name the repositoryinv-svc-${UNIQUE_SUFFIX}
, replacing${UNIQUE_SUFFIX}
with your team name or initials. -
Deploy this application with Tekton:
-
In the OpenShift web console, click on the user ID on the top right, click on Copy login command and get the OpenShift login command, which includes a token.
-
Click on Display Token, copy the Login with the token. oc login command will log you in. Run the login command in your terminal:
-
Create a new
inventory-${UNIQUE_SUFFIX}-dev
project (setting theUNIQUE_SUFFIX
environment variables with your team name or initials to have a unique name): -
Create
registry-config
andci-config
secrets required for your pipeline runs to access your container registry:cat <<EOF | oc apply -f - --- kind: Secret apiVersion: v1 metadata: name: registry-config namespace: inventory-${UNIQUE_SUFFIX}-dev stringData: config.json: '{"auths":...}' # CHANGEME type: Opaque --- kind: Secret apiVersion: v1 metadata: name: ci-config namespace: inventory-${UNIQUE_SUFFIX}-dev stringData: img-namespace: library # CHANGEME img-server: core.harbor.example.com # CHANGEME type: Opaque EOF
!!! note
If you are doing this lab as part of a workshop secrets have been created for you in the ci-tools
namespace, you just need to copy them:
```sh
oc get secret registry-config -n ci-tools -o yaml | sed "s/ci-tools/inventory-${UNIQUE_SUFFIX}-dev/g" | oc apply -f -
oc get secret ci-config -n ci-tools -o yaml | sed "s/ci-tools/inventory-${UNIQUE_SUFFIX}-dev/g" | oc apply -f -
```
-
Clone the repo locally:
-
Create the tekton pipeline for the backend service your new project:
!!! note
- tkn pac create repository
assumes you have Pipelines-as-Code already setup on your cluster and Git provider. If you are running this lab as part of a workshop, this has been configured for you, make sure you use the provided GitHub organization when you create yout Git repository from template above.
- oc adm policy add-scc-to-user privileged -z pipeline
will make sure that the Tekton pipeline will be able to escalade privileges in your inventory-${UNIQUE_SUFFIX}-dev
project/namespace.
-
In OpenShift console (Pipelines Section > Pipelines > Repositories), edit the newly created
Repository
YAML to add cluster specific configuration (e.g. image repository): -
Kickoff the pipeline by making a dummy commit:
-
The CI pipeline should kick off. Once complete, you will be able to test the deployed service by going to the service route (accessible from openshift Console, or by running
oc get route
).
Deploy backend for frontend (BFF)
-
Create a new repository from the BFF Solution template.
Warning
In order to prevent naming collisions if you are running this as part of a workshop, chose the GitHub organization you have been invited to as
Owner
and name the repositoryinv-bff-${UNIQUE_SUFFIX}
, replacing${UNIQUE_SUFFIX}
with your team name or initials. -
Deploy this application with Tekton:
-
In the OpenShift web console, click on the user ID on the top right, click on Copy login command and get the OpenShift login command, which includes a token.
-
Click on Display Token, copy the Login with the token. oc login command will log you in. Run the login command in your terminal:
-
Move to your
inventory-${UNIQUE_SUFFIX}-dev
project created in previous lab: -
Clone the repo locally:
-
Create the tekton pipeline for the backend service your new project:
Note
tkn pac create repository
assumes you have Pipelines-as-Code already setup on your cluster and Git provider. If you are running this lab as part of a workshop, this has been configured for you, make sure you use the provided GitHub organization when you create yout Git repository from template above.oc adm policy add-scc-to-user privileged -z pipeline
will make sure that the Tekton pipeline will be able to escalade privileges in yourinventory-${UNIQUE_SUFFIX}-dev
project/namespace.
-
In OpenShift console (Pipelines Section > Pipelines > Repositories), edit the newly created
Repository
YAML to add cluster specific configuration (e.g. image repository): -
Last step before kicking off the pipeline is to make sure our Kubernetes/OpenShift deployment will get the
SERVICE_URL
environment variable configured. To do so, create a secret and patch the deployment to use it as source for environment variables: -
Update the Tekton
deploy
task in.tekton/tasks.yaml
to set deployment environment variables from newly created secret:.tekton/tasks.yaml... echo "Creating deployment $(params.app-name)" kubectl create deploy $(params.app-name) --image $(params.image) --port $(params.app-port) kubectl set env --from=secret/$(params.app-name)-config deployment/$(params.app-name) # NEW LINE kubectl expose deploy $(params.app-name) --port $(params.app-port) oc expose svc $(params.app-name) ...
-
After validation, commit and push the changes to git:
-
CI pipeline should be kicked off, you can test the hosted application once complete.
Deploy frontend microservice
-
Create a new repository from the UI Solution template.
Warning
In order to prevent naming collisions if you are running this as part of a workshop, chose the GitHub organization you have been invited to as
Owner
and name the repositoryinv-ui-${UNIQUE_SUFFIX}
, replacing${UNIQUE_SUFFIX}
with your team name or initials. -
Deploy this application with Tekton:
-
In the OpenShift web console, click on the user ID on the top right, click on Copy login command and get the OpenShift login command, which includes a token.
-
Click on Display Token, copy the Login with the token. oc login command will log you in. Run the login command in your terminal:
-
Move to your
inventory-${UNIQUE_SUFFIX}-dev
project created in previous lab: -
Clone the repo locally:
-
Create the tekton pipeline for the backend service your new project:
Note
tkn pac create repository
assumes you have Pipelines-as-Code already setup on your cluster and Git provider. If you are running this lab as part of a workshop, this has been configured for you, make sure you use the provided GitHub organization when you create yout Git repository from template above.oc adm policy add-scc-to-user privileged -z pipeline
will make sure that the Tekton pipeline will be able to escalade privileges in yourinventory-${UNIQUE_SUFFIX}-dev
project/namespace.
-
In OpenShift console (Pipelines Section > Pipelines > Repositories), edit the newly created
Repository
YAML to add cluster specific configuration (e.g. image repository): -
Last step before kicking off the pipeline is to make sure our Kubernetes/OpenShift deployment will get the
API_HOST
environment variable configured. To do so, create a secret and patch the deployment to use it as source for environment variables: -
Update the Tekton
deploy
task in.tekton/tasks.yaml
to set deployment environment variables from newly created secret:.tekton/tasks.yaml... echo "Creating deployment $(params.app-name)" kubectl create deploy $(params.app-name) --image $(params.image) --port $(params.app-port) kubectl set env --from=secret/$(params.app-name)-config deployment/$(params.app-name) # NEW LINE kubectl expose deploy $(params.app-name) --port $(params.app-port) oc expose svc $(params.app-name) ...
-
After validation, commit and push the changes to git:
-
CI pipeline should be kicked off, you can test the hosted application once complete.
Summary
Congrats! You have now completed the Micro App Guide demonstrating the Inventory solution.