Skip to content

Commit

Permalink
copy setup from docker-shared-services
Browse files Browse the repository at this point in the history
  • Loading branch information
elf-pavlik committed Sep 7, 2024
1 parent 796f6c1 commit ecb06ed
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 46 deletions.
79 changes: 79 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# SS = Shared Services
# https://docs.docker.com/compose/reference/envvars/#compose_project_name
#
COMPOSE_PROJECT_NAME=sai

#
# Domain, under which default, shared services will run.
# Default: .wod
# Example subdomains, under which services will run under:
# - pg-admin.wod.docker
# - router.wod.docker
# - ui.wod.docker
# Can be left blank, but then $TLS_DOMAINS need to contain all top level domains of your projects.
#
# Example:
# Using empty SHARED_DOMAIN_SEGMENT=""
# TLS_DOMAINS="pg-admin.docker router.docker ui.docker"
# Using custom SHARED_DOMAIN_SEGMENT=".wod"
# TLS_DOMAINS="pg-admin.wod.docker router.wod.docker ui.wod.docker"
#
SHARED_DOMAIN_SEGMENT=

#
# Specify domains for mkcert
# Because of browser limitations, each top-level domain should be added separately.
# This ensures that certificates are correctly recognized by browsers.
# Examples of top-level domains:
# - pg-admin.docker
# - router.docker
# - ui.docker
#
# Wildcards can be used, but note that they only cover one level of subdomains.
# Example:
# - *.laravel-starter-tpl.docker will match api.laravel-starter-tpl.docker
# - However, it will not match api.prod.laravel-starter-tpl.docker
#
TLS_DOMAINS="router.docker pod.docker *.pod.docker sai.docker ui.sai.docker vuejectron.docker plenary.docker"

#
# DNSMasq Configuration
#
# This service will route all *.docker domains to the local macOS or Linux machine.
# Example: your-project.docker will be routed to the local machine 127.0.0.1
#
# `ping your-project.docker` will return
#
# PING your-project.docker (127.0.0.1): 56 data bytes
# 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.129 ms
# 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.173 ms
# 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.111 ms
# 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.176 ms
#
# This allows further configuration of Traefik to route the traffic to the correct container.
#
# For more information, see:
# https://github.com/DrPsychick/docker-dnsmasq
#
# Note: To use, for example .mac domain, you need to change
# DMQ_GLOBAL=address=/docker/127.0.0.1 (to =>) DMQ_GLOBAL=address=/mac/127.0.0.1
#
DMQ_DHCP_DNS=dhcp-option=6,172.17.10.1,8.8.8.8,8.8.4.4
DMQ_DHCP_GATEWAY=dhcp-option=3,172.17.10.1
DMQ_DHCP_PXE=
DMQ_DHCP_RANGES=dhcp-range=172.17.10.10,172.17.10.100,24h
DMQ_DHCP_TFTP=
DMQ_DHCP_WINS=
DMQ_DNS_ADDRESS=
DMQ_DNS_ALIAS=
DMQ_DNS_CNAME=
DMQ_DNS_DOMAIN=domain=local
DMQ_DNS_FLAGS=expand-hosts\ndomain-needed\nselfmx\ndns-loop-detect
DMQ_DNS_LOCAL=local=/local/
DMQ_DNS_RESOLV=no-resolv
DMQ_DNS_SERVER=server=8.8.8.8\nserver=8.8.4.4
DMQ_DNS_SRV=
DMQ_DNS_TXT=
#DMQ_GLOBAL=address=/docker/127.0.0.1
DMQ_GLOBAL=address=/docker/172.100.61.250
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ packages/css-storage-fixture/**/.internal/accounts/index/clientCredentials

