|
| 1 | +-include .env |
| 2 | + |
| 3 | +# BuildKit enables higher performance docker builds and caching possibility |
| 4 | +# to decrease build times and increase productivity for free. |
| 5 | +# https://docs.docker.com/compose/environment-variables/envvars/ |
| 6 | +export DOCKER_BUILDKIT ?= 1 |
| 7 | + |
| 8 | +export CAROOT = $(shell mkcert -CAROOT) |
| 9 | + |
| 10 | +ifeq ($(COMPOSE_PROJECT_NAME),) |
| 11 | + COMPOSE_PROJECT_NAME=ss |
| 12 | +endif |
| 13 | + |
| 14 | +# Docker binary to use, when executing docker tasks |
| 15 | +DOCKER ?= docker |
| 16 | + |
| 17 | +# Binary to use, when executing docker-compose tasks |
| 18 | +DOCKER_COMPOSE ?= $(DOCKER) compose |
| 19 | + |
| 20 | +# Support image with all needed binaries, like envsubst, mkcert, wait4x |
| 21 | +SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest |
| 22 | + |
| 23 | +BUILDER_PARAMS ?= $(DOCKER) run --rm -i \ |
| 24 | + --env-file ./.env \ |
| 25 | + --env COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \ |
| 26 | + --env SHARED_DOMAIN_SEGMENT="$(SHARED_DOMAIN_SEGMENT)" |
| 27 | + |
| 28 | +BUILDER ?= $(BUILDER_PARAMS) $(SUPPORT_IMAGE) |
| 29 | +BUILDER_WIRED ?= $(BUILDER_PARAMS) --network network.$(COMPOSE_PROJECT_NAME) $(SUPPORT_IMAGE) |
| 30 | + |
| 31 | +# Shorthand envsubst command, executed through build-deps |
| 32 | +ENVSUBST ?= $(BUILDER) envsubst |
| 33 | + |
| 34 | +# Yamllint docker image |
| 35 | +YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \ |
| 36 | + -v $(PWD):/data \ |
| 37 | + cytopia/yamllint:latest \ |
| 38 | + -c ./.github/.yamllint.yaml \ |
| 39 | + -f colored . |
| 40 | + |
| 41 | +ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \ |
| 42 | + -v $(shell pwd):/repo \ |
| 43 | + --workdir /repo \ |
| 44 | + rhysd/actionlint:latest \ |
| 45 | + -color |
| 46 | + |
| 47 | +MARKDOWN_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \ |
| 48 | + -v $(shell pwd):/app \ |
| 49 | + --workdir /app \ |
| 50 | + davidanson/markdownlint-cli2-rules:latest \ |
| 51 | + --config ".github/.markdownlint.json" |
| 52 | + |
| 53 | +EXPORT_VARS = '\ |
| 54 | + $${SHARED_DOMAIN_SEGMENT} \ |
| 55 | + $${COMPOSE_PROJECT_NAME}' |
| 56 | + |
| 57 | +# |
| 58 | +# Self documenting Makefile code |
| 59 | +# ------------------------------------------------------------------------------------ |
| 60 | +ifneq ($(TERM),) |
| 61 | + BLACK := $(shell tput setaf 0) |
| 62 | + RED := $(shell tput setaf 1) |
| 63 | + GREEN := $(shell tput setaf 2) |
| 64 | + YELLOW := $(shell tput setaf 3) |
| 65 | + LIGHTPURPLE := $(shell tput setaf 4) |
| 66 | + PURPLE := $(shell tput setaf 5) |
| 67 | + BLUE := $(shell tput setaf 6) |
| 68 | + WHITE := $(shell tput setaf 7) |
| 69 | + RST := $(shell tput sgr0) |
| 70 | +else |
| 71 | + BLACK := "" |
| 72 | + RED := "" |
| 73 | + GREEN := "" |
| 74 | + YELLOW := "" |
| 75 | + LIGHTPURPLE := "" |
| 76 | + PURPLE := "" |
| 77 | + BLUE := "" |
| 78 | + WHITE := "" |
| 79 | + RST := "" |
| 80 | +endif |
| 81 | +MAKE_LOGFILE = /tmp/wayofdev-docker-shared-services.log |
| 82 | +MAKE_CMD_COLOR := $(BLUE) |
| 83 | + |
| 84 | +default: all |
| 85 | + |
| 86 | +help: |
| 87 | + @echo 'Management commands for project:' |
| 88 | + @echo 'Usage:' |
| 89 | + @echo ' ${MAKE_CMD_COLOR}make${RST} Creates containers, spins up project' |
| 90 | + @grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}' |
| 91 | + @echo |
| 92 | + @echo ' 📑 Logs are stored in $(MAKE_LOGFILE)' |
| 93 | + @echo |
| 94 | + @echo ' 📦 Package docker-shared-services (https://github.com/wayofdev/docker-shared-services)' |
| 95 | + @echo ' 🤠 Author Andrij Orlenko (https://github.com/lotyp)' |
| 96 | + @echo ' 🏢 ${YELLOW}Org wayofdev (https://github.com/wayofdev)${RST}' |
| 97 | + @echo |
| 98 | +.PHONY: help |
| 99 | + |
| 100 | +.EXPORT_ALL_VARIABLES: |
| 101 | + |
| 102 | +# |
| 103 | +# Default action |
| 104 | +# Defines default command when `make` is executed without additional parameters |
| 105 | +# ------------------------------------------------------------------------------------ |
| 106 | +all: hooks env up |
| 107 | +PHONY: all |
| 108 | + |
| 109 | +# |
| 110 | +# System Actions |
| 111 | +# ------------------------------------------------------------------------------------ |
| 112 | +env: ## Generate .env file from example, use `make env force=true`, to force re-create file |
| 113 | +ifeq ($(FORCE),true) |
| 114 | + @echo "${YELLOW}Force re-creating .env file from example...${RST}" |
| 115 | + @# $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env |
| 116 | + cp ./.env.example ./.env |
| 117 | +else ifneq ("$(wildcard ./.env)","") |
| 118 | + @echo "" |
| 119 | + @echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}" |
| 120 | +else |
| 121 | + @echo "Creating .env file from example" |
| 122 | + @# $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env |
| 123 | + cp ./.env.example ./.env |
| 124 | +endif |
| 125 | +.PHONY: env |
| 126 | + |
| 127 | +override-create: ## Generate override file from dist |
| 128 | + cp -v docker-compose.override.yaml.dist docker-compose.override.yaml |
| 129 | +.PHONY: override-create |
| 130 | + |
| 131 | +cert-install: ## Run mkcert to install CA into system storage and generate default certs for traefik |
| 132 | + bash mkcert.sh |
| 133 | +.PHONY: cert-install |
| 134 | + |
| 135 | +# |
| 136 | +# Docker Actions |
| 137 | +# ------------------------------------------------------------------------------------ |
| 138 | +up: ## Fire up project |
| 139 | + $(DOCKER_COMPOSE) up --remove-orphans -d --wait |
| 140 | +.PHONY: up |
| 141 | + |
| 142 | +up-router: ## Start only traefik service |
| 143 | + $(DOCKER_COMPOSE) up --remove-orphans -d --no-deps router --wait |
| 144 | +.PHONY: up-router |
| 145 | + |
| 146 | +up-dns: ## Start only dns service |
| 147 | + $(DOCKER_COMPOSE) up --remove-orphans -d --no-deps dns --wait |
| 148 | +.PHONY: up-dns |
| 149 | + |
| 150 | +down: ## Stops and destroys running containers |
| 151 | + $(DOCKER_COMPOSE) down --remove-orphans |
| 152 | +.PHONY: down |
| 153 | + |
| 154 | +stop: ## Stops all containers, without removing them |
| 155 | + $(DOCKER_COMPOSE) stop |
| 156 | +.PHONY: stop |
| 157 | + |
| 158 | +restart: down up ## Restart all containers, running in this project |
| 159 | +.PHONY: restart |
| 160 | + |
| 161 | +logs: ## Show logs for running containers in this project |
| 162 | + $(DOCKER_COMPOSE) logs -f |
| 163 | +.PHONY: logs |
| 164 | + |
| 165 | +ps: ## List running containers in this project |
| 166 | + $(DOCKER_COMPOSE) ps |
| 167 | +.PHONY: ps |
| 168 | + |
| 169 | +pull: ## Pull upstream images, specified in docker-compose.yml file |
| 170 | + $(DOCKER_COMPOSE) pull |
| 171 | +.PHONY: pull |
| 172 | + |
| 173 | +clean: |
| 174 | + $(DOCKER_COMPOSE) rm --force --stop |
| 175 | +.PHONY: clean |
| 176 | + |
| 177 | +prune: ## Stops and removes all containers and volumes |
| 178 | + $(DOCKER_COMPOSE) down --remove-orphans --volumes |
| 179 | +.PHONY: prune |
| 180 | + |
| 181 | +# |
| 182 | +# Code Quality, Git, Linting |
| 183 | +# ------------------------------------------------------------------------------------ |
| 184 | +hooks: ## Install git hooks from pre-commit-config |
| 185 | + pre-commit install |
| 186 | + pre-commit install --hook-type commit-msg |
| 187 | + pre-commit autoupdate |
| 188 | +.PHONY: hooks |
| 189 | + |
| 190 | +lint: lint-yaml lint-actions lint-md ## Lint all files in project |
| 191 | +.PHONY: lint |
| 192 | + |
| 193 | +lint-yaml: ## Lints yaml files inside project |
| 194 | + @$(YAML_LINT_RUNNER) | tee -a $(MAKE_LOGFILE) |
| 195 | +.PHONY: lint-yaml |
| 196 | + |
| 197 | +lint-actions: ## Lint all github actions |
| 198 | + @$(ACTION_LINT_RUNNER) | tee -a $(MAKE_LOGFILE) |
| 199 | +.PHONY: lint-actions |
| 200 | + |
| 201 | +lint-md: ## Lint all markdown files using markdownlint-cli2 |
| 202 | + @$(MARKDOWN_LINT_RUNNER) --fix "**/*.md" "!CHANGELOG.md" | tee -a $(MAKE_LOGFILE) |
| 203 | +.PHONY: lint-md |
| 204 | + |
| 205 | +lint-md-dry: ## Lint all markdown files using markdownlint-cli2 in dry-run mode |
| 206 | + @$(MARKDOWN_LINT_RUNNER) "**/*.md" "!CHANGELOG.md" | tee -a $(MAKE_LOGFILE) |
| 207 | +.PHONY: lint-md-dry |
| 208 | + |
| 209 | +# |
| 210 | +# Testing |
| 211 | +# ------------------------------------------------------------------------------------ |
| 212 | +# dcgoss binary is used for testing |
| 213 | +# README: https://github.com/aelsabbahy/goss/tree/master/extras/dcgoss |
| 214 | +# macOS install: https://github.com/goss-org/goss/tree/master/extras/dgoss#mac-osx |
| 215 | +# |
| 216 | +test: ## Run self-tests using dcgoss |
| 217 | + dcgoss run router |
| 218 | +.PHONY: test |
| 219 | + |
| 220 | +# |
| 221 | +# Release |
| 222 | +# ------------------------------------------------------------------------------------ |
| 223 | +commit: ## Run commitizen to create commit message |
| 224 | + czg commit --config="./.github/.cz.config.js" |
| 225 | +.PHONY: commit |
0 commit comments