DEV Community

Cover image for Containerized Cookiecutter
Clemens Kaserer
Clemens Kaserer

Posted on

Containerized Cookiecutter

What is cookiecutter?!

A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python package project template.


Cookiecutter as a Container

Wonderful, now let's use cookiecutter from a container instead of installing it on your machine.

Base image

The image is based on python:3 and can be build for any architecture supported by python:3.

Flavors

The cookiecutter container image is available in 2 flavors

  • latest is build daily via travis and if the base images changes
  • version during each travis build the current cookiecutter version is validated and the image is tagged accordingly starting with 1.7.0. More versions can be found on hub.docker.com/r/ckaserer/cookiecutter.

Requirements

  • Bash
  • docker

Getting started

To process any cookiecutter template you can execute

docker run --rm -it -v $(pwd):/cookiecutter ckaserer/cookiecutter TEMPLATE

Or if you like the a more convinient approach you can put following lines in your bashrc

# cookiecutter
function cookiecutter () {
  local command="docker run --rm -it -v $(pwd):/cookiecutter ckaserer/cookiecutter"
  echo "+ ${command} $@" && ${command} $@
}
readonly -f cookiecutter
[ "$?" -eq "0" ] || return $?

and after sourcing your bashrc again to load the newly added function into our shell via

source ~/.bashrc

you can process your template just like you would when installing cookiecutter on your machine via

cookiecutter TEMPLATE

Source

Top comments (0)