1
+ # ###########################################################################
2
+ # Variables
3
+ # ###########################################################################
4
+
1
5
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
2
6
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
3
7
8
+ # SHELL stores the shell that the Makefile uses.
9
+ SHELL := /bin/bash -o errexit -o nounset
10
+
11
+ # disable docker BuildKit option
12
+ DOCKER_BUILDKIT =0
13
+ # disable docker cli build option
14
+ COMPOSE_DOCKER_CLI_BUILD =0
15
+
16
+ # UNAME_OS stores the value of uname -s.
17
+ UNAME_OS := $(shell uname -s)
18
+ # UNAME_ARCH stores the value of uname -m.
19
+ UNAME_ARCH := $(shell uname -m | sed s/x86_64/amd64/ | sed s/aarch64/arm64/ | sed s/aarch64_be/arm64/)
20
+ # ROOT_DIR stores git root directory
21
+ ROOT_DIR := $(shell git rev-parse --show-toplevel)
22
+ # ORIGINAL_BRANCH stores git branch name
23
+ ORIGINAL_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
24
+ # GIT_SHA stores git last commit hash
25
+ GIT_SHA := $(shell git rev-parse HEAD)
26
+
4
27
IMAGE ?= styled-proverbs
5
28
TAG ?= latest
6
29
30
+ # Set V=1 on the command line to turn off all suppression. Many trivial
31
+ # commands are suppressed with "@", by setting V=1, this will be turned off.
32
+ ifeq ($(V ) ,1)
33
+ AT :=
34
+ else
35
+ AT := @
36
+ endif
37
+
38
+ # if this session isn't interactive, then we don't want to allocate a
39
+ # TTY, which would fail, but if it is interactive, we do want to attach
40
+ # so that the user can send e.g. ^C through.
41
+ INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
42
+ ifeq ($(INTERACTIVE ) , 1)
43
+ DOCKER_FLAGS += -t
44
+ endif
45
+
7
46
UTILS := docker
8
47
# Make sure that all required utilities can be located.
9
48
UTIL_CHECK := $(or $(shell which $(UTILS ) >/dev/null && echo 'ok') ,$(error Did you forget to install `docker` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS ) ) )
10
49
50
+ # Run all by default when "make" is invoked.
51
+ .DEFAULT_GOAL := help
52
+
53
+ # ###########################################################################
54
+ # Common
55
+ # ###########################################################################
56
+
11
57
# Default target (by virtue of being the first non '.'-prefixed in the file).
12
58
.PHONY : _no-target-specified
13
59
_no-target-specified :
14
60
$(error Please specify the target to make - `make list` shows targets)
15
61
16
- # Lists all targets defined in this makefile.
17
- .PHONY : list
18
- list :
19
- @$(MAKE ) -pRrn : -f $(MAKEFILE_LIST ) 2> /dev/null | awk -v RS= -F: ' /^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | command grep -v -e ' ^[^[:alnum:]]' -e ' ^$@$$command ' | sort
20
-
21
62
# Ensure docker token command.
22
63
.PHONY : _ensure-token
23
64
_ensure-token :
@@ -30,15 +71,90 @@ endif
30
71
_ensure-clean :
31
72
@[ -z " $$ ((git status --porcelain --untracked-files=no || echo err) | command grep -v 'CHANGELOG.md')" ] || { echo " Workspace is not clean; please commit changes first." >&2 ; exit 2; }
32
73
74
+ # Lists all targets defined in this makefile.
75
+ .PHONY : list
76
+ list :
77
+ @$(MAKE ) -pRrn : -f $(MAKEFILE_LIST ) 2> /dev/null | awk -v RS= -F: ' /^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | command grep -v -e ' ^[^[:alnum:]]' -e ' ^$@$$command ' | sort
78
+
79
+ # Run information command with target descriptions.
80
+ .PHONY : help
81
+ # #= diff: to show modified files
82
+ # #= docker-build: to build docker image
83
+ # #= docker-clean: to remove docker container
84
+ # #= docker-lint: to lint docker image
85
+ # #= docker-list: to list docker images
86
+ # #= docker-rebuild: to rebuild docker image
87
+ # #= docker-remove: to remove docker container
88
+ # #= docker-remove-all: to remove all docker images
89
+ # #= docker-start: to start docker container
90
+ # #= docker-stop: to stop docker container
91
+ # #= help: to list all make targets with descriptions
92
+ # #= info: to gather environment information
93
+ # #= list: to list all make targets
94
+ # #= tilt-start: to start k8s cluster
95
+ # #= tilt-stop: to stop k8s cluster
96
+ help :
97
+ @echo
98
+ @echo
99
+ @echo " Please use [make <target>] where <target> is one of:"
100
+ @echo
101
+ $(AT ) sed -n ' s/^##=//p' $(MAKEFILE_LIST ) 2> /dev/null | column -t -s ' :' | sed -e ' s/^/ /'
102
+ @echo
103
+ @echo
104
+
105
+ # # Show information about the runtime environment
106
+ .PHONY : info
107
+ info :
108
+ @echo
109
+ @echo
110
+ $(AT ) echo " user: $$ (whoami)" ; \
111
+ $(AT ) echo " directory: $$ (pwd)" ; \
112
+ $(AT ) echo " ls -ahl: $$ (ls -ahl)" ; \
113
+ docker images; \
114
+ docker ps
115
+ @echo
116
+ @echo
117
+
33
118
# Run docker build command.
34
119
.PHONY : docker-build
35
120
docker-build : _ensure-token _ensure-clean
36
- docker build -f Dockerfile -t $(IMAGE ) :$(TAG ) --build-arg VERCEL_TOKEN=$(TOKEN ) .
121
+ docker build --rm --platform=linux/$(UNAME_ARCH ) -f Dockerfile -t $(IMAGE ) :$(TAG ) -t " $( IMAGE) :$( GIT_SHA) " --build-arg VERCEL_TOKEN=$(TOKEN ) .
122
+
123
+ # Run docker rebuild command.
124
+ .PHONY : docker-rebuild
125
+ docker-rebuild : _ensure-token _ensure-clean
126
+ docker build --rm --platform=linux/$(UNAME_ARCH ) -f Dockerfile -t " $( IMAGE) :$( TAG) " -t " $( IMAGE) :$( GIT_SHA) " --build-arg VERCEL_TOKEN=$(TOKEN ) --no-cache=true .
127
+
128
+ # Run docker list command.
129
+ .PHONY : docker-list
130
+ docker-list :
131
+ docker container list --filter name=" $( IMAGE) " --format ' {{ .ID }}'
132
+
133
+ # Run docker remove container command.
134
+ .PHONY : docker-remove
135
+ docker-remove :
136
+ docker container rm --force " $( IMAGE) " > /dev/null
137
+
138
+ # Run docker remove all images command.
139
+ .PHONY : docker-remove-all
140
+ docker-remove-all :
141
+ docker images | grep $(IMAGE ) | awk ' {print $3}' | xargs docker rmi -f
142
+
143
+ # Run docker lint command.
144
+ .PHONY : docker-lint
145
+ docker-lint :
146
+ docker run -it --rm --platform=linux/amd64 --privileged -v ` pwd` :/root/ \
147
+ projectatomic/dockerfile-lint \
148
+ dockerfile_lint -f Dockerfile -r ./default_rules.yaml
149
+
150
+ # Run docker clean command.
151
+ .PHONY : docker-clean
152
+ docker-clean : docker-stop docker-remove
37
153
38
154
# Run docker start command.
39
155
.PHONY : docker-start
40
156
docker-start :
41
- docker-compose -f docker-compose.yml up -d
157
+ docker-compose -f docker-compose.yml up -d --force-recreate
42
158
43
159
# Run docker stop command.
44
160
.PHONY : docker-stop
@@ -54,3 +170,8 @@ tilt-start:
54
170
.PHONY : tilt-stop
55
171
tilt-stop :
56
172
tilt down --delete-namespaces
173
+
174
+ # Run git diff command.
175
+ .PHONY : diff
176
+ diff :
177
+ $(AT ) git diff --diff-filter=d --name-only
0 commit comments