Skip to content

Commit ecb06ed

Browse files
committed
copy setup from docker-shared-services
https://github.com/wayofdev/docker-shared-services
1 parent 796f6c1 commit ecb06ed

File tree

11 files changed

+505
-46
lines changed

11 files changed

+505
-46
lines changed

.env

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# SS = Shared Services
3+
# https://docs.docker.com/compose/reference/envvars/#compose_project_name
4+
#
5+
COMPOSE_PROJECT_NAME=sai
6+
7+
#
8+
# Domain, under which default, shared services will run.
9+
# Default: .wod
10+
# Example subdomains, under which services will run under:
11+
# - pg-admin.wod.docker
12+
# - router.wod.docker
13+
# - ui.wod.docker
14+
# Can be left blank, but then $TLS_DOMAINS need to contain all top level domains of your projects.
15+
#
16+
# Example:
17+
# Using empty SHARED_DOMAIN_SEGMENT=""
18+
# TLS_DOMAINS="pg-admin.docker router.docker ui.docker"
19+
# Using custom SHARED_DOMAIN_SEGMENT=".wod"
20+
# TLS_DOMAINS="pg-admin.wod.docker router.wod.docker ui.wod.docker"
21+
#
22+
SHARED_DOMAIN_SEGMENT=
23+
24+
#
25+
# Specify domains for mkcert
26+
# Because of browser limitations, each top-level domain should be added separately.
27+
# This ensures that certificates are correctly recognized by browsers.
28+
# Examples of top-level domains:
29+
# - pg-admin.docker
30+
# - router.docker
31+
# - ui.docker
32+
#
33+
# Wildcards can be used, but note that they only cover one level of subdomains.
34+
# Example:
35+
# - *.laravel-starter-tpl.docker will match api.laravel-starter-tpl.docker
36+
# - However, it will not match api.prod.laravel-starter-tpl.docker
37+
#
38+
TLS_DOMAINS="router.docker pod.docker *.pod.docker sai.docker ui.sai.docker vuejectron.docker plenary.docker"
39+
40+
#
41+
# DNSMasq Configuration
42+
#
43+
# This service will route all *.docker domains to the local macOS or Linux machine.
44+
# Example: your-project.docker will be routed to the local machine 127.0.0.1
45+
#
46+
# `ping your-project.docker` will return
47+
#
48+
# PING your-project.docker (127.0.0.1): 56 data bytes
49+
# 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.129 ms
50+
# 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.173 ms
51+
# 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.111 ms
52+
# 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.176 ms
53+
#
54+
# This allows further configuration of Traefik to route the traffic to the correct container.
55+
#
56+
# For more information, see:
57+
# https://github.com/DrPsychick/docker-dnsmasq
58+
#
59+
# Note: To use, for example .mac domain, you need to change
60+
# DMQ_GLOBAL=address=/docker/127.0.0.1 (to =>) DMQ_GLOBAL=address=/mac/127.0.0.1
61+
#
62+
DMQ_DHCP_DNS=dhcp-option=6,172.17.10.1,8.8.8.8,8.8.4.4
63+
DMQ_DHCP_GATEWAY=dhcp-option=3,172.17.10.1
64+
DMQ_DHCP_PXE=
65+
DMQ_DHCP_RANGES=dhcp-range=172.17.10.10,172.17.10.100,24h
66+
DMQ_DHCP_TFTP=
67+
DMQ_DHCP_WINS=
68+
DMQ_DNS_ADDRESS=
69+
DMQ_DNS_ALIAS=
70+
DMQ_DNS_CNAME=
71+
DMQ_DNS_DOMAIN=domain=local
72+
DMQ_DNS_FLAGS=expand-hosts\ndomain-needed\nselfmx\ndns-loop-detect
73+
DMQ_DNS_LOCAL=local=/local/
74+
DMQ_DNS_RESOLV=no-resolv
75+
DMQ_DNS_SERVER=server=8.8.8.8\nserver=8.8.4.4
76+
DMQ_DNS_SRV=
77+
DMQ_DNS_TXT=
78+
#DMQ_GLOBAL=address=/docker/127.0.0.1
79+
DMQ_GLOBAL=address=/docker/172.100.61.250

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ packages/css-storage-fixture/**/.internal/accounts/index/clientCredentials
3939

4040
# ldo
4141
examples/*/ldo/
42+
43+
traefik/certs/*

Makefile

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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

Comments
 (0)