This app is for testing continuous deployments on cloud.gov.
This is a basic Node.js app that outputs a simple message.
The app has development, test, and production environments in cloud.gov Each of these environments is contained in its own cloud.gov space.
Travis CI is configured to run the app's unit tests and, if tests are successful, deploy the code to cloud.gov. Travis CI is configured with environment variables containing a deployer account's credentials. This allows Travis CI to connect to the cloud.gov API and push the app.
Development:
- Developer pushes a change to the
dev
branch on GitHub - Travis CI detects the push, and runs tests
- If tests pass, Travis CI deploys to the cloud.gov dev environment
Testing:
- Developer merges the
dev
branch into thetest
branch - Developer pushes the updated
test
branch to GitHub - Travis CI detects the push to
test
, and runs tests - If tests pass, Travis CI deploys to the cloud.gov test environment
- Users can test the app in the test environment
Production:
- Developer merges the
test
branch into themaster
branch - Developer or ops engineer does a
cf push
to manually deploy to production
Here is how to reproduce this environment.
Create a new space for each environment (dev, test, prod, etc) in which the app will run (or just use the org's sandbox
space). This example uses a development environment, a test environment, and a production environment.
Example:
cf create-space workshop-dev
cf create-space workshop-test
cf create-space workshop-prod
Provision a deployer account for each space you want Travis CI to continuously deploy to. Make a note of the new usernames and passwords that cloud.gov creates for you; you will input this into Travis CI later.
This example will continuously deploy to the development and test environments, while requiring a manual deployment to production. Because we are manually deploying to production, we do not create a deployer account for the workshop-prod
space in this example.
Example:
cf target -o gsa-cto -s workshop-dev
cf create-service cloud-gov-service-account space-deployer workshop-dev-deployer
cf target -o gsa-cto -s workshop-test
cf create-service cloud-gov-service-account space-deployer workshop-test-deployer
Either create a new repository and commit a simple app, or fork this repository.
Ensure you have the following files in your repository, and configure them as appropriate.
We actually have three manifest files. Make sure you set an unique name in each file:
manifest.dev.yml
- configures the development environmentmanifest.test.yml
- configures the test environmentmanifest.yml
- configures the production environment
The .travis.yml
file tells Travis CI how to deploy the app. There are two sections under deploy
. One is for dev and one is for test. Make sure the space
fields match whatever spaces you created in cloud.gov (or use sandbox
).
Connect your GitHub account to Travis CI.
On your Travis CI profile page, enable builds for your GitHub repo.
Add environment variables to Travis CI settings. These should match the deployer account credentials you created in step [1.2](1.2 Provision deployer accounts):
DEV_DEPLOYER_USERNAME
DEV_DEPLOYER_PASSWORD
TEST_DEPLOYER_USERNAME
TEST_DEPLOYER_PASSWORD
Note that .travis.yml
makes references to these environment variables. This is how Travis CI authenticates to cloud.gov when deploying to the dev and test environments.
Here are the cloud.gov sandboxes that this demo runs in: