4. Deployment Pipelines - pnguye35/pal-tracker GitHub Wiki

Purpose This lab demonstrates Github Actions, which provides the ability to do continuous integration/continuous delivery (CI/CD) from within your Github projects.

In this lab we will be creating a pipeline to deploy an application to Cloud Foundry. The lab will lead you through the anatomy of how Github Actions solve this problem. You can apply the same pipeline structure to other CI tools like Concourse or Jenkins.

For the purpose of this lab there are two environments:

Local environment (i.e. your workstation) Review environment (the sandbox space on PAS) This is a small but realistic example of a deployment pipeline. In your actual experience there will likely be more environments such as a QA, staging, pre-production, etc.

When code is pushed to GitHub, Github Actions will build, test and deploy to the review environment automatically. The application can be observed running on Cloud Foundry before deciding to deploy to production.

Learning Outcomes After completing the lab, you will be able to:

Describe CI and its importance Explain configuration for different environments and why it is important Use the CF CLI commands to manage routes for an application Describe the steps of a CI build Get started Before starting the lab, pull in the CI pipeline definition and the build task:

cd ~/workspace/pal-tracker git cherry-pick pipeline-start This will pull in a Github Actions pipeline at .github/workflows/pipeline.yml file which defines the configuration for Github Actions.

Github Actions will automatically pick up and execute the pipeline when you commit and push your changes in this lab.

Configure environment variables Add credentials as PAL Tracker project Github secrets for the following environment variables based on your PAS Credentials:

CF_API_URL

CF_ORG

CF_SPACE

CF_USERNAME

CF_PASSWORD

Understanding Routes All requests to apps that are running on Cloud Foundry go through a router which holds a mapping between the route and an app. When a request comes in, it is routed to one of the app instances in a round robin fashion. We have been using --random-route and random-route: true in the class because the route an app is bound to is global to the Cloud Foundry installation. In other words, if one student takes the route pal-tracker then nobody else is able to use that route. Anyone asking to take the pal-tracker route after that would be denied.

Apps can have multiple routes bound to them which can be useful for a blue-green deployment strategy.

To get some familiarity with routing, run the following commands:

Map another route to your app with the map-route command, making sure to view the help for the command first. Choose a unique hostname by following this guide.

Navigate to both the old and new routes in a browser to check that both work and go to the same app.

Configure application manifest To show that we are pushing to a review environment, change the WELCOME_MESSAGE in your manifest.yml to Hello from the review environment.

We will also explicitly state routes for our app in our manifest file. We will differentiate your route from others in the Cloud Foundry instance by following this guide.

Set this route for the application in your manifest. Your manifest should now look similar to this example:

Hide manifest.yml pal-tracker/manifest.yml

applications:

  • name: pal-tracker path: build/libs/pal-tracker.jar routes:
    • route: pal-tracker-${UNIQUE_IDENTIFIER}.${DOMAIN} env: WELCOME_MESSAGE: Hello from the review environment JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }' You must correctly fill-in the ${UNIQUE_IDENTIFIER} and ${DOMAIN} placeholders in the above example.

Push your changes to GitHub.

This will trigger a build of your pipeline in Github. Visit the Github Actions view of your project to watch the execution of the pipeline.

View deployed application After the pipeline runs, check the deployed app in your review environment and verify that the welcome message is correct.

Assignment Submit the assignment using the cloudNativeDeveloperReviewPipeline Gradle task. It requires you to provide the URL of your application.

For example:

cd ~/workspace/assignment-submission ./gradlew cloudNativeDeveloperReviewPipeline -PreviewUrl=https://${APP_URL} Learning Outcomes Now that you have completed the lab, you should be able to:

Describe CI and its importance Explain configuration for different environments and why it is important Use the CF CLI commands to manage routes for an application Describe the steps of a CI build Extra If you have additional time:

Try out triggered deployment to alternate (production) environments using Github Deployments.

Reimplement the pipeline with an alternate CI build infrastructure of your choice:

Concourse Jenkins Travis CI