Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -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. |
| 14 | |
| 15 | # Makefile for testing and developing XOS |
| 16 | |
| 17 | # set default shell |
| 18 | SHELL = bash -e -o pipefail |
| 19 | |
| 20 | # Variables |
Zack Williams | 9a76635 | 2019-04-09 18:08:05 -0700 | [diff] [blame^] | 21 | VERSION ?= $(shell cat ./VERSION) |
| 22 | CORE_NAME ?= xos-core |
| 23 | CLIENT_NAME ?= xos-client |
Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -0700 | [diff] [blame] | 24 | |
Zack Williams | 9a76635 | 2019-04-09 18:08:05 -0700 | [diff] [blame^] | 25 | ## Testing related |
| 26 | XOS_LIBRARIES := $(wildcard lib/*) |
| 27 | |
| 28 | ## Docker related |
| 29 | DOCKER_REGISTRY ?= |
| 30 | DOCKER_REPOSITORY ?= |
| 31 | DOCKER_BUILD_ARGS ?= |
| 32 | DOCKER_TAG ?= ${VERSION} |
| 33 | CORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CORE_NAME}:${DOCKER_TAG} |
| 34 | CLIENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CLIENT_NAME}:${DOCKER_TAG} |
| 35 | |
| 36 | ## Docker labels. Only set ref and commit date if committed |
| 37 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 38 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 39 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 40 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 41 | |
| 42 | # Targets |
| 43 | all: test |
| 44 | |
| 45 | ## Docker targets |
| 46 | docker-build: |
| 47 | docker build $(DOCKER_BUILD_ARGS) \ |
| 48 | -t ${CORE_IMAGENAME} \ |
| 49 | --build-arg org_label_schema_version="${VERSION}" \ |
| 50 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 51 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 52 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 53 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 54 | -f Dockerfile.core . |
| 55 | docker build $(DOCKER_BUILD_ARGS) \ |
| 56 | -t ${CLIENT_IMAGENAME} \ |
| 57 | --build-arg org_label_schema_version="${VERSION}" \ |
| 58 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 59 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 60 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 61 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 62 | -f Dockerfile.client . |
| 63 | |
| 64 | docker-push: |
| 65 | docker push ${CORE_IMAGENAME} |
| 66 | docker push ${CLIENT_IMAGENAME} |
| 67 | |
| 68 | # Create a virtualenv and install all the libraries |
Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -0700 | [diff] [blame] | 69 | venv-xos: |
Zack Williams | 9a76635 | 2019-04-09 18:08:05 -0700 | [diff] [blame^] | 70 | virtualenv $@;\ |
| 71 | source ./$@/bin/activate ; set -u ;\ |
| 72 | pip install -r requirements.txt nose2 mock requests_mock;\ |
| 73 | pip install -e lib/xos-util ;\ |
| 74 | pip install -e lib/xos-config ;\ |
| 75 | pip install -e lib/xos-genx ;\ |
| 76 | pip install -e lib/xos-kafka ;\ |
| 77 | pip install -e lib/xos-api ;\ |
| 78 | pip install -e lib/xos-synchronizer ;\ |
| 79 | pip install -e lib/xos-migrate |
Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -0700 | [diff] [blame] | 80 | |
| 81 | # tests |
Zack Williams | 9a76635 | 2019-04-09 18:08:05 -0700 | [diff] [blame^] | 82 | test: lib-test unit-test migration-test core-xproto-test |
Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -0700 | [diff] [blame] | 83 | |
| 84 | lib-test: |
| 85 | for lib in $(XOS_LIBRARIES); do pushd $$lib; tox; popd; done |
| 86 | |
Zack Williams | 9a76635 | 2019-04-09 18:08:05 -0700 | [diff] [blame^] | 87 | unit-test: |
| 88 | tox |
Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -0700 | [diff] [blame] | 89 | |
| 90 | migration-test: venv-xos |
| 91 | source ./venv-xos/bin/activate ; set -u ;\ |
Zack Williams | 9a76635 | 2019-04-09 18:08:05 -0700 | [diff] [blame^] | 92 | xos-migrate --xos-dir . -s core --check |
Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -0700 | [diff] [blame] | 93 | |
Scott Baker | be2a517 | 2019-04-10 18:02:50 -0700 | [diff] [blame] | 94 | create-migrations: venv-xos |
| 95 | source ./venv-xos/bin/activate ; set -u ;\ |
| 96 | xos-migrate --xos-dir . -s core -v |
| 97 | |
Scott Baker | 08d1040 | 2019-04-08 16:19:59 -0700 | [diff] [blame] | 98 | core-xproto-test: venv-xos |
| 99 | source ./venv-xos/bin/activate ; set -u ;\ |
Zack Williams | 9a76635 | 2019-04-09 18:08:05 -0700 | [diff] [blame^] | 100 | xosgenx xos/core/models/core.xproto --lint --strict |
Scott Baker | 08d1040 | 2019-04-08 16:19:59 -0700 | [diff] [blame] | 101 | |
Zack Williams | 70a67e7 | 2019-03-08 12:38:51 -0700 | [diff] [blame] | 102 | clean: |
| 103 | find . -name '*.pyc' | xargs rm -f |
| 104 | find . -name '__pycache__' | xargs rm -rf |
| 105 | rm -rf \ |
| 106 | .coverage \ |
| 107 | coverage.xml \ |
| 108 | nose2-results.xml \ |
| 109 | venv-xos \ |
| 110 | lib/*/.tox \ |
| 111 | lib/*/build \ |
| 112 | lib/*/dist \ |
| 113 | lib/*/*.egg-info \ |
| 114 | lib/*/.coverage \ |
| 115 | lib/*/coverage.xml \ |
| 116 | lib/*/*results.xml \ |
| 117 | lib/*/*/VERSION \ |
| 118 | lib/xos-genx/xos-genx-tests/out/* \ |
| 119 | lib/xos-util/tests/test_version.py |
| 120 | |