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 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame] | 37 | all: test |
| 38 | |
| 39 | docker-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 | |
| 57 | docker-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 |
| 63 | test-docker: docker-start test-create test-delete docker-clean |
| 64 | |
| 65 | docker-start: |
| 66 | docker run -p 9102:9102 --name xos-tosca -d ${DOCKER_IMAGENAME} |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 67 | |
Matteo Scandolo | 78ca3eb | 2017-07-13 16:58:22 -0700 | [diff] [blame] | 68 | test-create: |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame] | 69 | 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 Scandolo | 485b713 | 2017-06-30 11:46:47 -0700 | [diff] [blame] | 74 | |
Matteo Scandolo | 78ca3eb | 2017-07-13 16:58:22 -0700 | [diff] [blame] | 75 | test-delete: |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame] | 76 | 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 Scandolo | 78ca3eb | 2017-07-13 16:58:22 -0700 | [diff] [blame] | 81 | |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame] | 82 | docker-clean: |
| 83 | docker rm -f xos-tosca || true |
| 84 | docker rmi -f ${DOCKER_IMAGENAME} || true |
| 85 | |
| 86 | test: test-unit |
| 87 | |
| 88 | test-unit: generate-xproto |
| 89 | tox |
| 90 | |
| 91 | venv-tosca: |
| 92 | virtualenv $@;\ |
| 93 | source ./$@/bin/activate ; set -u ;\ |
| 94 | pip install -r requirements.txt |
| 95 | |
| 96 | generate-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 Bavier | 58fac5d | 2019-05-20 16:28:09 -0700 | [diff] [blame] | 102 | test/test.xproto ;\ |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame] | 103 | 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 Bavier | 58fac5d | 2019-05-20 16:28:09 -0700 | [diff] [blame] | 108 | test/test.xproto |
Zack Williams | 6bb2cfe | 2019-03-27 15:01:45 -0700 | [diff] [blame] | 109 | |
| 110 | clean: |
| 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/* |