Defining CodeBuild runtime in buildspec.yml
Recently AWS removed a variety of runtime images for their CodeBuild configuration.
Until that moment you could choose OS, Runtime and then an image you’d like to use for your build process. You could choose from ones prepared for nodejs, python, java, etc.
Right now for new builds you can only choose from
The question is - how do you specify that you want e.g. nodejs configuration for your build?
It’s pretty easy - you define it directly in your
buildspec.yml like this:
version: 0.2 phases: install: runtime-versions: nodejs: 10 python: 3.7 commands: - npm install -g firstname.lastname@example.org (...)
version: 0.2 in the header. In the
runtime-versions you enlist all runtime environments you require for your build. A list of all possible values can be find on this page.
I must say that I really like specifying runtime directly in the
buildspec.yml as it’s as close to the build process as possible – you have all the information in one place.
Not to mention that with previous approach if you wanted to create a build configuration that is using nodejs image but at the same time you wanted to have a python 3.6 installed you needed to do some additional steps that included downloading “raw” python by
wget and installing it manually (take a look at this thread).
Now - it’s just a matter of mentioning it in the
runtime-versions and it works pretty nice:
[Container] 2019/05/25 00:07:20 Entering phase INSTALL [Container] 2019/05/25 00:07:20 Running command echo "Installing Node.js version 10 ..." Installing Node.js version 10 ... [Container] 2019/05/25 00:07:20 Running command n 10.15.3 [Container] 2019/05/25 00:07:21 Running command echo "Installing Python version 3.7 ..." Installing Python version 3.7 ... [Container] 2019/05/25 00:07:21 Running command npm install -g email@example.com
At the beginning I thought it will be more time-consuming to install the dependencies in comparison to directly using CodeBuild prepared image. However, as you can see from the logs – it doesn’t make any meaningful impact on the time of build at all.
I find the approach with defining runtime environments from
buildspec.yml much easier and would recommend for you to give it a spin!