Skip to content

Commit 52b3477

Browse files
authored
Merge pull request #3 from wearefine/v2.0.0
Release V2.0.0
2 parents de523d7 + c51682d commit 52b3477

12 files changed

+471
-137
lines changed

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,50 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

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

7-
## [Unreleased] - TBD
8+
## [v2.0.0] - 6-1-2018
9+
10+
### Added
11+
12+
- DOCKER_REGISTRY_URL parameter - Private registry URL to use for fetching containers
13+
- DOCKER_REGISTRY_CREDS_ID parameter - CredentialsId to use to login to a private Docker registry
14+
- AWS_DEFAULT_REGION parameter - Used when using AWS resources such as Elastic Container Registry
15+
- Tests and deploys using Docker containers
16+
- Workspace is cleaned at the end of each run
17+
- All git information from checkout is now set in environment variables
18+
- Downstream jobs with parameters
819

920
## [v1.2.1] - 1-23-2018
21+
1022
- Fixed a bug with the cleanup step trying to clean DB and users that weren't created if SKIP_MIGRATIONS = 'true'
1123

1224
## [v1.2.0] - 1-23-2018
25+
1326
- SKIP_MIGRATIONS parameter - You can skip running migrations during tests
1427

1528
## [v1.1.1] - 11-17-2017
29+
1630
### Fixed
31+
1732
- MySQL query was trying to remove a user that wasn't there during the setup process
1833

1934
## [v1.1.0] - 11-16-2017
35+
2036
### Added
37+
2138
- SKIP_TESTS parameter so you can just deploy code
2239
- More debug output in railsRvm function
2340

2441
### Fixed
42+
2543
- ruby_string being undeclared
2644
- DEBUG not setting the env var when passing in true
2745

2846
### Updated
47+
2948
- railsinstallDeps is now its own function
3049
- railsDeploy is now its own function
3150
- SQL commands now clean old DBs, and Users before adding new ones at the start of the build

Jenkinsfile.clean_example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node {
2+
try {
3+
stage('Volume Clean') {
4+
sh 'docker volume prune -f'
5+
}
6+
currentBuild.result = 'SUCCESS'
7+
} catch(Exception e) {
8+
currentBuild.result = 'FAILURE'
9+
slackSend channel: '#devops', failOnError: true, color: 'danger', message: 'Jenkins Docker cleanup run *FAILED*!'
10+
throw e
11+
}
12+
slackSend channel: '#devops', failOnError: true, color: 'good', message: 'Jenkins Docker cleanup run *SUCCESSFUL*!'
13+
}

Jenkinsfile.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ rails {
1515
DEBUG = 'false'
1616
SKIP_TESTS = 'false'
1717
SKIP_MIGRATIONS = 'false'
18+
DOCKER_REGISTRY_CREDS_ID = 'access_docker_hub'
19+
DOCKER_REGISTRY_URL = 'https://hub.docker.io'
20+
AWS_DEFAULT_REGION = 'us-east-1'
21+
SKIP_DEPLOY = 'false'
22+
DOWNSTREAM_JOB_NAME = 'job_name'
23+
DOWNSTREAM_JOB_PARAMS = [string(name: 'rubyVersion', value: version), string(name: 'checksum', value: checksum))]
1824
}

README.md

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Testing your Rails project on every change should be a smooth process. With Jenk
77
### Rails Project
88

99
This pipeline job assumes your project has the following:
10+
1011
- Capistrano based deployments
1112
- Uses a single database the is cleaned up after each build
1213
- Testing is done on a single node without docker
@@ -16,26 +17,33 @@ This pipeline job assumes your project has the following:
1617
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.
1718

1819
#### OS
19-
- rvm installed in the jenkins user
20-
- git
21-
- build-essential
20+
21+
- rvm installed in the jenkins user
22+
- git
23+
- build-essential
2224

2325
#### Jenkins
24-
- Version: > 2.7.3 - tested on (2.19.4 LTS)
25-
26+
27+
- Version: > 2.7.3 - tested on (2.89.4 LTS)
28+
2629
#### Plugins
27-
- slack
28-
- pipeline (workflow-aggregator)
29-
- git
30-
- timestamper
31-
- credentials
32-
- sshagent
33-
- junit
30+
31+
- slack
32+
- pipeline (workflow-aggregator)
33+
- git
34+
- timestamper
35+
- credentials
36+
- sshagent
37+
- junit
38+
- docker
39+
- AWS ECR credentials
3440

3541
#### Scripts Approval
42+
3643
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.
3744

3845
### Manage with Puppet
46+
3947
The following modules work great to manage a Jenkins instance.
4048

4149
- maestrodev/rvm
@@ -61,6 +69,12 @@ rails {
6169
DEBUG = 'false'
6270
SKIP_TESTS = 'false'
6371
SKIP_MIGRATIONS = 'false'
72+
DOCKER_REGISTRY_CREDS_ID = 'access_docker_hub'
73+
DOCKER_REGISTRY_URL = 'https://hub.docker.io'
74+
AWS_DEFAULT_REGION = 'us-east-1'
75+
SKIP_DEPLOY = 'false'
76+
DOWNSTREAM_JOB_NAME = 'job_name'
77+
DOWNSTREAM_JOB_PARAMS = [string(name: 'rubyVersion', value: version), string(name: 'checksum', value: checksum))]
6478
}
6579
```
6680

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

89109
## Testing Framework Support
90110

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

98118
## Deploy Vars Configuration
99119

100-
If you need secure credentials in your deployment steps there is an input parameter that allows for this.
120+
If you need secure credentials in your deployment steps there is an input parameter that allows for this.
101121

102122
```groovy
103123
DEPLOY_VARS = [
104124
string(credentialsId: 'secret-text', variable: 'secret-text'),
105125
<credential-type>(credentialsId: <cred-id>, variable: <var-name>)
106126
]
107127
```
128+
108129
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.
109130

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

116137
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.
117138

118-
119139
## Test Results
140+
120141
All test results are assumed to be in JUnit format and placed in a single directory named `testresults`.
121142

122-
## [Changelog](CHANGELOG.md)
143+
## Docker Builds
123144

124-
## [MIT License](LICENSE)
145+
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.
146+
147+
**Note:** The current setup only works with AWS ECR but can easily be adapted to work with other private registries.
148+
149+
## [Changelog](CHANGELOG.md)
125150

151+
## [MIT License](LICENSE)

0 commit comments

Comments
 (0)