quentincaffeino / svc-base-docker

Base repo for docker based services with multi-env make

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Base repo for docker based services with make

This setup makes use of docker-compose ability to combine multiple configurations by reading several input files via defining multiple -f attributes and also combines it with environment-based make to make use easier with multi-environment setups with dynamic variables and env-based docker-compose configs

Table of contents

Variables

  • PROJECT_NAME - Project name
  • DOCKER_COMPOSE_FILES - Instructs make which docker-compose files use for which environment

Prerequisites

  • sh
  • make
  • perl
  • docker
  • docker compose (or docker-compose, supports both)

Usage

Every docker-compose comand is wrapped with make. Example usage:

[VARIABLES] make docker-[COMMAND-NAME] [VARIABLES]
# Eg.:
make docker-up
ENV=prod make docker-config
make docker-build s="service-name"

Where COMMAND-NAME is a docker-compose command name (eg.: up, down, config, ...)

Compose options

There are times when you need to pass extra variables to docker-compose command. Most of them accept some sort of options flags/attributes. Those could be passed using go (global options for docker-compose) or o (options for docker-compose command) variable like so:

make docker-up go=--verbose o="-d"
Note: Quotes are only nessesary when there are multiple space-separated flags/attrs to pass to the command.

Some commands also accept service(s) which to run command against (eg.: build to build only specific services). To pass those use s option:

make docker-build s="service-name service2-name"

Extra commands

Some commands with options are very commonly used and because to write them each time is very inconvenient shortcuts were added:

make docker-upd
# is same as
make docker-up o="--detach" # Detached mode: Run containers in the background.

# AND

make docker-rmf
# is same as
make docker-rm o="--force" # Don't ask to confirm removal

# AND

make docker-logsf
# is same as
make docker-logs o="--follow" # View and follow output from containers

Base repo for services with make [extends svc-base-make]

Make setup which makes use of per-environment dotenv files

Prerequisites [extends svc-base-make]

  • sh
  • make
  • perl

Usage [extends svc-base-make]

make help

dotenv [extends svc-base-make]

Using make and per-environment dotenv files it is prepaired to run on several environments.

Overrides [extends svc-base-make]

To override variables locally create .env.local or .env.ENVIRONMENT-NAME.local (eg.: .env.prod.local) files.

About

Base repo for docker based services with multi-env make

License:MIT License


Languages

Language:Makefile 97.2%Language:Shell 2.8%