blob: 22c15314955189bf5642d6a2eac2347577db5717 [file] [log] [blame]
Zack Williamsfc85ade2019-03-11 11:05:47 -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# Configure shell
16SHELL = bash -e -o pipefail
17
18# Variables
19VERSION ?= $(shell cat ./VERSION)
20SERVICE_NAME ?= $(notdir $(abspath .))
21
22## Docker related
23DOCKER_REGISTRY ?=
24DOCKER_REPOSITORY ?=
25DOCKER_BUILD_ARGS ?=
26DOCKER_TAG ?= ${VERSION}
27DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${SERVICE_NAME}:${DOCKER_TAG}
28
29## Docker labels. Only set ref and commit date if committed
30DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
31DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
32DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
33DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
34
35## Migration related - paths are relative to the xos subdirectory within this repo
36XOS_DIR ?= "../../../xos"
37SERVICES_DIR ?= "../.."
38
39all: test
40
41docker-build:
42 docker build $(DOCKER_BUILD_ARGS) \
43 -t ${DOCKER_IMAGENAME} \
44 --build-arg org_label_schema_version="${VERSION}" \
45 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
46 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
47 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
48 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
49 -f Dockerfile.synchronizer .
50
51docker-push:
52 docker push ${DOCKER_IMAGENAME}
53
54test: test-unit test-migration
55
56test-unit:
57 tox
58
59venv-service:
60 virtualenv $@;\
61 source ./$@/bin/activate ; set -u ;\
62 pip install -r requirements.txt xosmigrate~=3.0.1
63
64create-migration: venv-service
65 source ./venv-service/bin/activate; set -u;\
66 cd xos; xos-migrate --xos-dir ${XOS_DIR} --services-dir ${SERVICES_DIR} -s ${SERVICE_NAME}
67
68test-migration: venv-service
69 source ./venv-service/bin/activate; set -u;\
70 cd xos; xos-migrate --xos-dir ${XOS_DIR} --services-dir ${SERVICES_DIR} -s ${SERVICE_NAME} --check
71
72clean:
73 find . -name '*.pyc' | xargs rm -f
74 rm -rf \
75 .tox \
76 venv-service \
77 xos/.coverage \
78 xos/coverage.xml \
79 xos/nose2-results.xml