NOTE: This is not a ready-to-use project, it's more like an executable cocktail napkin that I'm using to sketch out ideas for building, testing, and delivering infrastructure projects.
This project builds a docker image that you can use with the dojo tool to have a consistent local development environment for working with infrastructure code, with useful tools preinstalled. It is the base image for spin-tools, which adds some scripts that help to manage infrastructure projects.
Tested and released images are published to dockerhub as kiefm/spin-dojo-image.
In addition to basic useful utilities, the image includes terraform, inspec (rspec-based testing framework), bats (shell script-based testing framework), the aws CLI (note, this is an old version because of compatibility issues with Alpine linux not having glibc).
Create a Dojofile:
DOJO_DOCKER_IMAGE="kiefm/spin-dojo-image:latest"
By default, the current directory in the docker instance is /dojo/work.
Prerequisites:
- Docker (I use colima to install it on my Mac)
- Dojo (I install it on my Mac with homebrew)
Usage:
Change into the project folder. Make sure it has a Dojofile. Then run 'dojo' to download and start the image. You should end up on a prompt, where you can run commands.
Set up docker hub so the image can be built and published.
Set environment variable: DOCKERHUB_TOKEN
(I like to do this in a .direnv file)
Install bats for running tests (I use homebrew for bats-core)
- Build locally:
./tasks build_local - Run tests:
./tasks itest - Repeat above steps until ready
- Push changes to build and publish a new "latest"
- Edit the CHANGELOG and increment the version number in the first line to trigger a new release
Check out the image/Dockerfile to understand what's in the image. A summary:
- base image is alpine Linux, to make this image as small as possible
- terraform binary on the PATH
jqto parse JSON from bash scriptsdotto generate infrastructure graphs from terraform- a minimal ssh and git setup - to clone terraform modules
Those files are used inside the docker image:
~/.ssh/-- is copied from host to dojo's home~/.ssh~/.ssh/config-- will be generated on docker container start. SSH client is configured to ignore known ssh hosts.~/.aws/-- is copied from host to dojo's home~/.aws~/.gitconfig-- if exists locally, will be copied~/.profile-- will be generated on docker container start, in order to ensure current directory is/dojo/work.- For openstack access - environment variables must be locally set:
[ 'OS_AUTH_URL', 'OS_TENANT_NAME', 'OS_USERNAME', 'OS_PASSWORD']. Dojo will pass them to the docker image. - For AWS access
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYmust be set.
To enable debug output:
OS_DEBUG=1 TF_LOG=debug
Full spec is ops-base
Based on docker-terraform-dojo from Ewa Czechowska, Tomasz Sętkowski