-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
166 lines (131 loc) · 4.56 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Extremely simple HTTP server that responds on port 8000 with a hello message in HTML format.
DOCKER_HUB_ID ?= ibmosquito
MATCH ?= "Hello"
TIME_OUT ?= 30
# The Open Horizon Exchange's organization ID namespace where you will be publishing files
HZN_ORG_ID ?= examples
export SERVICE_NAME ?= web-hello-python
PATTERN_NAME ?= pattern-web-helloworld-python
DEPLOYMENT_POLICY_NAME ?= deployment-policy-web-helloworld-python
NODE_POLICY_NAME ?= node-policy-web-helloworld-python
export SERVICE_VERSION ?= 1.0.0
export SERVICE_CONTAINER := $(DOCKER_HUB_ID)/$(SERVICE_NAME):$(SERVICE_VERSION)
ARCH ?= amd64
# Detect Operating System running Make
OS := $(shell uname -s)
# Leave blank for open DockerHub containers
# CONTAINER_CREDS:=-r "registry.wherever.com:myid:mypw"
CONTAINER_CREDS ?=
default: build run
build:
docker build -t $(SERVICE_CONTAINER) .
dev: stop build
docker run -it -v `pwd`:/outside \
--name ${SERVICE_NAME} \
-p 8000:8000 \
$(SERVICE_CONTAINER) /bin/bash
run: stop
docker run -d \
--name ${SERVICE_NAME} \
--restart unless-stopped \
-p 8000:8000 \
$(SERVICE_CONTAINER)
check-syft:
@echo "=================="
@echo "Generating SBoM syft-output file..."
@echo "=================="
syft $(SERVICE_CONTAINER) > syft-output
cat syft-output
check:
@echo "=================="
@echo "SERVICE DEFINITION"
@echo "=================="
@cat service.json | envsubst
@echo ""
# add SBOM for the source code
check-grype:
grype $(SERVICE_CONTAINER) > grype-output
cat grype-output
sbom-policy-gen:
@echo "=================="
@echo "Generating service.policy.json file..."
@echo "=================="
./sbom-property-gen.sh
test:
@echo "=================="
@echo "Testing $(SERVICE_NAME)..."
@echo "=================="
@curl -sS http://127.0.0.1:8000
push:
docker push $(SERVICE_CONTAINER)
publish: publish-service publish-service-policy publish-deployment-policy
remove: remove-deployment-policy remove-service-policy remove-service
publish-service:
@echo "=================="
@echo "PUBLISHING SERVICE"
@echo "=================="
@hzn exchange service publish -O $(CONTAINER_CREDS) --json-file=service.json --pull-image
@echo ""
remove-service:
@echo "=================="
@echo "REMOVING SERVICE"
@echo "=================="
@hzn exchange service remove -f $(HZN_ORG_ID)/$(SERVICE_NAME)_$(SERVICE_VERSION)_$(ARCH)
@echo ""
publish-service-policy:
@echo "========================="
@echo "PUBLISHING SERVICE POLICY"
@echo "========================="
@hzn exchange service addpolicy -f service.policy.json $(HZN_ORG_ID)/$(SERVICE_NAME)_$(SERVICE_VERSION)_$(ARCH)
@echo ""
remove-service-policy:
@echo "======================="
@echo "REMOVING SERVICE POLICY"
@echo "======================="
@hzn exchange service removepolicy -f $(HZN_ORG_ID)/$(SERVICE_NAME)_$(SERVICE_VERSION)_$(ARCH)
@echo ""
publish-pattern:
@ARCH=$(ARCH) \
SERVICE_NAME="$(SERVICE_NAME)" \
SERVICE_VERSION="$(SERVICE_VERSION)"\
PATTERN_NAME="$(PATTERN_NAME)" \
hzn exchange pattern publish -f pattern.json
publish-deployment-policy:
@echo "============================"
@echo "PUBLISHING DEPLOYMENT POLICY"
@echo "============================"
@hzn exchange deployment addpolicy -f deployment.policy.json $(HZN_ORG_ID)/policy-$(SERVICE_NAME)_$(SERVICE_VERSION)
@echo ""
remove-deployment-policy:
@echo "=========================="
@echo "REMOVING DEPLOYMENT POLICY"
@echo "=========================="
@hzn exchange deployment removepolicy -f $(HZN_ORG_ID)/policy-$(SERVICE_NAME)_$(SERVICE_VERSION)
@echo ""
stop:
@docker rm -f ${SERVICE_NAME} >/dev/null 2>&1 || :
clean:
@docker rmi -f $(SERVICE_CONTAINER) >/dev/null 2>&1 || :
agent-run:
@echo "================"
@echo "REGISTERING NODE"
@echo "================"
@hzn register --policy=node.policy.json
@watch hzn agreement list
agent-run-pattern:
@hzn register --pattern "${HZN_ORG_ID}/$(PATTERN_NAME)"
agent-stop:
@hzn unregister -f
deploy-check:
@hzn deploycheck all -t device -B deployment.policy.json --service=service.json --service-pol=service.policy.json --node-pol=node.policy.json
log:
@echo "========="
@echo "EVENT LOG"
@echo "========="
@hzn eventlog list
@echo ""
@echo "==========="
@echo "SERVICE LOG"
@echo "==========="
@hzn service log -f $(SERVICE_NAME)
.PHONY: default build dev run test check push publish remove publish-service remove-service publish-service-policy remove-service-policy publish-pattern publish-deployment-policy remove-deployment-policy stop clean agent-run agent-run-pattern agent-stop deploy-check log