Skip to content

Commit

Permalink
Merge pull request #3 from wearefine/v2.0.0
Browse files Browse the repository at this point in the history
Release V2.0.0
  • Loading branch information
cpitkin authored Jun 8, 2018
2 parents de523d7 + c51682d commit 52b3477
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 137 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased] - TBD
## [v2.0.0] - 6-1-2018

### Added

- DOCKER_REGISTRY_URL parameter - Private registry URL to use for fetching containers
- DOCKER_REGISTRY_CREDS_ID parameter - CredentialsId to use to login to a private Docker registry
- AWS_DEFAULT_REGION parameter - Used when using AWS resources such as Elastic Container Registry
- Tests and deploys using Docker containers
- Workspace is cleaned at the end of each run
- All git information from checkout is now set in environment variables
- Downstream jobs with parameters

## [v1.2.1] - 1-23-2018

- Fixed a bug with the cleanup step trying to clean DB and users that weren't created if SKIP_MIGRATIONS = 'true'

## [v1.2.0] - 1-23-2018

- SKIP_MIGRATIONS parameter - You can skip running migrations during tests

## [v1.1.1] - 11-17-2017

### Fixed

- MySQL query was trying to remove a user that wasn't there during the setup process

## [v1.1.0] - 11-16-2017

### Added

- SKIP_TESTS parameter so you can just deploy code
- More debug output in railsRvm function

### Fixed

- ruby_string being undeclared
- DEBUG not setting the env var when passing in true

### Updated

- railsinstallDeps is now its own function
- railsDeploy is now its own function
- SQL commands now clean old DBs, and Users before adding new ones at the start of the build
Expand Down
13 changes: 13 additions & 0 deletions Jenkinsfile.clean_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node {
try {
stage('Volume Clean') {
sh 'docker volume prune -f'
}
currentBuild.result = 'SUCCESS'
} catch(Exception e) {
currentBuild.result = 'FAILURE'
slackSend channel: '#devops', failOnError: true, color: 'danger', message: 'Jenkins Docker cleanup run *FAILED*!'
throw e
}
slackSend channel: '#devops', failOnError: true, color: 'good', message: 'Jenkins Docker cleanup run *SUCCESSFUL*!'
}
6 changes: 6 additions & 0 deletions Jenkinsfile.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ rails {
DEBUG = 'false'
SKIP_TESTS = 'false'
SKIP_MIGRATIONS = 'false'
DOCKER_REGISTRY_CREDS_ID = 'access_docker_hub'
DOCKER_REGISTRY_URL = 'https://hub.docker.io'
AWS_DEFAULT_REGION = 'us-east-1'
SKIP_DEPLOY = 'false'
DOWNSTREAM_JOB_NAME = 'job_name'
DOWNSTREAM_JOB_PARAMS = [string(name: 'rubyVersion', value: version), string(name: 'checksum', value: checksum))]
}
58 changes: 42 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Testing your Rails project on every change should be a smooth process. With Jenk
### Rails Project

This pipeline job assumes your project has the following:

- Capistrano based deployments
- Uses a single database the is cleaned up after each build
- Testing is done on a single node without docker
Expand All @@ -16,26 +17,33 @@ This pipeline job assumes your project has the following:
If you're new to Jenkins pipelines you should go read the [documentation](https://jenkins.io/doc/book/pipeline/) before proceeding to get a sense for what to expect using this code. The rest of the setup process will assume you have basic knowledge of Jenkins or CI/CD jobs in general.

#### OS
- rvm installed in the jenkins user
- git
- build-essential

- rvm installed in the jenkins user
- git
- build-essential

#### Jenkins
- Version: > 2.7.3 - tested on (2.19.4 LTS)


- Version: > 2.7.3 - tested on (2.89.4 LTS)

#### Plugins
- slack
- pipeline (workflow-aggregator)
- git
- timestamper
- credentials
- sshagent
- junit

- slack
- pipeline (workflow-aggregator)
- git
- timestamper
- credentials
- sshagent
- junit
- docker
- AWS ECR credentials

