Skip to content

Commit f83a3c4

Browse files
author
Alexander Rogalskiy
committed
Updates on files
1 parent de3a960 commit f83a3c4

File tree

2 files changed

+136
-7
lines changed

2 files changed

+136
-7
lines changed

Makefile

+128-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,64 @@
1+
############################################################################
2+
# Variables
3+
############################################################################
4+
15
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
26
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
37

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+
427
IMAGE ?= styled-proverbs
528
TAG ?= latest
629

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+
746
UTILS := docker
847
# Make sure that all required utilities can be located.
948
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)))
1049

50+
# Run all by default when "make" is invoked.
51+
.DEFAULT_GOAL := help
52+
53+
############################################################################
54+
# Common
55+
############################################################################
56+
1157
# Default target (by virtue of being the first non '.'-prefixed in the file).
1258
.PHONY: _no-target-specified
1359
_no-target-specified:
1460
$(error Please specify the target to make - `make list` shows targets)
1561

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-
2162
# Ensure docker token command.
2263
.PHONY: _ensure-token
2364
_ensure-token:
@@ -30,15 +71,90 @@ endif
3071
_ensure-clean:
3172
@[ -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; }
3273

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+
33118
# Run docker build command.
34119
.PHONY: docker-build
35120
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
37153

38154
# Run docker start command.
39155
.PHONY: docker-start
40156
docker-start:
41-
docker-compose -f docker-compose.yml up -d
157+
docker-compose -f docker-compose.yml up -d --force-recreate
42158

43159
# Run docker stop command.
44160
.PHONY: docker-stop
@@ -54,3 +170,8 @@ tilt-start:
54170
.PHONY: tilt-stop
55171
tilt-stop:
56172
tilt down --delete-namespaces
173+
174+
# Run git diff command.
175+
.PHONY: diff
176+
diff:
177+
$(AT)git diff --diff-filter=d --name-only

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ See also the list of [contributors][contributors] who participated in this proje
703703

704704
[![Stargazers repo roster for @AlexRogalskiy/proverbs](https://reporoster.com/stars/AlexRogalskiy/proverbs)][stars]
705705

706+
[![Stargazers over time](https://starchart.cc/AlexRogalskiy/proverbs.svg)][stars_chart]
707+
708+
[![Statistics report](https://cauldron.io/project/5117/stats.svg)][stats_chart]
709+
706710
## *Forks*
707711

708712
[![Forkers repo roster for @AlexRogalskiy/proverbs](https://reporoster.com/forks/AlexRogalskiy/proverbs)][forkers]
@@ -759,6 +763,10 @@ Like ***Styled Proverbs*** ? Consider buying me a coffee :)
759763

760764
[stars]: https://github.com/AlexRogalskiy/proverbs/stargazers
761765

766+
[stars_chart]: https://starchart.cc/AlexRogalskiy/proverbs
767+
768+
[stats_chart]: https://cauldron.io/project/5117
769+
762770
[forkers]: https://github.com/AlexRogalskiy/proverbs/network/members
763771

764772
[contributors]: https://github.com/AlexRogalskiy/proverbs/graphs/contributors

0 commit comments

Comments
 (0)