-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile_smi-build
194 lines (146 loc) · 5.23 KB
/
makefile_smi-build
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Copyright 2020 Keyport Techonologies, Inc. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Usage:
#
# make Same as "make all".
# make all Build and publish a server image.
# make build Build the server image.
# make test Run tests against the built server.
# make deploy Build the server, a server image and push the image to an image registry.
# make clean Remove build output, build image and server images.
#
# Notes:
#
# 1. Build only runs the build and tests the server. The folder home will
# contain the built server.
# 2. Publish will build, test, create the server image and push it to an image
# registry.
# 3. The ~/.ssh folder and the Docker-in-Docker folder need to be mapped
# volumes when running a make command.
#
# sudo docker run -it --rm \
# -v /home/<username>/.ssh:/root/.ssh \
# -v /var/run/docker.sock:/var/run/docker.sock \
# smi-build:tag \
# "make build"
DOCKER_REGISTRY=keyporttech
SERVER_IMAGE=smi-server
SERVER_IMAGE_VERSION=0.1.2
# Use http to clone repository because no authentication required
PEGASUS_GIT_REPOSITORY=http://github.com/OpenPegasus/OpenPegasus.git
SHELL=/bin/bash
.ONESHELL:
.PHONY: all build test publish clean
# Top-level build targets
all: build \
publish
build: clone-repository \
build-server \
test-server
deploy: build \
docker-build-server-image \
docker-push-server-image
test: test-server
clean: clean-build \
docker-remove-server-images
# Subtargets for build
clone-repository:
@echo "Cloning OpenPegasus GitHub respository using build container..."
@echo "Listing the current environment path..."
@echo ${PATH}
@ Set global git config to ignore certificate
git config --global http.sslverify false
@echo "Changing to SMI root directory ${PEGASUS_SMI_ROOT}"
cd ${PEGASUS_SMI_ROOT}
@echo "Cloning OpenPegasus github repo under the SMI root directory ${PEGASUS_GIT_REPOSITORY}"
git clone ${PEGASUS_GIT_REPOSITORY}
build-server:
@echo "Building the server using the build container..."
@echo "Changing to pegasus root directory..."
cd ${PEGASUS_ROOT}
@echo "Building the server using the pegasus source..."
make clobber clean
make build
test-server:
@echo "Testing the server using the build container..."
@echo "Changing to pegasus root directory..."
cd ${PEGASUS_ROOT}
@echo "Testing the server build..."
make repository
make testrepository
make tests
# recreate after tests. Note that we should actually clear the
# home directory of a number of items and leave just what is required
make repository
make testrepository
provision-server:
@echo "Provision the server in build container..."
@echo "Create the repository..."
make repository
# TODO: This will become optional so that the user can create their
# specific repository extensions.
make testrepository
remove-uneeded-components:
@echo "Remove the server unwanted files in the build container..."
@echo "Remove all test executables"
cd ${PEGASUS_HOME}
rm bin/Test*
@echo remove object files
rm -r obj
@echo remove any trace files
TRACEDIR="trace"
if [ -d "${TRACEDIR}" ]; then
rm ${TRACEDIR}/*
endif
@echo Remove unwanted schemas
# TODO: This assumes that CIM241 is the desired schema
# This can only be used if there is no correspondence to files on the
# host since it removes the files from the host also. Blocking for now
cd ${PEGASUS_ROOT}/Schemas
# rm -rdf CIM2131
# rm -rdf CIM217
# rm -rdf CIM222
# rm -rdf CIM225
# rm -rdf CIM228
# rm -rdf CIM231
# rm -rdf CIM236
# rm -rdf CIM25
# rm -rdf CIM29
# FUTURE: Remove all source files
# Subtargets for publish
docker-build-server-image: remove-uneeded-components
@echo "Building the SMI Server image..."
@echo "Listing the current docker version..."
docker version
@echo "Changing to SMI root directory..."
cd ${PEGASUS_SMI_ROOT}
docker build --tag ${SERVER_IMAGE}:${SERVER_IMAGE_VERSION} .
docker-push-server-image:
@echo "Pushing the built SMI Server image to private image registry..."
docker logout
docker login -u $${DOCKER_USER} -p $${DOCKER_PASSWORD}
docker tag ${SERVER_IMAGE}:${SERVER_IMAGE_VERSION} ${DOCKER_REGISTRY}/${SERVER_IMAGE}:${SERVER_IMAGE_VERSION}
docker push ${DOCKER_REGISTRY}/${SERVER_IMAGE}:${SERVER_IMAGE_VERSION}
docker logout
# Subtargets for clean
clean-build:
@echo "Cleaning the build container..."
@echo "Changing to pegasus root directory..."
cd ${PEGASUS_ROOT}
@echo "Cleaning the build..."
make clobber
make clean
docker-remove-server-images:
@echo "Removing server images..."
@echo "Removing the repository tagged server image..."
docker rmi ${DOCKER_REGISTRY}/${SERVER_IMAGE}:${SERVER_IMAGE_VERSION}
@echo "Removing the server image..."
docker rmi ${SERVER_IMAGE}:${SERVER_IMAGE_VERSION}