blob: 82c84390859e991fe84008df55f5300a9d4b4820 [file] [log] [blame]
Scott Bakerb1671512019-04-01 19:16:54 -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 Scandoloa4a279a2019-03-14 15:56:22 -070014
Scott Bakerb1671512019-04-01 19:16:54 -070015# Configure shell
16SHELL = bash -e -o pipefail
Matteo Scandoloa4a279a2019-03-14 15:56:22 -070017
Scott Bakerb1671512019-04-01 19:16:54 -070018# Variables
19VERSION ?= $(shell cat ./VERSION)
20SERVICE_NAME ?= $(notdir $(abspath .))
21SYNCHRONIZER_NAME ?= rcord-synchronizer
Matteo Scandoloa4a279a2019-03-14 15:56:22 -070022
Scott Bakerb1671512019-04-01 19:16:54 -070023## Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${SYNCHRONIZER_NAME}:${DOCKER_TAG}
Matteo Scandoloa4a279a2019-03-14 15:56:22 -070029
Scott Bakerb1671512019-04-01 19:16:54 -070030## Docker labels. Only set ref and commit date if committed
31DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
32DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
33DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
34DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
Matteo Scandoloa4a279a2019-03-14 15:56:22 -070035
Scott Bakerb1671512019-04-01 19:16:54 -070036## Migration related - paths are relative to the xos subdirectory within this repo
37XOS_DIR ?= "../../../xos"
38SERVICES_DIR ?= "../.."
39
40all: test
41
42docker-build:
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.synchronizer .
51
52docker-push:
53 docker push ${DOCKER_IMAGENAME}
54
Scott Bakerfa330332019-04-09 15:43:11 -070055test: test-unit test-migration test-xproto
Scott Bakerb1671512019-04-01 19:16:54 -070056
57test-unit:
58 tox
59
60venv-service:
61 virtualenv $@;\
62 source ./$@/bin/activate ; set -u ;\
Matteo Scandolo43e17bd2019-05-17 14:32:53 -070063 pip install -r requirements.txt xosmigrate~=3.2.6
Scott Bakerb1671512019-04-01 19:16:54 -070064
65create-migration: venv-service
66 source ./venv-service/bin/activate; set -u;\
67 cd xos; xos-migrate --xos-dir ${XOS_DIR} --services-dir ${SERVICES_DIR} -s ${SERVICE_NAME}
68
69test-migration: venv-service
70 source ./venv-service/bin/activate; set -u;\
71 cd xos; xos-migrate --xos-dir ${XOS_DIR} --services-dir ${SERVICES_DIR} -s ${SERVICE_NAME} --check
72
Scott Bakerfa330332019-04-09 15:43:11 -070073test-xproto: venv-service
74 source ./venv-service/bin/activate; set -u;\
75 xosgenx --lint --strict xos/synchronizer/models/rcord.xproto
76
Scott Bakerb1671512019-04-01 19:16:54 -070077clean:
78 find . -name '*.pyc' | xargs rm -f
79 rm -rf \
80 .tox \
81 venv-service \
82 xos/.coverage \
83 xos/coverage.xml \
84 xos/nose2-results.xml