First, we need to setup our workstation to have a docker image that we can use to mimic codebuild in the wild. For this I’ve setup nodejs, but you can browse the binaries and freely use whichever you want.
Below is a simple list of commands to get setup.
Note to self: scripting this may be useful in the future
# Local Codebuild
Reference: [https://aws.amazon.com/blogs/devops/announcing-local-build-support-for-aws-codebuild/](https://aws.amazon.com/blogs/devops/announcing-local-build-support-for-aws-codebuild/)
### Locally pull available codebuild images
git clone https://github.com/aws/aws-codebuild-docker-images.git
### Browse for the binary you're looking for
cd aws-codebuild-docker-images
cd ubuntu/{BINARY}
docker build -t aws/codebuild/{BINARY}:{VERSION} .
### Pull codebuild locally
docker pull amazon/aws-codebuild-local:latest --disable-content-trust=false
### Install the codebuild script to do local magic
wget https://raw.githubusercontent.com/aws/aws-codebuild-docker-images/master/local_builds/codebuild_build.sh
chmod +x codebuild_build.sh
### Optionally..
mv codebuild_build.sh /usr/local/bin/codebuild
## Usage
codebuild_build.sh [-i image_name] [-a artifact_output_directory] [options]
### Example Usage
codebuild -i aws/codebuild/{BINARY}:{VERSION} -a /path/to/artifacts -s /path/to/src
Once installed, the usage is actually brilliantly simple:
codebuild -i aws/codebuild/nodejs:10.14.1 -a /path/to/artifact -s /path/to/src -b /path/to/buildspec.yml
- Your path to artifact is where you want the artifact to be “downloaded” to.
- Your buildspec can be named anything as long as it follows the conventions; I typically have
buildspec.yml
for production, andbuildspec-{env}
for others, because unfortunately codebuild does not support native environment variables for this yet (if it does and I’m missing it, please point me in the right direction!)