Continuous Delivery Best Practices
- Only build your binaries once
- Covered by uploading jar to github in the end of the
build
Job
- Covered by uploading jar to github in the end of the
- Deploy the same way to every environment
- Covered by using the same script to deploy both test and prod
- Smoke-test your deployments
- Covered by running the smoke-tests after deploying to staging and prod
- Deploy into a copy of production
- Covered by deploying to a CF, but different space
- Each change should propagate through the pipeline instantly
- Covered by using the
serial
keyword on jobs
- Covered by using the
- If any part of the pipeline fails, stop the line
- Covered by using the keyword
passed
when getting resources from previous jobs
- Covered by using the keyword
Deployment pipeline
Requirements
In order to run this workshop you will need to have the following tools available in your local workstation:
Setup
fly
is a command line interface that allows you to interact with Concourse.
Follow the steps below in order to configure fly
:
- Log into Concourse and add the Concourse server to your fly CLI target's list:
fly -t comandante login --concourse-url https://play.comandante.ci/
- Check that you have logged in successfully and your fly CLI can talk to Concourse:
fly -t comandante status
build
1st step: create a job called In this step we are going to create a build
job that will compile the application and run unit tests.
- Clone this repository and create a file called
pipeline.yml
that you will use to create all your pipeline configuration - Edit the
secrets.yml
file and add your team name in there. You will need it in order to distiguish your pipeline in Concourse. - Create a Job called
build
with an empty Plan. - Set the pipeline with
fly -t comandante set-pipeline -p <pipeline name> -c pipeline.yml -l secrets.yml
. - Run
fly -t comandante pipelines
and observe that your pipeline was successfully created. - By default, pipelines are paused in Concourse when they are created. Run
fly -t comandante unpause-pipeline -p <pipeline name>
to unpause the pipeline. - Create a Git Resource for
https://github.com/spring-projects/spring-petclinic
(more about Resources here). - Add a Task called
package
to thebuild
Job. That task will run./mvnw package
inside aopenjdk:8-jdk-slim
Docker container. - Trigger the
build
Job and make sure it is green:fly -t comandante -j <pipeline name>/build
- Create an
output
in thepackage
Task to save the jar to our S3-compatible server using the s3-resource:
- You will need to declare the Resource in
pipelines.yml
and use:
regexp: ((team))/packages/spring-petclinic-(.*).jar
- You will need to create a
put
Step in thebuild
Job which will upload the jar - Then create the
output
that will make the jar inside the Task container available to theput
Step - You will find the credentials to an S3 bucket-like service in
secrets.yml
deploy
2nd step: create a Job called In this step, we are going to deploy the app to a staging environment and run smoke-tests.
- Create a Task called
push-to-staging
that will download the jar and deploy to a CloudFoundry staging environment:
- You will need to pass the jar produced in the previous Job (use the
get
Step and use thepassed
Parameter to instruct Concourse to use the Resource used by the previous Job) - Use the
governmentpaas/cf-cli
Docker image (thecf
CLI is available there) - Here you can find some intructions on how to deploy an app to CF (use
petclinic-((cf_staging_space))-((team))
as your app name - You will find the CF credentials you need in
secrets.yml
(useparams
to pass the credentials to your Task commands).
- Create a Task called
smoke-test
that will run smoke tests against the deployed application (this can be acurl
call for now hitting the URLhttp://petclinic-((cf_staging_space))-((team)).((cf_app_domain))
) - Set the pipeline and make sure it is green
test
3nd step: create a Job called In this step we are going to run acceptance/performance tests.
- Create a Job called
test
. You will need to pass the jar we deployed to staging and the source code.
- We are not going to use the jar on this Job actually, but it needs to be here so we can pass it the the downstream Jobs
- We need the sourse code because the test plan we will use lives there
- Create a Task to run the performance tests using
PETCLINIC_HOST=localhost PETCLINIC_PORT=8080 jmeter -n -t src/test/jmeter/petclinic_test_plan.jmx -l $TMPDIR/log.jtl
- Set the pipeline and make sure it is green
deploy
4th step: create a Job called In this step we are going to deploy the app to production.
- Create a Job called
deploy
and get the jar from the previous Job - Create a Task called
push-to-prod
and push the jar to the prod Space in CloudFoundry (you will find the credentials insecrets.yml
) - Set the pipeline and make sure it is green