|
| 1 | +--- |
| 2 | +title: biicode deployment |
| 3 | +layout: en |
| 4 | +permalink: biicode/ |
| 5 | +--- |
| 6 | + |
| 7 | +Travis CI can automatically publish your [biicode](https://www.biicode.com) blocks after a successful deploy. |
| 8 | + |
| 9 | +For a minimal configuration, all you need to do is add the following to you `.travis.yml`: |
| 10 | + |
| 11 | +{% highlight yaml %} |
| 12 | +deploy: |
| 13 | + provider: biicode |
| 14 | + user: "YOUR_USER" |
| 15 | + password: "YOUR_PASSWORD" # should be encrypted |
| 16 | +{% endhighlight %} |
| 17 | + |
| 18 | +Install Travis CI command line client to encrypt your password like this: |
| 19 | + |
| 20 | +{% highlight console %} |
| 21 | +$ travis encrypt "YOUR PASSWORD" --add deploy.password |
| 22 | +{% endhighlight %} |
| 23 | + |
| 24 | +You can also have the `travis` tool set everything up for you: |
| 25 | + |
| 26 | +{% highlight console %} |
| 27 | +$ travis setup biicode |
| 28 | +{% endhighlight %} |
| 29 | + |
| 30 | +Keep in mind that the setup command has to run in your project directory, so it can modify the `.travis.yml` for you. |
| 31 | + |
| 32 | +### Branch to deploy from |
| 33 | + |
| 34 | +You can also explicitly specify the branch to deploy from with the **on** option: |
| 35 | + |
| 36 | +{% highlight yaml %} |
| 37 | +deploy: |
| 38 | + provider: biicode |
| 39 | + user: ... |
| 40 | + password: ... |
| 41 | + on: production |
| 42 | +{% endhighlight %} |
| 43 | + |
| 44 | +Alternatively, you can also configure Travis CI to deploy from all branches: |
| 45 | + |
| 46 | +{% highlight yaml %} |
| 47 | +deploy: |
| 48 | + provider: biicode |
| 49 | + user: ... |
| 50 | + password: ... |
| 51 | + on: |
| 52 | + all_branches: true |
| 53 | +{% endhighlight %} |
| 54 | + |
| 55 | +Builds triggered from Pull Requests will never trigger a deploy. |
| 56 | + |
| 57 | +### Deploying build artifacts |
| 58 | + |
| 59 | +After your tests ran and before the deploy, Travis CI will clean up any additional files and changes you made. |
| 60 | + |
| 61 | +Maybe that is not what you want, as you might generate some artifacts that are supposed to be deployed too (like dependencies' data). There is now an option to skip the clean up: |
| 62 | + |
| 63 | +{% highlight yaml %} |
| 64 | +deploy: |
| 65 | + provider: biicode |
| 66 | + user: ... |
| 67 | + password: ... |
| 68 | + skip_cleanup: true |
| 69 | +{% endhighlight %} |
| 70 | + |
| 71 | +### Conditional Deploys |
| 72 | + |
| 73 | +You can run deploy only when certain conditions are met. |
| 74 | +See [Conditional Releases with `on:`](/user/deployment#Conditional-Releases-with-on%3A). |
| 75 | + |
| 76 | +### Running commands before and after deploy |
| 77 | + |
| 78 | +You can use the `before_deploy` and `after_deploy` stages to run commands just before and after the deploy is done. These will only be triggered if Travis CI is actually deploying. |
| 79 | + |
| 80 | +{% highlight yaml %} |
| 81 | +before_deploy: "echo 'ready to publish?'" |
| 82 | +deploy: |
| 83 | + .. |
| 84 | + after_deploy: |
| 85 | + - bii deps --detail |
| 86 | +{% endhighlight %} |
| 87 | + |
| 88 | +### Using biicode in your deploy |
| 89 | + |
| 90 | +Add this to your `install:` entry to install biicode in your build machine: |
| 91 | + |
| 92 | +{% highlight yaml %} |
| 93 | +install: |
| 94 | + - wget http://apt.biicode.com/install.sh && chmod +x install.sh && ./install.sh |
| 95 | + - bii setup:cpp |
| 96 | +{% endhighlight %} |
| 97 | + |
| 98 | +This downloads a script to install biicode on Debian-based distros, as explained in [biicode docs](http://docs.biicode.com/c++/installation.html#alternative-install-debian) and executes a biicode command to set up required tools for C/C++ development. It actually installs CMake. |
| 99 | + |
| 100 | +Now you're ready to use biicode in the build virtual machine. All biicode commands are available. Note: build changes made before performing the deploy are discarded except disabled with the `skip_cleanup` flag (See *"Deploying build artifacts"*). |
| 101 | + |
| 102 | +It's a good practice to check biicode's version after installing: |
| 103 | + |
| 104 | +{% highlight yaml %} |
| 105 | +install |
| 106 | + ... |
| 107 | + - bii --version |
| 108 | +{% endhighlight %} |
| 109 | + |
| 110 | + |
| 111 | +### A simple biicode deployment example step by step |
| 112 | + |
| 113 | +Let's say you have a C++ math library called *CppMath*. It's hosted in github and you are running some unit tests via Travis CI. |
| 114 | +Deploy your CppMath library to biicode, a C and C++ dependency manager, make it available for everybody to use via an `#include`! |
| 115 | + |
| 116 | +Use Travis CI with biicode to automatize* the process: |
| 117 | + |
| 118 | + - Run some unit tests on the library |
| 119 | + - Use `bii publish` command to deploy to biicode. |
| 120 | + |
| 121 | +Here's [CppMath example code](https://github.com/Manu343726/CppMath/), it's structured as a `manu343726/cppmath` biicode block. *manu343726 is the biicode developer who wrote the example, hence that user instead of `developer`.* |
| 122 | + |
| 123 | +Supposing your biicode account is `developer`, create a `.travis.yml` file to automatize deploy and publish like this: |
| 124 | + |
| 125 | +{% highlight yaml %} |
| 126 | +install: |
| 127 | + - wget http://apt.biicode.com/install.sh && chmod +x install.sh && ./install.sh #Install biicode |
| 128 | + - bii setup:cpp #Install biicode required C/C++ tools (GCC, cmake, etc) |
| 129 | +script: |
| 130 | + - bii find --update #Find biicode dependencies |
| 131 | + - bii cpp:configure #Configure block for building |
| 132 | + - bii cpp:build #Build block |
| 133 | + - ./bin/developer_cppmath_tests --reporter=info #Run tests |
| 134 | +deploy: |
| 135 | + provider: biicode |
| 136 | + user: developer |
| 137 | + password: #password |
| 138 | + secure: encrypted password here |
| 139 | + on: |
| 140 | + repo: developer/cppmath #GitHub repo |
| 141 | +{% endhighlight %} |
| 142 | + |
| 143 | +Script part creates, builds and runs the project and if it's a success Travis CI executes deploy publishing the `developer/cppmath` block. |
| 144 | + |
| 145 | +>**Tip** |
| 146 | +>biicode generates an executable `user_blockname_sourcefilename` for each source file with a `main()` function. In the example it would be `developer_cppmath_tests`. |
0 commit comments