Continuous Integration/Delivery (CICD) With GoCD for Cloud Foundry — Simple Pipeline Workflow
Part 1
GoCD Server Installation on Mac OS X
1.Double-click the file downloaded from the downloads page to unzip the contents.
wget https://download.gocd.io/binaries/17.3.0-4704/osx/go-server-17.3.0-4704-osx.zip
unzip -a go-server-17.3.0-4704-osx.zip
2. Double-click on the Go Server.app icon to open the launcher.
3. While the GoCD server is starting up, you'll see a progress bar in the top left of your screen.
4. Once the GoCD server has started, it will open your default browser to the GoCD dashboard page (defaults to: http://localhost:8153).
Location of GoCD server files
/Users/{user}/Library/Application Support/Go Server
GoCD Agent Installation on Mac OS X
1.Double-click the file downloaded from the downloads page to unzip the contents.
wget https://download.gocd.io/binaries/17.3.0-4704/osx/go-agent-17.3.0-4704-osx.zip
unzip -a go-agent-17.3.0-4704-osx.zip
2.Double-click on the Go Agent.app icon to open the launcher.
The very first time you run the GoCD agent on your machine you will be prompted for the hostname or IP address of your GoCD server. By default it will try connecting to the local machine. Click the OK button to continue.
Location of GoCD Agent files
/Users/{user}/Library/Application Support/Go Agent
Registering your agent with the server
For security reasons, all newly installed Go agents need to be enabled on the Go server before work is assigned to them. This prevents an unauthorized person from getting access to your source code. To enable a newly installed Go agent, do the following:
1.Open the Go server dashboard
2.Find the agent you've just installed on the list and add the agent . The Go server will now schedule work for this agent.
Enable Agent
Add Resource to agent
Setup pipeline for CICD Simple Workflow
Create build package pipeline
Create build package stage
Step 1: Basic Settings -> provide your pipeline name and group name
Step 2: Materials -> select material type , provide repo url and branch
Sample spring boot app -> https://github.com/devxchangeio-blog/user-service.git
Step 3. provide your stage name & job name
Step 4. Select Task Type as more..
Add the gradle command
./gradlew
Arguments
--profile
clean
build
Your build package pipeline is created
Step 5. Goto user-service-build-package → buildPackage →build
Assign the agent to the resources to run the job. You can assign multiple agent to the job and save.
Step 6. Export artifact (jar or war) to destination
Step 7. Trigger the pipeline
Create build package was successful and artifact published to destination.
Create Deploy to DEV pipeline
Step 1: Basic Settings -> provide your pipeline name and group name
Step 2: Materials -> select material type , provide deployment repo url and branch
Deployment script -> https://github.com/devxchangeio-blog/gocd_deployment_manifest.git
dev/deployment
deploy.sh -- download
manifest.yml -- add you application properties
applications:-
name: user-service
memory: 256MB
instances: 1
host: user-service-dev
route: user-service-dev
path: ../user-service/user-service-0.0.1-SNAPSHOT.jar
buildpack: java_buildpack
Step 3. provide your stage name & job name
Step 4. Select Task Type as script executor .. and Shell -> bash
Script
chmod +x dev/deploy.sh -- change the mode
./dev/deploy.sh -- push the artifact to cloud foundry
Step 5. Goto user-service-deploy-to-dev pipeline → Environment variables
Add below variable to your environment
deploy.sh - accept below variables
CF_ORG : your org name
CF_SPACE : your space name
CF_API : https://api.run.pivotal.io -- your console url
CF_USER : your user name
CF_PASS : your password
Step 6 : Goto Materials → Add Material → Pipeline
Material Name
user-service-build-package
Add dependency pipeline
user-service-build-package [buildPackage]
Step 7. Goto user-service-deploy-to-dev → General Option → Label Template
to maintain the build count
${user-service-build-package}
Step 8. user-servie-deploy-to-dev → deployStage → deploy-to-dev
Assign the agent to the resources to run the job. You can assign multiple agent to the job and save.
Step 9. user-servie-deploy-to-dev → deployStage → deploy-to-dev → Tasks- Add new task → Fetch Artifact
Trigger the deploy pipeline
Deployed to dev environment.
application pushed to hosted pivotal cloud foundry .
Create environments
From the home page, click environments and add a new Pipeline Environment if none exists using "Add A New Environment".
- Make sure Pipeline Environment has an agent associated with it in order for any pipeline within it to run. Agents can be added via 'Add Agents' tab when you create environment or can be managed using 'Agents' tab, as shown above.
- Once environment is create, go to 'Environments' tab from home page, and click on the environment created. It appears like this:
Flow the same steps and create other deploy pipeline
Create Deploy-to-qa pipeline
Add Fetch artifact (build->dev)
user-service-build-package/user-servie-deploy-to-dev
Script Executor
chmod +x qa/deploy.sh -- change the mode
./qa/deploy.sh -- push the artifact to cloud foundry
Create Deploy-to-stg pipeline
Add Fetch artifact (build-> dev->qa)
user-service-build-package/user-servie-deploy-to-dev/user-servie-deploy-to-qa
Script Executor
chmod +x stg/deploy.sh -- change the mode
./stg/deploy.sh -- push the artifact to cloud foundry
Create Deploy-to-prd pipeline
Add Fetch artifact (build-> dev->qa->stg)
user-service-build-package/user-servie-deploy-to-dev/user-servie-deploy-to-qa/user-servie-deploy-to-stg
Script Executor
chmod +x prd/deploy.sh -- change the mode
./prd/deploy.sh -- push the artifact to cloud foundry
CICD Workflow
About the Creator
Karthikeyan Sadayamuthu
Lead Developer @Comcast, Founder of devxchange.io
Comments
There are no comments for this story
Be the first to respond and start the conversation.