blob: 988ca06a06bc2914dc40aeb262531bc69a19cf81 [file] [log] [blame]
Zack Williams6bb2cfe2019-03-27 15:01:45 -07001# Copyright 2019-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
Matteo Scandolo9ce18252017-06-22 10:48:25 -070014
Zack Williams6bb2cfe2019-03-27 15:01:45 -070015# Configure shell
16SHELL = bash -e -o pipefail
Matteo Scandolo9ce18252017-06-22 10:48:25 -070017
Zack Williams6bb2cfe2019-03-27 15:01:45 -070018# Variables
19VERSION ?= $(shell cat ./VERSION)
20SERVICE_NAME ?= $(notdir $(abspath .))
21LOADER_NAME ?= tosca-loader
Matteo Scandolo5c0af1b2017-07-05 14:51:21 -070022
Zack Williams6bb2cfe2019-03-27 15:01:45 -070023## Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${SERVICE_NAME}:${DOCKER_TAG}
29LOADER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${LOADER_NAME}:${DOCKER_TAG}
Matteo Scandolo9ce18252017-06-22 10:48:25 -070030
Zack Williams6bb2cfe2019-03-27 15:01:45 -070031## Docker labels. Only set ref and commit date if committed
32DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
33DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
34DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
35DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
36
37## xosgenx related - paths are relative to this directory
38XOS_DIR ?= "../xos"
39
40all: test
41
42docker-build: generate-xproto
43 docker build $(DOCKER_BUILD_ARGS) \
44 -t ${DOCKER_IMAGENAME} \
45 --build-arg org_label_schema_version="${VERSION}" \
46 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
47 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
48 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
49 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
50 -f Dockerfile .
51 docker build $(DOCKER_BUILD_ARGS) \
52 -t ${LOADER_IMAGENAME} \
53 --build-arg org_label_schema_version="${VERSION}" \
54 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
55 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
56 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
57 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
58 -f loader/Dockerfile.tosca-loader loader
59
60docker-push:
61 docker push ${DOCKER_IMAGENAME}
62 docker push ${LOADER_IMAGENAME}
63
64# Test starting the image, loading TOSCA, deleting TOSCA, and cleaning up after
65# Not sure if this has been functional recently
66test-docker: docker-start test-create test-delete docker-clean
67
68docker-start:
69 docker run -p 9102:9102 --name xos-tosca -d ${DOCKER_IMAGENAME}
Matteo Scandolo9ce18252017-06-22 10:48:25 -070070
Matteo Scandolo78ca3eb2017-07-13 16:58:22 -070071test-create:
Zack Williams6bb2cfe2019-03-27 15:01:45 -070072 curl -H "xos-username: xosadmin@opencord.org" \
73 -H "xos-password: rk1UYDHZXbu6KVCMkhmV" \
74 -X POST \
75 --data-binary @test/tosca/test.yaml \
76 127.0.0.1:9102/run
Matteo Scandolo485b7132017-06-30 11:46:47 -070077
Matteo Scandolo78ca3eb2017-07-13 16:58:22 -070078test-delete:
Zack Williams6bb2cfe2019-03-27 15:01:45 -070079 curl -H "xos-username: xosadmin@opencord.org" \
80 -H "xos-password: rk1UYDHZXbu6KVCMkhmV" \
81 -X POST \
82 --data-binary @test/tosca/test.yaml \
83 127.0.0.1:9102/delete
Matteo Scandolo78ca3eb2017-07-13 16:58:22 -070084
Zack Williams6bb2cfe2019-03-27 15:01:45 -070085docker-clean:
86 docker rm -f xos-tosca || true
87 docker rmi -f ${DOCKER_IMAGENAME} || true
88
89test: test-unit
90
91test-unit: generate-xproto
92 tox
93
94venv-tosca:
95 virtualenv $@;\
96 source ./$@/bin/activate ; set -u ;\
97 pip install -r requirements.txt
98
99generate-xproto: venv-tosca
100 source ./venv-tosca/bin/activate ; set -u ;\
101 xosgenx \
102 --target=src/tosca/xtarget/tosca.xtarget \
103 --output=src/tosca/custom_types \
104 --write-to-file=target \
105 ${XOS_DIR}/xos/core/models/core.xproto ;\
106 xosgenx \
107 --target=src/tosca/xtarget/tosca_keys.xtarget \
108 --output=src/grpc_client/ \
109 --write-to-file=single \
110 --dest-file=KEYS.py \
111 ${XOS_DIR}/xos/core/models/core.xproto
112
113clean:
114 find . -name '*.pyc' | xargs rm -f
115 rm -rf \
116 .tox \
117 .coverage \
118 venv-tosca \
119 coverage \
120 coverage.xml \
121 nose2-results.xml \
122 src/grpc_client/KEYS.py \
123 src/grpc_client/__pycache__ \
124 src/tosca/__pycache__ \
125 src/tosca/custom_types/* \
126 test/__pycache__ \
127 test/out/*