Running AWS Code build locally
I’ve been working with code build for some time now, have even had to configure our own images for some Windows builds. Recently I helped my friend Zain setup a pipeline, while learning the ins and out of codebuild ( using scp in codebuild to be specfic ) we performed 100’s of test builds. While the sercice itself is quite cheap free is a good option to cheap. When asked how can I cut the costs I suggested running codebuild locally which I had not done myself until now.
There is a great article on AWS Code Build Locally
but I thought I’d repeat the process and provide a very simple app to demonstrate the process as well as using actual aws credentials to perform typical tasks such as syncing to s3 or accessing parameter store.
There are some pre-requisist:
- aws command line installed
- aws access key and secret ( if you need to access a native service not just compile and app )
- 10 gig hdd space ( yes the codebuild image is huge )
- about 30 mins to buidl the container
The Steps at a high level are:
- Clone the codebuild docker image repo
- Build the docker image
- Pull the codebuild agent container
- Download the aws helper script and your good to go.
For those beginning what is the codebuild doing, well it’s a build envrioment. If you look in the docker file you’ll see it’s literally installing all the dependencies you might need ( ok not all of them but lots of common ones ).
You pass your repo to the build environment along with the instructions in the buildspec.yaml and the code build agent will interpret the commands running your build steps.
My current workign directory ( pwd )
I place codebuild.sh in my path so I can call it anywhere
Use -i to specify the build envioment image
Use -a to specify the output directory. for me /tmp works fine I don’t need to keep the artifact
Use -c to specify the aws credentials file
You can see how the shell scripts helps as it puts together this:
See a run below