blob: 2b08bd261785c2e41e3af55e70971658d6213ac1 [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
Zack Williams6bb2cfe2019-03-27 15:01:45 -070037all: test
38
39docker-build: generate-xproto
40 docker build $(DOCKER_BUILD_ARGS) \
41 -t ${DOCKER_IMAGENAME} \
42 --build-arg org_label_schema_version="${VERSION}" \
43 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
44 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
45 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
46 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
47 -f Dockerfile .
48 docker build $(DOCKER_BUILD_ARGS) \
49 -t ${LOADER_IMAGENAME} \
50 --build-arg org_label_schema_version="${VERSION}" \
51 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
52 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
53 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
54 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
55 -f loader/Dockerfile.tosca-loader loader
56
57docker-push:
58 docker push ${DOCKER_IMAGENAME}
59 docker push ${LOADER_IMAGENAME}
60
61# Test starting the image, loading TOSCA, deleting TOSCA, and cleaning up after
62# Not sure if this has been functional recently
63test-docker: docker-start test-create test-delete docker-clean
64
65docker-start:
66 docker run -p 9102:9102 --name xos-tosca -d ${DOCKER_IMAGENAME}
Matteo Scandolo9ce18252017-06-22 10:48:25 -070067
Matteo Scandolo78ca3eb2017-07-13 16:58:22 -070068test-create:
Zack Williams6bb2cfe2019-03-27 15:01:45 -070069 curl -H "xos-username: xosadmin@opencord.org" \
70 -H "xos-password: rk1UYDHZXbu6KVCMkhmV" \
71 -X POST \
72 --data-binary @test/tosca/test.yaml \
73 127.0.0.1:9102/run
Matteo Scandolo485b7132017-06-30 11:46:47 -070074
Matteo Scandolo78ca3eb2017-07-13 16:58:22 -070075test-delete:
Zack Williams6bb2cfe2019-03-27 15:01:45 -070076 curl -H "xos-username: xosadmin@opencord.org" \
77 -H "xos-password: rk1UYDHZXbu6KVCMkhmV" \
78 -X POST \
79 --data-binary @test/tosca/test.yaml \
80 127.0.0.1:9102/delete
Matteo Scandolo78ca3eb2017-07-13 16:58:22 -070081
Zack Williams6bb2cfe2019-03-27 15:01:45 -070082docker-clean:
83 docker rm -f xos-tosca || true
84 docker rmi -f ${DOCKER_IMAGENAME} || true
85
86test: test-unit
87
88test-unit: generate-xproto
89 tox
90
91venv-tosca:
92 virtualenv $@;\
93 source ./$@/bin/activate ; set -u ;\
94 pip install -r requirements.txt
95
96generate-xproto: venv-tosca
97 source ./venv-tosca/bin/activate ; set -u ;\
98 xosgenx \
99 --target=src/tosca/xtarget/tosca.xtarget \
100 --output=src/tosca/custom_types \
101 --write-to-file=target \
Andy Bavier58fac5d2019-05-20 16:28:09 -0700102 test/test.xproto ;\
Zack Williams6bb2cfe2019-03-27 15:01:45 -0700103 xosgenx \
104 --target=src/tosca/xtarget/tosca_keys.xtarget \
105 --output=src/grpc_client/ \
106 --write-to-file=single \
107 --dest-file=KEYS.py \
Andy Bavier58fac5d2019-05-20 16:28:09 -0700108 test/test.xproto
Zack Williams6bb2cfe2019-03-27 15:01:45 -0700109
110clean:
111 find . -name '*.pyc' | xargs rm -f
112 rm -rf \
113 .tox \
114 .coverage \
115 venv-tosca \
116 coverage \
117 coverage.xml \
118 nose2-results.xml \
119 src/grpc_client/KEYS.py \
120 src/grpc_client/__pycache__ \
121 src/tosca/__pycache__ \
122 src/tosca/custom_types/* \
123 test/__pycache__ \
124 test/out/*