generated from wayofdev/docker-tpl
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
124 lines (101 loc) · 3.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
# BuildKit enables higher performance docker builds and caching possibility
# to decrease build times and increase productivity for free.
export DOCKER_BUILDKIT ?= 1
export COMPOSE_DOCKER_CLI_BUILD ?= 1
IMAGE_NAMESPACE ?= wayofdev/node
IMAGE_TEMPLATE ?= 18-alpine
IMAGE_TAG ?= $(IMAGE_NAMESPACE):$(IMAGE_TEMPLATE)-latest
DOCKERFILE_DIR ?= ./dist/$(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-node.log
MAKE_CMD_COLOR := $(BLUE)
default: all
help: ## Show this menu
@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-node (github.com/wayofdev/docker-node)'
@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: hooks generate build test
.PHONY: all
# Docker Actions
# ------------------------------------------------------------------------------------
build: ## Build default docker image
cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \
docker build -t $(IMAGE_TAG) .
PHONY: build
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_FILES_STRATEGY=cp GOSS_FILES_PATH=$(DOCKERFILE_DIR) dgoss run --add-host app:127.0.0.1 -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/node $(IMAGE_TAG) sh
.PHONY: ssh
# Ansible Actions
# ------------------------------------------------------------------------------------
generate: ## Generate dist files from src folder using ansible playbook
ansible-playbook src/playbook.yml
PHONY: generate
clean: ## Deletes all files in dist folder
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
lint-ansible: ## Lint ansible files inside project
ansible-lint .
.PHONY: lint-ansible
lint-docker: ## Run hadolint over dist Dockerfiles
hadolint -V ./dist/$(IMAGE_TEMPLATE)/Dockerfile
.PHONY: lint-docker