├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── src └── com │ └── wolox │ ├── ProjectConfiguration.groovy │ ├── docker │ └── DockerConfiguration.groovy │ ├── parser │ └── ConfigParser.groovy │ ├── services │ ├── Base.groovy │ ├── Elasticsearch.groovy │ ├── Mongodb.groovy │ ├── Mssql.groovy │ ├── Mysql.groovy │ ├── Postgis.groovy │ ├── Postgres.groovy │ └── Redis.groovy │ └── steps │ ├── Step.groovy │ └── Steps.groovy └── vars ├── base.groovy ├── buildSteps.groovy ├── deleteDockerImages.groovy ├── elasticsearch.groovy ├── mongodb.groovy ├── mssql.groovy ├── mysql.groovy ├── postgis.groovy ├── postgres.groovy ├── redis.groovy └── woloxCi.groovy /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We love pull requests from everyone. 4 | 5 | Fork, then clone the repo: 6 | 7 | git clone git@github.com:your-username/wolox-ci.git 8 | 9 | Make your changes, push to your fork and [submit a pull request][pr]. 10 | 11 | [pr]: https://github.com/Wolox/wolox-ci/compare/ 12 | 13 | At this point you're waiting on us. We like to at least comment on pull requests 14 | within three business days (and, typically, one business day). We may suggest 15 | some changes or improvements or alternatives. 16 | 17 | Please make sure to write a [good commit message][commit] :D 18 | 19 | [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010-2018 Google, Inc. http://angularjs.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Wolox CI 2 | 3 | This a Jenkins library built to make it easier for us at Wolox to configure pipelines without necessarily knowing about Jenkinsfile syntax. 4 | All our projects are built using a Dockerfile 5 | 6 | When using this library, your Jenkinsfile should look something like this: 7 | 8 | ``` 9 | @Library('wolox-ci') _ 10 | 11 | node { 12 | 13 | checkout scm 14 | 15 | woloxCi('.woloxci/config.yml'); 16 | } 17 | ``` 18 | 19 | It basically loads the library, clones the target repository and calls `woloxCi` to make its magic. 20 | As an argument, `woloxCi` receives the path to a configuration yaml file. 21 | This file looks something like this: 22 | 23 | ``` 24 | config: 25 | dockerfile: .woloxci/Dockerfile 26 | project_name: some-rails-project 27 | 28 | services: 29 | - mssql 30 | 31 | steps: 32 | analysis: 33 | - bundle exec rubocop -R app spec --format simple 34 | - bundle exec rubycritic --path ./analysis --minimum-score 80 --no-browser 35 | setup_db: 36 | - bundle exec rails db:create 37 | - bundle exec rails db:schema:load 38 | test: 39 | - bundle exec rspec 40 | security: 41 | - bundle exec brakeman --exit-on-error 42 | audit: 43 | - bundle audit check --update 44 | 45 | 46 | environment: 47 | RAILS_ENV: test 48 | GIT_COMMITTER_NAME: a 49 | GIT_COMMITTER_EMAIL: b 50 | LANG: C.UTF-8 51 | 52 | jenkinsEnvironment: 53 | - JENKINS_URL 54 | 55 | timeout: 600 56 | ``` 57 | 58 | This file has different sections: 59 | 60 | ## Configuration 61 | 62 | The section under the `config` label defines some basic configuration for this project: 63 | 1. The dockerfile that contains the image for the project to run. 64 | 2. The project name. 65 | 66 | ## Services 67 | 68 | This section lists the project's dependencies. Each section will define and expose some environment variables that might be needed by the application: 69 | 70 | ### Microsoft SQL 71 | 72 | When listing `mssql` as a service, this will build a docker image from [`microsoft/mssql-server-linux`](https://hub.docker.com/r/microsoft/mssql-server-linux/) exposing the following environment variables: 73 | 74 | 1. DB_USERNAME 75 | 2. DB_PASSWORD 76 | 3. DB_HOST 77 | 4. DB_PORT 78 | 79 | ### PostgreSQL 80 | 81 | When listing `postgres` as a service, this will build a docker image from [`postgres`](https://hub.docker.com/_/postgres/) exposing the following environment variables: 82 | 83 | 1. DB_USERNAME 84 | 2. DB_PASSWORD 85 | 3. DB_HOST 86 | 4. DB_PORT 87 | 88 | ### Redis 89 | 90 | When listing `redis` as a service, this will build a docker image from [`redis`](https://hub.docker.com/_/redis/) exposing the following environment variables: 91 | 92 | 1. REDIS_URL: the redis url that looks like this `redis://redis` 93 | 94 | ### MySQL 95 | 96 | When listing `mysql` as a service, this will build a docker image from [`mysql`](https://hub.docker.com/_/mysql/) exposing the following environment variables: 97 | 98 | 1. DB_USERNAME 99 | 2. DB_PASSWORD 100 | 3. DB_HOST 101 | 4. DB_PORT 102 | 103 | ### MongoDB 104 | 105 | When listing `mongo` as a service, this will build a docker image from [`mongo`](https://hub.docker.com/_/mongo/) exposing the following environment variables: 106 | 107 | 1. DB_USERNAME 108 | 2. DB_PASSWORD 109 | 3. DB_HOST 110 | 4. DB_PORT 111 | 112 | ### Elasticsearch 113 | 114 | When listing `elasticsearch:6.4.0` as a service (it's mandatory specify the image version), this will build a docker image from [`elasticsearch`](https://www.docker.elastic.co/) exposing the following environment variables: 115 | 116 | 1. ELASTICSEARCH_URL 117 | 118 | ## Steps 119 | 120 | This section lets you define the steps you need to build your project. Each level inside the `steps` section is a stage in the Jenkins pipeline and each item in the stage is a command to run. In the case above, there are 5 stages named: 121 | 122 | 1. analysis 123 | 2. setup_db 124 | 3. test 125 | 4. security 126 | 5. audit 127 | 128 | 129 | The analysis stage, for example, runs the following commands: 130 | 131 | 1. `bundle exec rubocop -R app spec --format simple` 132 | 2. `bundle exec rubycritic --path ./analysis --minimum-score 80 --no-browser` 133 | 134 | 135 | ## Environment 136 | 137 | This section lets you set up custom environment variables. Each item inside this section defines a variable with its value. 138 | 139 | ## Jenkins Environment 140 | 141 | This section lets you define what Jenkins environment values you want to pass to the docker image, i.e. JENKINS_URL. 142 | Bear in mind that, for convenience, Wolox CI already passes the following Jenkins Environment Variables to the Docker image by default: 143 | 144 | 1. BUILD_ID 145 | 2. BRANCH_NAME 146 | 3. CHANGE_ID 147 | 4. CHANGE_BRANCH (if job is PR-triggered) 148 | 5. CHANGE_TARGET (if job is PR-triggered) 149 | 150 | ## Timeout 151 | 152 | This section lets you set up a custom timeout in seconds. The default is 600 (10 minutes). 153 | -------------------------------------------------------------------------------- /src/com/wolox/ProjectConfiguration.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox; 2 | 3 | import com.wolox.docker.DockerConfiguration; 4 | import com.wolox.steps.Steps; 5 | 6 | class ProjectConfiguration { 7 | def environment; 8 | def services; 9 | Steps steps; 10 | def dockerfile; 11 | def projectName; 12 | def buildNumber; 13 | DockerConfiguration dockerConfiguration; 14 | def env; 15 | def timeout; 16 | } 17 | -------------------------------------------------------------------------------- /src/com/wolox/docker/DockerConfiguration.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.docker; 2 | 3 | import com.wolox.ProjectConfiguration; 4 | 5 | class DockerConfiguration { 6 | 7 | ProjectConfiguration projectConfiguration; 8 | 9 | def imageName() { 10 | "${reference()}:${tag()}".toLowerCase(); 11 | } 12 | 13 | def baseName() { 14 | "${projectConfiguration.projectName}".toLowerCase(); 15 | } 16 | 17 | def reference() { 18 | def env = projectConfiguration.env; 19 | "${baseName()}-${env.BRANCH_NAME}".toLowerCase(); 20 | } 21 | 22 | def tag() { 23 | def env = projectConfiguration.env; 24 | "${env.BUILD_ID}".toLowerCase(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/wolox/parser/ConfigParser.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.parser; 2 | 3 | import com.wolox.ProjectConfiguration; 4 | import com.wolox.docker.DockerConfiguration; 5 | import com.wolox.services.*; 6 | import com.wolox.steps.*; 7 | 8 | class ConfigParser { 9 | 10 | private static String LATEST = 'latest'; 11 | private static Integer DEFAULT_TIMEOUT = 600; // 600 seconds 12 | 13 | static ProjectConfiguration parse(def yaml, def env) { 14 | ProjectConfiguration projectConfiguration = new ProjectConfiguration(); 15 | 16 | projectConfiguration.buildNumber = env.BUILD_ID; 17 | 18 | // parse the environment variables and jenkins environment variables to be passed 19 | projectConfiguration.environment = parseEnvironment(yaml.environment, yaml.jenkinsEnvironment, env); 20 | 21 | // add Build Number environment variables 22 | projectConfiguration.environment.add("BUILD_ID=${env.BUILD_ID}"); 23 | 24 | // add SCM environment variables 25 | projectConfiguration.environment.add("BRANCH_NAME=${env.BRANCH_NAME.replace('origin/','')}"); 26 | projectConfiguration.environment.add("CHANGE_ID=${env.CHANGE_ID}"); 27 | 28 | if (env.CHANGE_ID) { 29 | projectConfiguration.environment.add("CHANGE_BRANCH=${env.CHANGE_BRANCH}"); 30 | projectConfiguration.environment.add("CHANGE_TARGET=${env.CHANGE_TARGET}"); 31 | } 32 | 33 | // parse the execution steps 34 | projectConfiguration.steps = parseSteps(yaml.steps); 35 | 36 | // parse the necessary services 37 | projectConfiguration.services = parseServices(yaml.services); 38 | 39 | // load the dockefile 40 | projectConfiguration.dockerfile = parseDockerfile(yaml.config); 41 | 42 | // load the project name 43 | projectConfiguration.projectName = parseProjectName(yaml.config); 44 | 45 | projectConfiguration.env = env; 46 | 47 | projectConfiguration.dockerConfiguration = new DockerConfiguration(projectConfiguration: projectConfiguration); 48 | 49 | projectConfiguration.timeout = yaml.timeout ?: DEFAULT_TIMEOUT; 50 | 51 | return projectConfiguration; 52 | } 53 | 54 | static def parseEnvironment(def environment, def jenkinsEnvironment, def env) { 55 | def config = []; 56 | 57 | if (environment) { 58 | config += environment.collect { k, v -> "${k}=${v}"}; 59 | } 60 | 61 | if (jenkinsEnvironment) { 62 | config += jenkinsEnvironment.collect { k -> "${k}=${env.getProperty(k)}"}; 63 | } 64 | 65 | return config; 66 | } 67 | 68 | static def parseSteps(def yamlSteps) { 69 | List steps = yamlSteps.collect { k, v -> 70 | Step step = new Step(name: k) 71 | 72 | // a step can have one or more commands to execute 73 | v.each { 74 | step.commands.add(it); 75 | } 76 | return step 77 | } 78 | return new Steps(steps: steps); 79 | } 80 | 81 | static def parseServices(def steps) { 82 | def services = []; 83 | 84 | steps.each { 85 | def service = it.tokenize(':') 86 | def version = service.size() == 2 ? service.get(1) : LATEST 87 | def instance = getServiceClass(service.get(0).capitalize())?.newInstance() 88 | 89 | services.add([service: instance, version: version]) 90 | }; 91 | 92 | services.add([service: new Base(), version: LATEST]); 93 | 94 | return services 95 | } 96 | 97 | static def getServiceClass(def name) { 98 | // TODO: Refactor this 99 | switch(name) { 100 | case "Postgres": 101 | return Postgres 102 | break 103 | case "Postgis": 104 | return Postgis 105 | break 106 | case "Redis": 107 | return Redis 108 | break 109 | case "Mssql": 110 | return Mssql 111 | break 112 | case "Mysql": 113 | return Mysql 114 | break 115 | case "Mongodb": 116 | return Mongodb 117 | break 118 | case "Elasticsearch": 119 | return Elasticsearch 120 | break 121 | } 122 | } 123 | 124 | static def parseDockerfile(def config) { 125 | if (!config || !config["dockerfile"]) { 126 | return "Dockerfile"; 127 | } 128 | 129 | return config["dockerfile"]; 130 | } 131 | 132 | static def parseProjectName(def config) { 133 | if (!config || !config["project_name"]) { 134 | return "woloxci-project"; 135 | } 136 | 137 | return config["project_name"]; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/com/wolox/services/Base.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Base { 4 | def getVar() { 5 | return "base" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/wolox/services/Elasticsearch.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Elasticsearch { 4 | def getVar() { 5 | return "elasticsearch" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/wolox/services/Mongodb.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Mongodb { 4 | def getVar() { 5 | return "mongodb" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/wolox/services/Mssql.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Mssql { 4 | def getVar() { 5 | return "mssql" 6 | } 7 | } -------------------------------------------------------------------------------- /src/com/wolox/services/Mysql.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Mysql { 4 | def getVar() { 5 | return "mysql" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/wolox/services/Postgis.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Postgis { 4 | def getVar() { 5 | return "postgis" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/wolox/services/Postgres.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Postgres { 4 | def getVar() { 5 | return "postgres" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/wolox/services/Redis.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.services; 2 | 3 | class Redis { 4 | def getVar() { 5 | return "redis" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/wolox/steps/Step.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.steps; 2 | 3 | class Step { 4 | List commands = []; 5 | String name; 6 | } 7 | -------------------------------------------------------------------------------- /src/com/wolox/steps/Steps.groovy: -------------------------------------------------------------------------------- 1 | package com.wolox.steps; 2 | 3 | class Steps { 4 | List steps; 5 | 6 | def getVar(def dockerImage) { 7 | return "buildSteps" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vars/base.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def _, def nextClosure) { 5 | return { variables -> 6 | timeout(time: projectConfig.timeout, unit: 'SECONDS') { 7 | withEnv(projectConfig.environment) { 8 | wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) { 9 | nextClosure(variables) 10 | } 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vars/buildSteps.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | import com.wolox.steps.Step; 4 | 5 | def call(ProjectConfiguration projectConfig, def dockerImage) { 6 | return { variables -> 7 | List stepsA = projectConfig.steps.steps 8 | def links = variables.collect { k, v -> "--link ${v.id}:${k}" }.join(" ") 9 | dockerImage.inside(links) { 10 | stepsA.each { step -> 11 | stage(step.name) { 12 | step.commands.each { command -> 13 | sh command 14 | } 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /vars/deleteDockerImages.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig) { 5 | def reference = projectConfig.dockerConfiguration.reference(); 6 | try { 7 | sh "docker images --filter 'reference=${reference}*' --format \"{{.Tag}} {{.Repository}}:{{.Tag}}\" | sort -n | sed '\$d' | awk '{ print \$2 }' | xargs --no-run-if-empty docker rmi" 8 | 9 | } catch(ignored) { 10 | // this would make the entire popeline fail. We don't want that 11 | println ignored 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vars/elasticsearch.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def version, def nextClosure) { 5 | return { variables -> 6 | /* Build elasticsearch image */ 7 | docker.image("docker.elastic.co/elasticsearch/elasticsearch:${version}").withRun("-e \"discovery.type=single-node\"") { elasticsearch -> 8 | withEnv(["ELASTICSEARCH_URL=http://elasticsearch:9200"]) { 9 | variables.elasticsearch = elasticsearch; 10 | nextClosure(variables) 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vars/mongodb.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def version, def nextClosure) { 5 | return { variables -> 6 | def dbUser = 'mongoadmin' 7 | def dbPassword = 'my-secret-pw' 8 | /* Build mongodb image */ 9 | docker.image("mongo:${version}").withRun("-e \"MONGO_INITDB_ROOT_USERNAME=${dbUser}\" -e \"MONGO_INITDB_ROOT_PASSWORD=${dbPassword}\"") { db -> 10 | withEnv(["DB_USERNAME=${dbUser}", "DB_PASSWORD=${dbPassword}", "DB_HOST=db", "DB_PORT=27017"]) { 11 | variables.db = db; 12 | nextClosure(variables) 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vars/mssql.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def version, def nextClosure) { 5 | return { variables -> 6 | def dbPassword = 'someReallyStrongPwd123' 7 | /* Build mssql image */ 8 | docker.image("microsoft/mssql-server-linux:${version}").withRun("-e \"ACCEPT_EULA=Y\" -e \"SA_PASSWORD=${dbPassword}\"") { db -> 9 | withEnv(['DB_USERNAME=sa', "DB_PASSWORD=${dbPassword}", "DB_HOST=db", "DB_PORT=1433"]) { 10 | variables.db = db; 11 | nextClosure(variables) 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /vars/mysql.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def version, def nextClosure) { 5 | return { variables -> 6 | def dbPassword = 'my-secret-pw' 7 | /* Build mysql image */ 8 | docker.image("mysql:${version}").withRun("-e \"MYSQL_ROOT_PASSWORD=${dbPassword}\"") { db -> 9 | withEnv(['DB_USERNAME=root', "DB_PASSWORD=${dbPassword}", "DB_HOST=db", "DB_PORT=3306"]) { 10 | variables.db = db; 11 | nextClosure(variables) 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /vars/postgis.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def version, def nextClosure) { 5 | return { variables -> 6 | /* Build postgres image with postgis support */ 7 | docker.image("mdillon/postgis:${version}").withRun() { db -> 8 | withEnv(['DB_USERNAME=postgres', 'DB_PASSWORD=', "DB_HOST=db", "DB_PORT=5432"]) { 9 | variables.db = db; 10 | nextClosure(variables) 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vars/postgres.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def version, def nextClosure) { 5 | return { variables -> 6 | /* Build postgres image */ 7 | docker.image("postgres:${version}").withRun('-e POSTGRES_HOST_AUTH_METHOD=trust') { db -> 8 | withEnv(['DB_USERNAME=postgres', 'DB_PASSWORD=', "DB_HOST=db", "DB_PORT=5432"]) { 9 | variables.db = db; 10 | nextClosure(variables) 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vars/redis.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.*; 3 | 4 | def call(ProjectConfiguration projectConfig, def version, def nextClosure) { 5 | return { variables -> 6 | /* Build redis image */ 7 | docker.image("redis:${version}").withRun() { redis -> 8 | withEnv(["REDIS_URL=redis://redis"]) { 9 | variables.redis = redis; 10 | nextClosure(variables) 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vars/woloxCi.groovy: -------------------------------------------------------------------------------- 1 | @Library('wolox-ci') 2 | import com.wolox.parser.ConfigParser; 3 | import com.wolox.*; 4 | 5 | def call(String yamlName) { 6 | def yaml = readYaml file: yamlName; 7 | 8 | def buildNumber = Integer.parseInt(env.BUILD_ID); 9 | 10 | // load project's configuration 11 | ProjectConfiguration projectConfig = ConfigParser.parse(yaml, env); 12 | 13 | def imageName = projectConfig.dockerConfiguration.imageName().toLowerCase(); 14 | 15 | // build the image specified in the configuration 16 | def customImage = docker.build(imageName, "--file ${projectConfig.dockerfile} ."); 17 | 18 | // adds the last step of the build. 19 | def closure = buildSteps(projectConfig, customImage); 20 | 21 | // each service is a closure that when called it executes its logic and then calls a closure, the next step. 22 | projectConfig.services.each { 23 | 24 | closure = "${it.service.getVar()}"(projectConfig, it.version, closure); 25 | } 26 | 27 | // we execute the top level closure so that the cascade starts. 28 | try { 29 | closure([:]); 30 | } finally{ 31 | deleteDockerImages(projectConfig); 32 | } 33 | } 34 | --------------------------------------------------------------------------------