# ldo
examples/*/ldo/

traefik/certs/*
225 changes: 225 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
-include .env

# BuildKit enables higher performance docker builds and caching possibility
# to decrease build times and increase productivity for free.
# https://docs.docker.com/compose/environment-variables/envvars/
export DOCKER_BUILDKIT ?= 1

export CAROOT = $(shell mkcert -CAROOT)

ifeq ($(COMPOSE_PROJECT_NAME),)
COMPOSE_PROJECT_NAME=ss
endif

# Docker binary to use, when executing docker tasks
DOCKER ?= docker

# Binary to use, when executing docker-compose tasks
DOCKER_COMPOSE ?= $(DOCKER) compose

# Support image with all needed binaries, like envsubst, mkcert, wait4x
SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest

BUILDER_PARAMS ?= $(DOCKER) run --rm -i \
--env-file ./.env \
--env COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
--env SHARED_DOMAIN_SEGMENT="$(SHARED_DOMAIN_SEGMENT)"

BUILDER ?= $(BUILDER_PARAMS) $(SUPPORT_IMAGE)
BUILDER_WIRED ?= $(BUILDER_PARAMS) --network network.$(COMPOSE_PROJECT_NAME) $(SUPPORT_IMAGE)

# Shorthand envsubst command, executed through build-deps
ENVSUBST ?= $(BUILDER) envsubst

# Yamllint docker image
YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(PWD):/data \
cytopia/yamllint:latest \
-c ./.github/.yamllint.yaml \
-f colored .

ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/repo \
--workdir /repo \
rhysd/actionlint:latest \
-color

MARKDOWN_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/app \
--workdir /app \
davidanson/markdownlint-cli2-rules:latest \
--config ".github/.markdownlint.json"

EXPORT_VARS = '\
$${SHARED_DOMAIN_SEGMENT} \
$${COMPOSE_PROJECT_NAME}'

#
# Self documenting Makefile code
# ------------------------------------------------------------------------------------
ifneq ($(TERM),)
BLACK := $(shell tput setaf 0)
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
LIGHTPURPLE := $(shell tput setaf 4)
PURPLE := $(shell tput setaf 5)
BLUE := $(shell tput setaf 6)
WHITE := $(shell tput setaf 7)
RST := $(shell tput sgr0)
else
BLACK := ""
RED := ""
GREEN := ""
YELLOW := ""
LIGHTPURPLE := ""
PURPLE := ""
BLUE := ""
WHITE := ""
RST := ""
endif
MAKE_LOGFILE = /tmp/wayofdev-docker-shared-services.log
MAKE_CMD_COLOR := $(BLUE)

default: all

help:
@echo 'Management commands for project:'
@echo 'Usage:'
@echo ' ${MAKE_CMD_COLOR}make${RST} Creates containers, spins up project'
@grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}'
@echo
@echo ' 📑 Logs are stored in $(MAKE_LOGFILE)'
@echo
@echo ' 📦 Package docker-shared-services (https://github.com/wayofdev/docker-shared-services)'
@echo ' 🤠 Author Andrij Orlenko (https://github.com/lotyp)'
@echo ' 🏢 ${YELLOW}Org wayofdev (https://github.com/wayofdev)${RST}'
@echo
.PHONY: help

.EXPORT_ALL_VARIABLES:

#
# Default action
# Defines default command when `make` is executed without additional parameters
# ------------------------------------------------------------------------------------
all: hooks env up
PHONY: all

#
# System Actions
# ------------------------------------------------------------------------------------
env: ## Generate .env file from example, use `make env force=true`, to force re-create file
ifeq ($(FORCE),true)
@echo "${YELLOW}Force re-creating .env file from example...${RST}"
@# $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
cp ./.env.example ./.env
else ifneq ("$(wildcard ./.env)","")
@echo ""
@echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}"
else
@echo "Creating .env file from example"
@# $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
cp ./.env.example ./.env
endif
.PHONY: env

override-create: ## Generate override file from dist
cp -v docker-compose.override.yaml.dist docker-compose.override.yaml
.PHONY: override-create

cert-install: ## Run mkcert to install CA into system storage and generate default certs for traefik
bash mkcert.sh
.PHONY: cert-install

#
# Docker Actions
# ------------------------------------------------------------------------------------
up: ## Fire up project
$(DOCKER_COMPOSE) up --remove-orphans -d --wait
.PHONY: up

up-router: ## Start only traefik service
$(DOCKER_COMPOSE) up --remove-orphans -d --no-deps router --wait
.PHONY: up-router

up-dns: ## Start only dns service
$(DOCKER_COMPOSE) up --remove-orphans -d --no-deps dns --wait
.PHONY: up-dns

down: ## Stops and destroys running containers
$(DOCKER_COMPOSE) down --remove-orphans
.PHONY: down

stop: ## Stops all containers, without removing them
$(DOCKER_COMPOSE) stop
.PHONY: stop

restart: down up ## Restart all containers, running in this project
.PHONY: restart

logs: ## Show logs for running containers in this project
$(DOCKER_COMPOSE) logs -f
.PHONY: logs

ps: ## List running containers in this project
$(DOCKER_COMPOSE) ps
.PHONY: ps

pull: ## Pull upstream images, specified in docker-compose.yml file
$(DOCKER_COMPOSE) pull
.PHONY: pull

clean:
$(DOCKER_COMPOSE) rm --force --stop
.PHONY: clean

prune: ## Stops and removes all containers and volumes
$(DOCKER_COMPOSE) down --remove-orphans --volumes
.PHONY: prune

#
# Code Quality, Git, Linting
# ------------------------------------------------------------------------------------
hooks: ## Install git hooks from pre-commit-config
pre-commit install
pre-commit install --hook-type commit-msg
pre-commit autoupdate
.PHONY: hooks

lint: lint-yaml lint-actions lint-md ## Lint all files in project
.PHONY: lint

lint-yaml: ## Lints yaml files inside project
@$(YAML_LINT_RUNNER) | tee -a $(MAKE_LOGFILE)
.PHONY: lint-yaml

lint-actions: ## Lint all github actions
@$(ACTION_LINT_RUNNER) | tee -a $(MAKE_LOGFILE)
.PHONY: lint-actions

lint-md: ## Lint all markdown files using markdownlint-cli2
@$(MARKDOWN_LINT_RUNNER) --fix "**/*.md" "!CHANGELOG.md" | tee -a $(MAKE_LOGFILE)
.PHONY: lint-md

lint-md-dry: ## Lint all markdown files using markdownlint-cli2 in dry-run mode
@$(MARKDOWN_LINT_RUNNER) "**/*.md" "!CHANGELOG.md" | tee -a $(MAKE_LOGFILE)
.PHONY: lint-md-dry

#
# Testing
# ------------------------------------------------------------------------------------
# dcgoss binary is used for testing
# README: https://github.com/aelsabbahy/goss/tree/master/extras/dcgoss
# macOS install: https://github.com/goss-org/goss/tree/master/extras/dgoss#mac-osx
#
test: ## Run self-tests using dcgoss
dcgoss run router
.PHONY: test

#
# Release
# ------------------------------------------------------------------------------------
commit: ## Run commitizen to create commit message
czg commit --config="./.github/.cz.config.js"
.PHONY: commit
Loading

0 comments on commit ecb06ed

Please sign in to comment.