forked from wayofdev/docker-php-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
138 lines (114 loc) · 4.27 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
# 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
IMAGE_NAMESPACE ?= wayofdev/php-base
IMAGE_TEMPLATE ?= 8.3-fpm-alpine
IMAGE_TAG ?= $(IMAGE_NAMESPACE):$(IMAGE_TEMPLATE)-latest
DOCKERFILE_DIR ?= ./dist/base/$(IMAGE_TEMPLATE)
CACHE_FROM ?= $(IMAGE_TAG)
OS ?= $(shell uname)
CURRENT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# 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/docker-php-base.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_LIST) | 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-base (github.com/wayofdev/docker-php-base)'
@echo ' 🤠 Author Andrij Orlenko (github.com/lotyp)'
@echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
.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
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
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-base $(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
# Code Quality, Git, Linting, Testing
# ------------------------------------------------------------------------------------
hooks: ## Install git hooks from pre-commit-config
pre-commit install
pre-commit autoupdate
.PHONY: hooks
lint-yaml: ## Lints yaml files inside project
yamllint .
.PHONY: lint-yaml
lint-ansible: ## Lint ansible files inside project
ansible-lint .
.PHONY: lint-ansible
lint-docker: ## Run hadolint linter over dist Dockerfiles
hadolint -V ./dist/base/8.1-cli-alpine/Dockerfile
hadolint -V ./dist/base/8.1-fpm-alpine/Dockerfile
hadolint -V ./dist/base/8.1-supervisord-alpine/Dockerfile
hadolint -V ./dist/base/8.2-cli-alpine/Dockerfile
hadolint -V ./dist/base/8.2-fpm-alpine/Dockerfile
hadolint -V ./dist/base/8.2-supervisord-alpine/Dockerfile
hadolint -V ./dist/base/8.3-cli-alpine/Dockerfile
hadolint -V ./dist/base/8.3-fpm-alpine/Dockerfile
hadolint -V ./dist/base/8.3-supervisord-alpine/Dockerfile
.PHONY: lint-docker