How to Write Build Targets¶
The YourBase command-line utility is configured using YAML. It is broken into three sections: dependencies, build targets, and CI information. Dependencies describe which build packs to use, build targets describe what to build and how, and CI information is used to make a decision on when to build which targets based on some rules.
Dependencies in YourBase are modeled as build packs – these are programmatically defined dependencies that know how to download, install, and configure themselves.
Dependencies come in two types, build and runtime dependencies. Build dependencies are automatically used as part of the runtime dependency list, but runtime dependencies are not used when performing builds.
Available build packs¶
The Android NDK
The Android SDK
Apache’s ant JVM build tool
The Dart programming language
The flutter SDK
Gradle build tool
The Heroku CLI
The homebrew project, if your project needs binaries / C libraries
Maven build tool
Python, using pyenv and creating per-project virtualenvs
Ruby, installed using rbenv
The R programming language
In order to declare that your projects uses a build pack, it must be added to one of the dependency listings. For example, a simple Python project might have a dependencies section similar to the following:
1 2 3 4 5
dependencies: build: - python:3.6.3 runtime: - heroku:latest
The example above will define two dependencies, Python 3.6.3 and the latest version of the Heroku CLI. Once these dependencies are defined, subsequent invocations of the yb cli tool will leverage the buildpacks to perform the required installation and setup so that the tools are available. With this example YAML, you could now issue a command such as: yb run python -v and the buildpacks would install (as-needed) and make available to you the version of Python specified in the config.
Once dependencies have been specified we can move on to describing our build. This is done with one, or more, “build targets” each with their own name, environment variables, commands, etc. For example, consider that our simple Python application has a set of tests to run. This is a common scenario that many projects share; here we can define a build target with two commands: install our dependencies, and then run our tests.
1 2 3 4 5 6 7 8 9 10 11
dependencies: build: - python:3.6.3 runtime: - heroku:latest build_targets: - name: default commands: - pip install -r requirements.txt - python tests/run_tests.py
Now, we can use the build sub-command to perform our build – yb build.
CI information simply describes which build targets to execute under a set of conditions. Further enhancing our example, we can instruct the YourBase build system to run our tests every time a commit happens:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
dependencies: build: - python:3.6.3 runtime: - heroku:latest build_targets: - name: default commands: - pip install -r requirements.txt - python tests/run_tests.py ci: builds: - name: tests build_target: default
If we want to limit the times that the system performs these builds, we can gate the build on a set of conditions; for example, to build only when the source code is tagged we could add the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
dependencies: build: - python:3.6.3 runtime: - heroku:latest build_targets: - name: default commands: - pip install -r requirements.txt - python tests/run_tests.py ci: builds: - name: tests build_target: default when: tagged and branch matches 'refs/tags/alpha-*'
For more information on how to configure CI builds, see Getting Started with YourBase.