Building a project » History » Version 1
Olivier Bitsch, 06/25/2021 10:58 AM
| 1 | 1 | Olivier Bitsch | # Notify your builder-ci to care of a build |
|---|---|---|---|
| 2 | |||
| 3 | Building any project requires to send a POST with more or less information about the project you wish to build. There are several method to trigger a build: |
||
| 4 | |||
| 5 | * Use git hooks (preferred) |
||
| 6 | * Use curl |
||
| 7 | * Use postman or similar |
||
| 8 | |||
| 9 | ## Using git hooks |
||
| 10 | |||
| 11 | Git hooks is the best way to notify your builder that a new change in your source code is required to be build. Two examples are provided into `/usr/share/doc/builder-ci/helpers/` folders. |
||
| 12 | |||
| 13 | * git-core.py : this is an example when using with a git bare folder. It fits perfectly when you use Redmine with Git. Copy and adapt this file into <git bare>/.git/hooks/post-receive (don't forget to add execution bit with `chmod +x <git bare>/.git/hooks/post-receive`). |
||
| 14 | * gitolite_hooks.py : use this file if you use gitolite. Copy and adapt this file into /<gitolite-path>/local/hooks/common/post-receive.d |
||
| 15 | |||
| 16 | In all case, you will have to adapt in order to configure `builder_url` and `git_url` which is base git url. |
||
| 17 | |||
| 18 | ## Using curl |
||
| 19 | |||
| 20 | You can use curl with the similar format |
||
| 21 | |||
| 22 | ~~~ bash |
||
| 23 | json='{ |
||
| 24 | "project": "builder-ci", |
||
| 25 | "sources": { |
||
| 26 | "method": "git", |
||
| 27 | "options": { |
||
| 28 | "url": "https://github.com/iabsis/builder-ci", |
||
| 29 | "branch": "master" |
||
| 30 | } |
||
| 31 | }, |
||
| 32 | "builder": { |
||
| 33 | "method": "docker", |
||
| 34 | "options": { |
||
| 35 | "image": "builder-bullseye" |
||
| 36 | } |
||
| 37 | }, |
||
| 38 | "notify": { |
||
| 39 | "method": "redmine" |
||
| 40 | } |
||
| 41 | }' |
||
| 42 | ~~~ |
||
| 43 | |||
| 44 | And trigger your build with |
||
| 45 | |||
| 46 | ~~~ bash |
||
| 47 | curl -X 'POST' \ |
||
| 48 | 'http://localhost:5000/build' \ |
||
| 49 | -H 'accept: application/json' \ |
||
| 50 | -H 'Content-Type: application/json' \ |
||
| 51 | -d ${json} |
||
| 52 | ~~~ |
||
| 53 | |||
| 54 | Of course change localhost if you put your builder onto an IP address or domain name. |
||
| 55 | |||
| 56 | ## Using postman |
||
| 57 | |||
| 58 | Simply send a POST of the following json to `http://<ip of your server>:5000/build` |
||
| 59 | |||
| 60 | ~~~ json |
||
| 61 | { |
||
| 62 | "project": "builder-ci", |
||
| 63 | "sources": { |
||
| 64 | "method": "git", |
||
| 65 | "options": { |
||
| 66 | "url": "https://github.com/iabsis/builder-ci", |
||
| 67 | "branch": "master" |
||
| 68 | } |
||
| 69 | }, |
||
| 70 | "builder": { |
||
| 71 | "method": "docker", |
||
| 72 | "options": { |
||
| 73 | "image": "builder-bullseye" |
||
| 74 | } |
||
| 75 | }, |
||
| 76 | "notify": { |
||
| 77 | "method": "redmine" |
||
| 78 | } |
||
| 79 | } |
||
| 80 | ~~~ |
||
| 81 | |||
| 82 | # Steps and Methods |
||
| 83 | |||
| 84 | Before understand the Json format, you have to know that Builder-CI will run step into this following order: |
||
| 85 | |||
| 86 | 1. **sources (mandatory)**: provide methods to fetch source code. The supported method is only git for now, but can be extended in the future. |
||
| 87 | 1. **patcher (optional)**: provide methods to alter the source code. There is no supported option for now, but patching will be extended in the future. |
||
| 88 | 1. **builder (mandatory)**: provide methods to builder your source code. Methods available are docker, pbuilder and rpmbuild. |
||
| 89 | 1. **publish (mandatory)**: provide methods to publish your artifacts resulting of your build. Methods available are createrepo, local-folder, redmine and apt-ftparchive. |
||
| 90 | |||
| 91 | At each step, the following additional step is executed: |
||
| 92 | |||
| 93 | 1. **notify (optional)**: provide methods to update the build status. Method available is only redmine, but can be extended in the future. |
||
| 94 | |||
| 95 | # Json format |
||
| 96 | |||
| 97 | The json format to be send is the following: |
||
| 98 | |||
| 99 | ~~~ json |
||
| 100 | { |
||
| 101 | "project": "<project name>", |
||
| 102 | "<step>": { |
||
| 103 | "method": "<method>", |
||
| 104 | "options": { |
||
| 105 | "<option 1>": "<value 1>", |
||
| 106 | "<option 2>": "<value 2>" |
||
| 107 | } |
||
| 108 | }, |
||
| 109 | "<step>": { |
||
| 110 | "method": "<method>", |
||
| 111 | "options": { |
||
| 112 | "<option 1>": "<value 1>" |
||
| 113 | } |
||
| 114 | }, |
||
| 115 | ... |
||
| 116 | } |
||
| 117 | ~~~ |
||
| 118 | |||
| 119 | By example: |
||
| 120 | |||
| 121 | ~~~ json |
||
| 122 | { |
||
| 123 | "project": "builder-ci", |
||
| 124 | "sources": { |
||
| 125 | "method": "git", |
||
| 126 | "options": { |
||
| 127 | "url": "https://projects.iabsis.com/git/builder-ci", |
||
| 128 | "branch": "master" |
||
| 129 | } |
||
| 130 | }, |
||
| 131 | "builder": { |
||
| 132 | "method": "docker", |
||
| 133 | "options": { |
||
| 134 | "image": "builder-bullseye" |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | ~~~ |
||
| 139 | |||
| 140 | Means: |
||
| 141 | |||
| 142 | 1. git method is called at step sources. Gets sources code on https://projects.iabsis.com/git/builder-ci and branch master. |
||
| 143 | 2. not method called at optional step patcher, this step will not be run. |
||
| 144 | 3. docker method called at step builder. Use image builder-bullseye to make the build. |
||
| 145 | 4. not method defined for mandatory step publish, auto method will be defined instead. |
||
| 146 | 5. not method defined for optional step notify, this step will not be run. |
||
| 147 | |||
| 148 | You can get an generated json file with all method and options available here : https://projects.iabsis.com/projects/builder-ci/files |
||
| 149 | |||
| 150 | # Yaml format |
||
| 151 | |||
| 152 | In case of you wish to let the project itself configure how it should be built, you can add a file called `builder.yml` in root of your source code project. This file can contain more or less the same data than the json, excepted step "sources" and attribute "project". |
||
| 153 | |||
| 154 | By example |
||
| 155 | |||
| 156 | ~~~ |
||
| 157 | builder: |
||
| 158 | - method: docker |
||
| 159 | options: |
||
| 160 | image: builder-centos8 |
||
| 161 | env: |
||
| 162 | SPEC_PATH: redhat/builder.spec |
||
| 163 | publish: |
||
| 164 | - method: redmine |
||
| 165 | options: |
||
| 166 | file: builder.rpm |
||
| 167 | ~~~ |
||
| 168 | |||
| 169 | ## Fallback options into builder.conf |
||
| 170 | |||
| 171 | If you don't want to exposed sensitive data, you can configure fallback options into file `/etc/builder-ci/builder-ci.conf`. If an option is requires by a method (e.g. api key for redmine publish method), this options can be picked from the configuration file. |
||
| 172 | |||
| 173 | ~~~ conf |
||
| 174 | [redmine] |
||
| 175 | |||
| 176 | url = http://<redmine url>/ |
||
| 177 | key = abcd1234efgh |
||
| 178 | ~~~ |
||
| 179 | |||
| 180 | ## Methods and Options overriding order |
||
| 181 | |||
| 182 | In case of you define the same option into yml + json POST + configuration file, the options will be picked in this order: |
||
| 183 | |||
| 184 | 1. Attempt to get methods and options from YML |
||
| 185 | 2. If no methods in YML, attempt to get methods and options from json POST |
||
| 186 | 3. If no methods defined in both YML or json POST, try to guess automatically the methods |
||
| 187 | 4. If option requested by method is missing from both YML or json POST, try to get value into config file. |
||
| 188 | |||
| 189 | ## About meta |
||
| 190 | |||
| 191 | Meta are pair of key/value fetched by various methods during build. By example git method will return commit_id which will be then used by redmine notify method. Main different between options and meta is meta is available globally while options is specific for the method currently ran. |