Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
236 lines (209 sloc) 8.92 KB
defaults: &defaults
working_directory: /home/circleci/my-company-monolith
docker:
- image: circleci/openjdk:8-jdk-browsers
version: 2
jobs:
# Build and test with maven
build:
<<: *defaults
steps:
- checkout
# Caching is one of the most effective ways to make jobs faster on CircleCI.
# Downloading from a Remote Repository in Maven is triggered by a project declaring a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer).
# Do not overwrite your release (not snapshots) artifacts (my-company-blog-domain, my-company-blog-materialized-view, my-company-project-domain, my-company-project-materialized-view) on remote maven repository, othervise the cache will become stale.
- restore_cache:
key: my-company-monolith1a-{{ checksum "pom.xml" }}
- run:
name: Build and Install maven artifact
command: mvn -s .circleci/maven.settings.xml install -P idugalic-cloud
- save_cache:
paths:
- ~/.m2
key: my-company-monolith1a-{{ checksum "pom.xml" }}
- run:
name: Collecting test results
command: |
mkdir -p junit/
find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} junit/ \;
when: always
- store_test_results:
path: junit/
- store_artifacts:
path: junit/
- run:
name: Collecting artifacts
command: |
mkdir -p artifacts/
cp pom.xml artifacts/
cp .circleci/maven.settings.xml artifacts/
find . -type f -regex ".*/target/.*jar" -exec cp {} artifacts/ \;
- store_artifacts:
path: artifacts/
- persist_to_workspace:
root: artifacts/
paths:
- .
# Deploying build artifact on PWS staging environment for testing.
staging:
<<: *defaults
steps:
- attach_workspace:
at: workspace/
- run:
name: Install CloudFoundry CLI
command: |
curl -v -L -o cf-cli_amd64.deb 'https://cli.run.pivotal.io/stable?release=debian64&source=github'
sudo dpkg -i cf-cli_amd64.deb
cf -v
- deploy:
name: Deploy to Staging - PWS CLoudFoundry (CF_PASSWORD variable required)
command: |
cf api https://api.run.pivotal.io
cf auth idugalic@gmail.com $CF_PASSWORD
cf target -o idugalic -s Stage
cf push stage-my-company-monolith -p workspace/*.jar --no-start
cf bind-service stage-my-company-monolith mysql
cf restart stage-my-company-monolith
# Deploying current/old production on PWS staging environemnt for DB schema backward compatibility testing.
production-on-staging:
<<: *defaults
steps:
- attach_workspace:
at: workspace/
- run:
name: Install CloudFoundry CLI
command: |
curl -v -L -o cf-cli_amd64.deb 'https://cli.run.pivotal.io/stable?release=debian64&source=github'
sudo dpkg -i cf-cli_amd64.deb
cf -v
- run:
name: Install AWS CLI
command: sudo apt-get update && sudo apt-get install -y awscli
- run:
name: Download latest production artifact from AWS S3 (AWS Permissions on CircleCI required)
command: aws s3 sync s3://my-company-production . --region eu-central-1
- deploy:
name: Deploy latest production application to Staging - PWS CLoudFoundry (CF_PASSWORD variable required)
command: |
if [ -e "./my-company-monolith-1.0.0-SNAPSHOT.jar" ]; then
cf api https://api.run.pivotal.io
cf auth idugalic@gmail.com $CF_PASSWORD
cf target -o idugalic -s Stage
cf push stage-my-company-monolith-prod -p workspace/*.jar --no-start
cf bind-service stage-my-company-monolith-prod mysql
cf restart stage-my-company-monolith-prod
else
echo "Artifact does not exist, deploying current build"
cf api https://api.run.pivotal.io
cf auth idugalic@gmail.com $CF_PASSWORD
cf target -o idugalic -s Stage
cf push stage-my-company-monolith-prod -p workspace/*.jar --no-start
cf bind-service stage-my-company-monolith-prod mysql
cf restart stage-my-company-monolith-prod
fi
# A very simple e2e test on PWS staging environemnt
staging-e2e:
<<: *defaults
steps:
- run:
name: End to end test on Staging
command: |
curl -I "https://stage-my-company-monolith.cfapps.io/health"
curl -I "https://stage-my-company-monolith.cfapps.io/api/blogposts"
curl -I "https://stage-my-company-monolith.cfapps.io/api/projects"
# Testing if the latest DB schema is compatible with latest production application (DB schema backward compatibility testing).
production-on-staging-e2e:
<<: *defaults
steps:
- run:
name: End to end test on Staging of current production
command: |
curl -I "https://stage-my-company-monolith-prod.cfapps.io/health"
curl -I "https://stage-my-company-monolith-prod.cfapps.io/api/blogposts"
curl -I "https://stage-my-company-monolith-prod.cfapps.io/api/projects"
# Deploying build artifact on PWS production environment with Blue-Green deployment strategy and the rollback option.
# Build artifact is uploaded to AWS s3 as the latest production artifact in this stage. It is used within 'production-on-staging' and 'production-on-staging-e2e' jobs to test DB schema backward compatibility
production:
<<: *defaults
steps:
- attach_workspace:
at: workspace/
- run:
name: Install CloudFoundry CLI
command: |
curl -v -L -o cf-cli_amd64.deb 'https://cli.run.pivotal.io/stable?release=debian64&source=github'
sudo dpkg -i cf-cli_amd64.deb
cf -v
- run:
name: Install AWS CLI
command: sudo apt-get update && sudo apt-get install -y awscli
- deploy:
name: Deploy to Production - PWS CLoudFoundry (CF_PASSWORD variable required)
command: |
cf api https://api.run.pivotal.io
cf auth idugalic@gmail.com $CF_PASSWORD
cf target -o idugalic -s Prod
cf push prod-my-company-monolith-B -p workspace/*.jar --no-start
cf bind-service prod-my-company-monolith-B mysql
cf restart prod-my-company-monolith-B
# Map Original Route to Green
cf map-route prod-my-company-monolith-B cfapps.io -n prod-my-company-monolith
# Unmap temp Route to Green
cf unmap-route prod-my-company-monolith-B cfapps.io -n prod-my-company-monolith-B
# Unmap Route to Blue (only if Blue exist)
cf app prod-my-company-monolith && cf unmap-route prod-my-company-monolith cfapps.io -n prod-my-company-monolith
# Stop and rename current Blue in case you need to roll back your changes (only if Blue exist)
cf app prod-my-company-monolith && cf stop prod-my-company-monolith
cf app prod-my-company-monolith-old && cf delete prod-my-company-monolith-old -f
cf app prod-my-company-monolith && cf rename prod-my-company-monolith prod-my-company-monolith-old
# Rename Green to Blue
cf rename prod-my-company-monolith-B prod-my-company-monolith
- deploy:
name: Upload latest production artifact to AWS S3 (AWS Permissions on CircleCI required)
command: aws s3 sync workspace/ s3://my-company-production --delete --region eu-central-1
notify:
webhooks:
- url: https://webhook.atomist.com/atomist/circle
workflows:
version: 2
my-company-monolith-workflow:
jobs:
- build
- staging:
requires:
- build
filters:
branches:
only: master
- staging-e2e:
requires:
- staging
filters:
branches:
only: master
- production-on-staging:
requires:
- staging-e2e
filters:
branches:
only: master
- production-on-staging-e2e:
requires:
- production-on-staging
filters:
branches:
only: master
- approve-production:
type: approval
requires:
- production-on-staging-e2e
filters:
branches:
only: master
- production:
requires:
- approve-production
filters:
branches:
only: master