Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from bbyers-pivotal/master
Browse files Browse the repository at this point in the history
Adding Concourse CI/CD
  • Loading branch information
Marcelo Borges authored Oct 31, 2017
2 parents 5b7646b + f8fe667 commit a33e24d
Show file tree
Hide file tree
Showing 21 changed files with 460 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ci/DockerImages/cfapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ubuntu:14.04

MAINTAINER Brian Byers <[email protected]>

ENV HOME /root
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -y && apt-get install -y curl

ADD https://cli.run.pivotal.io/stable?release=linux64-binary&version=6.32.0&source=github-rel cf-cli.tgz
# Install CF CLI
RUN tar -xzf cf-cli.tgz && mv cf /opt && rm cf-cli.tgz

# Environment variables
ENV CF_HOME /opt
ENV PATH $PATH:$CF_HOME
15 changes: 15 additions & 0 deletions ci/DockerImages/gradle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM java:8-jdk

MAINTAINER Brian Byers <[email protected]>

ENV HOME /root

# Install Gradle
RUN wget https://services.gradle.org/distributions/gradle-4.2.1-bin.zip
RUN unzip gradle-4.2.1-bin.zip
RUN mv gradle-4.2.1 /opt/
RUN rm gradle-4.2.1-bin.zip

# Environment variables
ENV GRADLE_HOME /opt/gradle-4.2.1
ENV PATH $PATH:$GRADLE_HOME/bin
86 changes: 86 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pcf-ers-demo on concourse

![](images/pipeline.png)