#### Scripts Approval

When the job runs the first time you will need to work through allowing certain functions to execute in the groovy sandbox. This is normal as not all high use groovy functions are in the default safelist but more are added all the time.

### Manage with Puppet

The following modules work great to manage a Jenkins instance.

- maestrodev/rvm
Expand All @@ -61,6 +69,12 @@ rails {
DEBUG = 'false'
SKIP_TESTS = 'false'
SKIP_MIGRATIONS = 'false'
DOCKER_REGISTRY_CREDS_ID = 'access_docker_hub'
DOCKER_REGISTRY_URL = 'https://hub.docker.io'
AWS_DEFAULT_REGION = 'us-east-1'
SKIP_DEPLOY = 'false'
DOWNSTREAM_JOB_NAME = 'job_name'
DOWNSTREAM_JOB_PARAMS = [string(name: 'rubyVersion', value: version), string(name: 'checksum', value: checksum))]
}
```

Expand All @@ -85,6 +99,12 @@ rails {
- **DEBUG:** Turn off Slack notifications and turn on more console output. [String] Default: false
- **SKIP_TESTS:** Don't run tests just checkout and deploy [String] Default: false
- **SKIP_MIGRATIONS:** Don't setup a database or run migrations. [String] Default: false
- **DOCKER_REGISTRY_URL:** The private Docker registry URL. Required to build with Docker. [String]
- **DOCKER_REGISTRY_CREDS_ID:** The private Docker registry credentials ID in Jenkins. Required to build with Docker. [String]
- **AWS_DEFAULT_REGION:** The AWS region of you Elastic Container Registry
- **SKIP_DEPLOY:** Do you want to skip deploying the code [String] Default: false
- **DOWNSTREAM_JOB_NAME:** Required if DOWNSTREAM_JOB_PARAMS is not null or empty. The name of the downstream job you wish to run. [String]
- **DOWNSTREAM_JOB_PARAMS:** Special map of parameters and their corresponding values to pass to the downstream job. [Map]

## Testing Framework Support

Expand All @@ -97,14 +117,15 @@ Testing supports rspec or minitest based on the test directory name. If it is un

## Deploy Vars Configuration

If you need secure credentials in your deployment steps there is an input parameter that allows for this.
If you need secure credentials in your deployment steps there is an input parameter that allows for this.

```groovy
DEPLOY_VARS = [
string(credentialsId: 'secret-text', variable: 'secret-text'),
<credential-type>(credentialsId: <cred-id>, variable: <var-name>)
]
```

I went ahead and left the first item in the list the same as above but changed the second to include explanations of the values. You can find these in the pipeline syntax section of a pipeline job. Once there select the `withCredentials` step. Then add the credentials needed for the deploy step and click generate code. It will generate code that looks like the below example.

```groovy
Expand All @@ -115,11 +136,16 @@ withCredentials([string(credentialsId: 'secret-test-stuff', variable: 'testing')

You will notice that inside the `withCredentials` method there is a list of values. This is the list that you need to copy and paste (as is) into the `DEPLOY_VARS` parameter.


## Test Results

All test results are assumed to be in JUnit format and placed in a single directory named `testresults`.

## [Changelog](CHANGELOG.md)
## Docker Builds

## [MIT License](LICENSE)
If a Dockerfile is present in the repo and `DOCKER_REGISTRY_URL` and `DOCKER_REGISTRY_CREDS_ID` are set builds will run with Docker. A sidcar MySQL container is spun up to use for the build then deleted when the build completes. All containers are cleaned up after the build completes. Gems are stored in a Docker volume per project per branch (eg. mysite_master-gems). This allows for faster builds since gems are cached between runs. Since this can lead to filling up the disk quickly it is recommended that you run a periodic clean job to remove old volumes. See Jenkinsfile.clean_example.

**Note:** The current setup only works with AWS ECR but can easily be adapted to work with other private registries.

## [Changelog](CHANGELOG.md)

## [MIT License](LICENSE)
Loading

0 comments on commit 52b3477

Please sign in to comment.