forked from TomerFi/switcher_webapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
113 lines (89 loc) · 4.68 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
# ******************************************************************** #
# .env_vars file contains following keys, example: #
# -------------------------------------------------------------------- #
# (Optional) #
# EXPOSED_PORT=8000 #
# CONF_THROTTLE=5.0 #
# #
# (Mandatory) #
# CONF_DEVICE_IP_ADDR=192.168.100.157 #
# CONF_PHONE_ID=1234 #
# CONF_DEVICE_ID=ab1c2d #
# CONF_DEVICE_PASSWORD=12345678 #
# #
# change the source file name by passing env_vars=another_file to make #
# ******************************************************************** #
EXPOSED_PORT ?= 8000
CONF_THROTTLE ?= 5.0
env_vars ?= .env_vars
include $(env_vars)
export $(shell sed 's/=.*//' $(env_vars))
default: help
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
IMAGE_NAME = tomerfi/switcher_webapi
CONTAINER_NAME = switcher_webapi
GIT_COMMIT = $(strip $(shell git rev-parse --short HEAD))
CURRENT_DATE = $(strip $(shell date -u +"%Y-%m-%dT%H:%M:%SZ"))
CODE_VERSION = $(strip $(shell cat VERSION))
ifndef CODE_VERSION
$(error You need to create a VERSION file to build the image.)
endif
FULL_IMAGE_NAME = $(strip $(IMAGE_NAME):$(CODE_VERSION))
docker-build: ## build image from Dockerfile.
docker build \
--build-arg VCS_REF=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(CURRENT_DATE) \
--build-arg VERSION=$(CODE_VERSION) \
-t $(FULL_IMAGE_NAME) .
docker-build-testing-image: ## build image from Dockerfile using a testing tag.
docker build \
--build-arg VCS_REF=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(CURRENT_DATE) \
--build-arg VERSION=testing \
-t $(strip $(IMAGE_NAME)):testing .
docker-remove-testing-image: ## remove the testing image (must be build first).
docker image rm $(strip $(IMAGE_NAME)):testing
docker-build-no-cache: ## build image from Dockerfile with no caching.
docker build --no-cache \
--build-arg VCS_REF=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(CURRENT_DATE) \
--build-arg VERSION=$(CODE_VERSION) \
-t $(FULL_IMAGE_NAME) .
structure-test: ## run the container-structure-test tool against the built testing image (must be build first) using the relative container_structure.yml file
sh shellscripts/container-structure-test-verify.sh container_structure.yml $(strip $(IMAGE_NAME)):testing
docker-build-structure-test: ## build the image and test the container structure
docker-build-structure-test: docker-build structure-test
docker-build-no-cache-structure-test: ## build the image and test the container structure
docker-build-no-cache-structure-test: docker-build-no-cache structure-test
docker-full-structure-testing: ## build the image with the testing tag and remove after structure test
docker-full-structure-testing: docker-build-testing-image structure-test docker-remove-testing-image
docker-tag-latest: ## add latest tag before pushing the latest version
docker tag $(FULL_IMAGE_NAME) $(IMAGE_NAME):latest
docker-run: ## run the built image as a container (must be built first).
docker-run: verify-environment-file
docker run -d -p $(EXPOSED_PORT):8000 \
-e CONF_DEVICE_IP_ADDR=$(CONF_DEVICE_IP_ADDR) \
-e CONF_PHONE_ID=$(CONF_PHONE_ID) \
-e CONF_DEVICE_ID=$(CONF_DEVICE_ID) \
-e CONF_DEVICE_PASSWORD=$(CONF_DEVICE_PASSWORD) \
-e CONF_THROTTLE=$(CONF_THROTTLE) \
--name $(CONTAINER_NAME) $(FULL_IMAGE_NAME)
docker-build-and-run: ## build image from Dockerfile and run as container.
docker-build-and-run: docker-build docker-run
docker-build-no-cache-and-run: ## build image from Dockerfile with no caching and run as container.
docker-build-no-cache-and-run: docker-build-no-cache docker-run
verify-environment-file: ## verify the existence of the required environment variables file.
ifndef CONF_DEVICE_IP_ADDR
$(error Mandatory configuration value CONF_DEVICE_IP_ADDR was not provided, can't run container.)
endif
ifndef CONF_PHONE_ID
$(error Mandatory configuration value CONF_PHONE_ID was not provided, can't run container.)
endif
ifndef CONF_DEVICE_ID
$(error Mandatory configuration value CONF_DEVICE_ID was not provided, can't run container.)
endif
ifndef CONF_DEVICE_PASSWORD
$(error Mandatory configuration value CONF_DEVICE_PASSWORD was not provided, can't run container.)
endif
$(info Safe to run image (assuming the provided information is infact correct).)