* [Concourse](http://councourse.ci)
* Build only once and deploy anywhere
* Every build is a release candidate
* Every build step runs inside a docker container mounting to garden linux cells

## Resources

Resources in concourse are implemented as docker images which contain implementations corresponding their types

* git-repo ([git-resource](https://github.com/concourse/git-resource)): A Github repo. E.g. pcf-ers-demo Github resource

* version ([semver-resource](https://github.com/concourse/semver-resource)): A file to track the version stored in Github. E.g. 1.0.1 in a file named as current-version

* release-candidate (([github-resource](https://github.com/concourse/github-release-resource))) Store pcf-ers-demo artifact E.g. pcf-ers-demo-1.0.1-rc1.jar

* production-release (([github-resource](https://github.com/concourse/github-release-resource))) Store pcf-ers-demo artifact E.g. pcf-ers-demo-1.0.1.jar

## Pipeline Progress

### Check out from the git-repo

### Unit testing pcf-ers-demo

This step runs on a container with maven and java installed.
Basically it just runs "./mvnw test" against the git-repo

### build-artifact

* git-repo - Check out the same source version of git-repo as unit step
* version - Checkout the version file from Github
* "./mvnw install" generates the jar artifact
* Push the artifact to the Github resource as music-resource
* Git tag on the git-repo
* Bump the version resource for the next usage

### integration-tests

* Pull the binary from release-candidate
* Deploy to cloudfoundry acceptance tests space
* Run Automation Acceptance Tests suite

### promote-to-uat

* Pull the binary from release-candidate
* Deploy to cloudfoundry uat space
* Waiting for user acceptance tests

### manual-deploy-to-prod

* Manually trigger the build when the operators are ready
* Pull the binary from release-candidate and rename
* Deploy to prod
* Copy to Github release as production-release

### How to replicate this pipeline in your env

* If you don't already have a Concourse environment, you can quickly spin one up locally with [Vagrant](https://concourse.ci/vagrant.html])

* Download the `fly` CLI by visiting `http://192.168.100.4:8080` and selecting your OS then install

* Fork this github repo to your own github account, [ generate the key pair and add the public key to github ](https://help.github.com/articles/generating-ssh-keys/), and save the private key for future usage.


* Install PCF Dev ([Vagrant VM](http://pivotal.io/pcf-dev))
* Setup spaces for development, test, uat and production
* `cf create-space development`
* `cf create-space test`
* `cf create-space uat`
* `cf create-space production`


* Set your fly endpoint (assuming you are taking the easy way and using vagrant)

* `fly -t lite login -c http://192.168.100.4:8080`

* Configure your environment details in pcf-ers-demo-credentials.yml

* `fly -t lite set-pipeline -p pcf-ers-demo -c ci/pipeline.yml -l pcf-ers-demo-credentials.yml`
* `fly -t lite unpause-pipeline -p pcf-ers-demo`
* Open `http://192.168.100.4:8080` in your browser and enjoy!

### __FYI DO NOT COMMIT `pcf-ers-demo-credentials.yml` as it has all your secrets__
Binary file added ci/images/pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ci/name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pcf-ers-demo
184 changes: 184 additions & 0 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
resources:
- name: git-repo
type: git
source:
uri: {{GIT_REPO}}
branch: master
private_key: {{GIT_PRIVATE_KEY}}

- name: deploy-test-app
type: cf
source:
api: {{CF_API}}
username: {{CF_USER}}
password: {{CF_PASS}}
organization: {{CF_TEST_ORG}}
space: {{CF_TEST_SPACE}}
skip_cert_check: true

- name: deploy-uat-app
type: cf
source:
api: {{CF_API}}
username: {{CF_USER}}
password: {{CF_PASS}}
organization: {{CF_UAT_ORG}}
space: {{CF_UAT_SPACE}}
skip_cert_check: true

- name: deploy-production-app
type: cf
source:
api: {{CF_API}}
username: {{CF_USER}}
password: {{CF_PASS}}
organization: {{CF_PROD_ORG}}
space: {{CF_PROD_SPACE}}
skip_cert_check: true

- name: version
type: semver
source:
driver: git
uri: {{GIT_REPO}}
branch: version
file: version
private_key: {{GIT_PRIVATE_KEY}}
initial_version: 1.0.0

- name: release-candidate
type: github-release
source:
owner: {{GIT_USER}}
repository: {{GIT_RELEASE_REPO}}
access_token: {{GIT_ACCESS_TOKEN}}

- name: production-release
type: github-release
source:
owner: {{GIT_USER}}
repository: {{GIT_RELEASE_REPO}}
access_token: {{GIT_ACCESS_TOKEN}}




jobs:
- name: unit-tests
plan:
- get: git-repo
trigger: true
- task: unit
file: git-repo/ci/tasks/unit.yml

- name: build-artifact
serial_groups: [version]
serial: true
plan:
- get: git-repo
passed: [unit-tests]
trigger: true
- get: version
params: { pre: rc }
- task: build-artifact
file: git-repo/ci/tasks/build-artifact.yml
timeout: 5m
params:
base_name: pcf-ers-demo
- put: release-candidate
params:
name: git-repo/ci/name
tag: version/number
body: git-repo/ci/release-body
globs:
- artifact-dir/pcf-ers-demo*.jar
- put: git-repo
params:
repository: git-repo
tag: version/number
- put: version
params: {file: version/number}

- name: integration-tests
serial_groups: [version]
plan:
- aggregate:
- get: version
passed: [build-artifact]
trigger: true
- get: release-candidate
passed: [build-artifact]
- get: git-repo
passed: [build-artifact]
- put: deploy-test-app
params:
manifest: git-repo/manifest-test.yml
current_app_name: pcf-ers-demo-test
path: release-candidate/pcf-ers-demo*.jar

- name: promote-to-uat
serial_groups: [version]
plan:
- aggregate:
- get: release-candidate
passed: [integration-tests]
trigger: true
- get: version
passed: [integration-tests]
- get: git-repo
passed: [integration-tests]
- put: deploy-uat-app
params:
manifest: git-repo/manifest-uat.yml
current_app_name: pcf-ers-demo-uat
path: release-candidate/pcf-ers-demo*.jar

- name: ship-it
serial_groups: [version]
serial: true
plan:
- aggregate:
- get: release-candidate
passed: [promote-to-uat]
- get: version
params: { bump: final }
passed: [promote-to-uat]
- get: git-repo
passed: [promote-to-uat]
- task: prepare-final
file: git-repo/ci/tasks/prepare-final.yml
params:
base_name: pcf-ers-demo
- put: production-release
params:
name: git-repo/ci/name
tag: version/number
body: git-repo/ci/release-body
globs:
- final-dir/pcf-ers-demo*.jar
- put: deploy-production-app
params:
manifest: git-repo/manifest-prod.yml
current_app_name: pcf-ers-demo
path: final-dir/pcf-ers-demo*.jar

- name: major
serial_groups: [ version ]
plan:
- put: version
params: { bump: major, pre: rc }

- name: minor
serial_groups: [ version ]
plan:
- put: version
params: { bump: minor, pre: rc }

- name: patch
serial_groups: [ version ]
plan:
- get: version
passed: [ ship-it ]
trigger: true
- put: version
params: { bump: patch }
1 change: 1 addition & 0 deletions ci/release-body
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pcf-ers-demo release message
8 changes: 8 additions & 0 deletions ci/scripts/build-artifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e

version=`cat version/number`
cd git-repo
./mvnw install
cp target/*.jar ../artifact-dir/${base_name}-${version}.jar
ls ../artifact-dir
12 changes: 12 additions & 0 deletions ci/scripts/prepare-final.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e

version=`cat version/number`

echo "Renaming release-candidate to final build"
echo "release candidate files"
ls release-candidate

cp release-candidate/*.jar final-dir/${base_name}-${version}.jar
echo "final dir files"
ls final-dir
7 changes: 7 additions & 0 deletions ci/scripts/unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e

export GRADLE_OPTS=-Dorg.gradle.native=false
cd git-repo
./mvnw -v
./mvnw test
10 changes: 10 additions & 0 deletions ci/scripts/verify-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e

get_code="curl -I $CONCOURSE_DEMO_URL 2>/dev/null | head -n 1 | cut -d$' ' -f2"
status_code=`eval $get_code`
if [ "$status_code" != "200" ]
then
echo "Expect status code from $CONCOURSE_DEMO_URL as 200, but got $status_code"
exit 1
fi
22 changes: 22 additions & 0 deletions ci/tasks/build-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
platform: linux

image_resource:
type: docker-image
source:
repository: brianbyers/concourse-gradle
tag: "latest"


inputs:
- name: git-repo
- name: version

outputs:
- name: artifact-dir

run:
path: git-repo/ci/scripts/build-artifact.sh

params:
base_name:
22 changes: 22 additions & 0 deletions ci/tasks/prepare-final.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
platform: linux

image_resource:
type: docker-image
source:
repository: brianbyers/concourse-gradle
tag: "latest"

inputs:
- name: git-repo
- name: version
- name: release-candidate

outputs:
- name: final-dir

run:
path: git-repo/ci/scripts/prepare-final.sh

params:
base_name:
Loading

0 comments on commit a33e24d

Please sign in to comment.