-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
184 lines (154 loc) · 5.63 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# 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 COMPOSE_DOCKER_CLI_BUILD ?= 1
# Docker binary to use, when executing docker tasks
DOCKER ?= docker
IMAGE_NAMESPACE ?= wayofdev/php-dev
IMAGE_TEMPLATE ?= 8.4-cli-alpine
IMAGE_TAG ?= $(IMAGE_NAMESPACE):$(IMAGE_TEMPLATE)-latest
DOCKERFILE_DIR ?= ./dist/dev/$(IMAGE_TEMPLATE)
CACHE_FROM ?= $(IMAGE_TAG)
OS ?= $(shell uname)
CURRENT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
YAML_CONFIG_PATH ?= .github/.yamllint.yaml
YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(PWD):/data \
cytopia/yamllint:latest \
-c $(YAML_CONFIG_PATH) \
-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"
ANSIBLE_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/code \
-e YAMLLINT_CONFIG_FILE=$(YAML_CONFIG_PATH) \
--workdir /code \
pipelinecomponents/ansible-lint:latest \
ansible-lint --show-relpath --config-file ".github/.ansible-lint.yml"
#
# 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-php-dev.log
MAKE_CMD_COLOR := $(BLUE)
default: all
help:
@echo 'Management commands for package:'
@echo 'Usage:'
@echo ' ${MAKE_CMD_COLOR}make${RST} Builds default image and then runs dgoss tests'
@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-php-dev (github.com/wayofdev/docker-php-dev)'
@echo ' 🤠 Author the dev (github.com/lotyp)'
@echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
@echo
.PHONY: help
.EXPORT_ALL_VARIABLES:
#
# Default action
# Defines default command when `make` is executed without additional parameters
# ------------------------------------------------------------------------------------
all: generate build test
PHONY: all
#
# Docker Actions
# ------------------------------------------------------------------------------------
build: ## Build default docker image
cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \
docker build -t $(IMAGE_TAG) .
PHONY: build
analyze: ## Analyze docker image
cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \
dive build -t $(IMAGE_TAG) .
.PHONY: analyze
build-from-cache: ## Build default docker image using cached layers
cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \
docker build --cache-from $(CACHE_FROM) . -t $(IMAGE_TAG)
PHONY: build-from-cache
pull: ## Pulls docker image from upstream
docker pull $(IMAGE_TAG)
.PHONY: pull
push: ## Pushes image to upstream
docker push $(IMAGE_TAG)
.PHONY: push
ssh: ## Login into built image
docker run --rm -it -v $(PWD)/:/opt/docker-php-dev $(IMAGE_TAG) sh
.PHONY: ssh
#
# Ansible Actions
# ------------------------------------------------------------------------------------
generate: ## Generates dockerfiles from ansible templates
ansible-playbook src/playbook.yml
PHONY: generate
clean: ## Cleans up generated files
rm -rf ./dist/*
PHONY: clean
#
# Testing
# ------------------------------------------------------------------------------------
test: ## Run dgoss tests over docker images
set -eux
GOSS_SLEEP="0.4" GOSS_WAIT_OPTS="-r 40s -s 2s > /dev/stdout" GOSS_FILES_STRATEGY=cp GOSS_FILES_PATH=$(DOCKERFILE_DIR) dgoss run -t $(IMAGE_TAG)
.PHONY: test
#
# 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-ansible ## Runs all linting commands
.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" "!app/vendor" "!app/node_modules" | 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" "!app/vendor" "!app/node_modules" | tee -a $(MAKE_LOGFILE)
.PHONY: lint-md-dry
lint-ansible: ## Lint ansible files inside project
@$(ANSIBLE_LINT_RUNNER) . | tee -a $(MAKE_LOGFILE)
.PHONY: lint-ansible
#
# Release
# ------------------------------------------------------------------------------------
commit: ## Run commitizen to create commit message
czg commit --config="./.github/.cz.config.js"
.PHONY: commit