blob: 08299be64cabcef9b5992f337ad5f41bb0c38354 [file] [log] [blame]
Zack Williams70a67e72019-03-08 12:38:51 -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.
14
15# Makefile for testing and developing XOS
16
17# set default shell
18SHELL = bash -e -o pipefail
19
20# Variables
Zack Williams9a766352019-04-09 18:08:05 -070021VERSION ?= $(shell cat ./VERSION)
22CORE_NAME ?= xos-core
23CLIENT_NAME ?= xos-client
Zack Williams70a67e72019-03-08 12:38:51 -070024
Zack Williams9a766352019-04-09 18:08:05 -070025## Testing related
26XOS_LIBRARIES := $(wildcard lib/*)
27
28## Docker related
29DOCKER_REGISTRY ?=
30DOCKER_REPOSITORY ?=
31DOCKER_BUILD_ARGS ?=
32DOCKER_TAG ?= ${VERSION}
33CORE_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CORE_NAME}:${DOCKER_TAG}
34CLIENT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CLIENT_NAME}:${DOCKER_TAG}
35
36## Docker labels. Only set ref and commit date if committed
37DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
38DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
39DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
40DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
41
42# Targets
43all: test
44
45## Docker targets
46docker-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
64docker-push:
65 docker push ${CORE_IMAGENAME}
66 docker push ${CLIENT_IMAGENAME}
67
68# Create a virtualenv and install all the libraries
Zack Williams70a67e72019-03-08 12:38:51 -070069venv-xos:
Zack Williams9a766352019-04-09 18:08:05 -070070 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 Williams70a67e72019-03-08 12:38:51 -070080
81# tests
Zack Williams9a766352019-04-09 18:08:05 -070082test: lib-test unit-test migration-test core-xproto-test
Zack Williams70a67e72019-03-08 12:38:51 -070083
84lib-test:
85 for lib in $(XOS_LIBRARIES); do pushd $$lib; tox; popd; done
86
Zack Williams9a766352019-04-09 18:08:05 -070087unit-test:
88 tox
Zack Williams70a67e72019-03-08 12:38:51 -070089
90migration-test: venv-xos
91 source ./venv-xos/bin/activate ; set -u ;\
Zack Williams9a766352019-04-09 18:08:05 -070092 xos-migrate --xos-dir . -s core --check
Zack Williams70a67e72019-03-08 12:38:51 -070093
Scott Bakerbe2a5172019-04-10 18:02:50 -070094create-migrations: venv-xos
95 source ./venv-xos/bin/activate ; set -u ;\
96 xos-migrate --xos-dir . -s core -v
97
Scott Baker08d10402019-04-08 16:19:59 -070098core-xproto-test: venv-xos
99 source ./venv-xos/bin/activate ; set -u ;\
Zack Williams9a766352019-04-09 18:08:05 -0700100 xosgenx xos/core/models/core.xproto --lint --strict
Scott Baker08d10402019-04-08 16:19:59 -0700101
Zack Williams70a67e72019-03-08 12:38:51 -0700102clean:
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