Skip to content

Make-scripts for building 'docker-compose.yml' on templates

Notifications You must be signed in to change notification settings

abitcipher/mkdcontmpl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build docker-compose.yml from templates

mkdcontmpl : MaKe Docker Compose ON TeMPLates.

Implements build docker-compose.yml and .env files from templates. The system operates with the concept of context and service.

Main commands (makefile targets)

Command Description
help Show this help; help.% — detail helps check help.about
initCtx Create new 'context' from .default: CTX=<context>
listCtx List all contexts
listSrv List all services in context
listSrvVersion List services with versions: SRV=<name>
addCtxSrv Add service to context: SRV=<name>
enableCtxSrv Enable service in context: SRV=<name>
disableCtxSrv Disable service in context: SRV=<name>
rmCtxSrv Remove service from context: SRV=<name>
buildCtx Build context: CTX=<context>

Example

  • Initialize context 'myctx' from template '.default'
$ make initCtx NEWCTX=myctx
  • Add service nginxto context myctx — that is, copy files from folder:

    • .template/docker-compose/template/*.tmpl > ./.context/myctx/.tmpl/

      and create directories:

    • .context/myctx/.tmpl/

    • .context/myctx/.yml/

    • .context/myctx/.environ/

  • Add service 'nginx' to context 'myctx'

    $ make addCtxSrv CTX=myctx SRV=nginx
  • Now you can edit files in directories to castomize configuration of the 'nginx' service:

    • .context/myctx/.environ/nginx.env
    • .context/myctx/.yml/nginx.service.env
    • .context/myctx/.yml/nginx.volume.env
  • Build context myctx — create files

    • .context/myctx/docker-compose.yml
    • .context/myctx/.env
$ make buildCtx CTX=myctx

Dependencies

The main utility on which the Jinja template engine depends is
MiniJinja

The scripts also use standard Unix utilities :

Command Description
minijinja-cli a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
sed stream editor for filtering and transforming text
cp copy files and directories
ln -s make links between files
mkdir make a directory
sort sort lines of text files
truncate shrink or extend the size of a file to the specified size
uniq report or omit repeated lines
awk using by keymap functions

Installation

MiniJinja is also available as an (optionally pre-compiled) command line executable called minijinja-cli

$ curl -sSfL https://github.com/mitsuhiko/minijinja/releases/latest/download/minijinja-cli-installer.sh | sh
$ echo "Hello {{ name }}" | minijinja-cli - -Dname=World
Hello World

Alternatively, if you have Rust and the Cargo package manager installed, you also can install the 'minijinja-cli' using the command

$ cargo install minijinja-cli

How it work

$ make help.about

Shortly, context — is a directory with a name set by the environment variable CTX, context-directory is located at the folder named .context. The .context/$(CTX)/ directory contains templates (Jinja/Jinja2) at the .context/$(CTX)/.tmpl folder for build docker-compose.yml. YML-files from the .context/$(CTX)/.yml/ directory describe the services available for this context, every file $(SRV).service.yml describe some service with name $(SRV) . Env-files from the directory .context/$(CTX)/.environ/ set environment variables for each service $(SRV).env. The command like:

$ make buildCtx CTX=test

created 'docker-compose.yml' & '.env' files at the ./.context/test folder.

About

Make-scripts for building 'docker-compose.yml' on templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published