Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 1 | # 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 Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 14 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 15 | # Configure shell |
| 16 | SHELL = bash -e -o pipefail |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 17 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 18 | # Variables |
| 19 | VERSION ?= $(shell cat ./VERSION) |
| 20 | SERVICE_NAME ?= $(notdir $(abspath .)) |
| 21 | LOADER_NAME ?= tosca-loader |
Matteo Scandolo | 5c0af1b | 2017-07-05 14:51:21 -0700 | [diff] [blame] | 22 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 23 | ## Docker related |
| 24 | DOCKER_REGISTRY ?= |
| 25 | DOCKER_REPOSITORY ?= |
| 26 | DOCKER_BUILD_ARGS ?= |
| 27 | DOCKER_TAG ?= ${VERSION} |
| 28 | DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${SERVICE_NAME}:${DOCKER_TAG} |
| 29 | LOADER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${LOADER_NAME}:${DOCKER_TAG} |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 30 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 31 | ## Docker labels. Only set ref and commit date if committed |
| 32 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 33 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 34 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 35 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 36 | |
| 37 | ## xosgenx related - paths are relative to this directory |
| 38 | XOS_DIR ?= "../xos" |
| 39 | |
| 40 | all: test |
| 41 | |
| 42 | docker-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 | |
| 60 | docker-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 |
| 66 | test-docker: docker-start test-create test-delete docker-clean |
| 67 | |
| 68 | docker-start: |
| 69 | docker run -p 9102:9102 --name xos-tosca -d ${DOCKER_IMAGENAME} |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 70 | |
Matteo Scandolo | 78ca3eb | 2017-07-13 16:58:22 -0700 | [diff] [blame] | 71 | test-create: |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 72 | 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 Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 77 | |
Matteo Scandolo | 78ca3eb | 2017-07-13 16:58:22 -0700 | [diff] [blame] | 78 | test-delete: |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 79 | 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 Scandolo | 78ca3eb | 2017-07-13 16:58:22 -0700 | [diff] [blame] | 84 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame^] | 85 | docker-clean: |
| 86 | docker rm -f xos-tosca || true |
| 87 | docker rmi -f ${DOCKER_IMAGENAME} || true |
| 88 | |
| 89 | test: test-unit |
| 90 | |
| 91 | test-unit: generate-xproto |
| 92 | tox |
| 93 | |
| 94 | venv-tosca: |
| 95 | virtualenv $@;\ |
| 96 | source ./$@/bin/activate ; set -u ;\ |
| 97 | pip install -r requirements.txt |
| 98 | |
| 99 | generate-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 | |
| 113 | clean: |
| 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/* |