Scott Baker | 31c3c0a | 2019-04-02 11:22:41 -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 | # Configure shell |
| 16 | SHELL = bash -e -o pipefail |
| 17 | |
| 18 | # Variables |
| 19 | VERSION ?= $(shell cat ./VERSION) |
| 20 | SERVICE_NAME ?= $(notdir $(abspath .)) |
| 21 | SYNCHRONIZER_NAME ?= simpleexampleservice-synchronizer |
| 22 | |
| 23 | ## Docker related |
| 24 | DOCKER_REGISTRY ?= |
| 25 | DOCKER_REPOSITORY ?= |
| 26 | DOCKER_BUILD_ARGS ?= |
| 27 | DOCKER_TAG ?= ${VERSION} |
| 28 | DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${SYNCHRONIZER_NAME}:${DOCKER_TAG} |
| 29 | |
| 30 | ## Docker labels. Only set ref and commit date if committed |
| 31 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 32 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 33 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 34 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 35 | |
| 36 | ## Migration related - paths are relative to the xos subdirectory within this repo |
| 37 | XOS_DIR ?= "../../../xos" |
| 38 | SERVICES_DIR ?= "../.." |
| 39 | |
| 40 | all: test |
| 41 | |
| 42 | docker-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 | |
| 52 | docker-push: |
| 53 | docker push ${DOCKER_IMAGENAME} |
| 54 | |
Scott Baker | 417e6de | 2019-04-09 16:23:32 -0700 | [diff] [blame] | 55 | test: test-unit test-migration test-xproto |
Scott Baker | 31c3c0a | 2019-04-02 11:22:41 -0700 | [diff] [blame] | 56 | |
| 57 | test-unit: |
| 58 | tox |
| 59 | |
| 60 | # NOTE: Avoid #! on pip and xos-migrate due to line-length issue. |
| 61 | # See https://github.com/pypa/virtualenv/issues/596 |
| 62 | |
| 63 | venv-service: |
| 64 | virtualenv $@;\ |
| 65 | source ./$@/bin/activate ; set -u ;\ |
Matteo Scandolo | e70c782 | 2019-05-17 14:33:48 -0700 | [diff] [blame] | 66 | python venv-service/bin/pip install -r requirements.txt xosmigrate~=3.2.6 |
Scott Baker | 31c3c0a | 2019-04-02 11:22:41 -0700 | [diff] [blame] | 67 | |
| 68 | create-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} |
| 71 | |
| 72 | test-migration: venv-service |
| 73 | source ./venv-service/bin/activate; set -u;\ |
| 74 | cd xos; python ../venv-service/bin/xos-migrate --xos-dir ${XOS_DIR} --services-dir ${SERVICES_DIR} -s ${SERVICE_NAME} --check |
| 75 | |
Scott Baker | 417e6de | 2019-04-09 16:23:32 -0700 | [diff] [blame] | 76 | test-xproto: venv-service |
| 77 | source ./venv-service/bin/activate; set -u;\ |
| 78 | python venv-service/bin/xosgenx --lint --strict xos/synchronizer/models/simpleexampleservice.xproto |
| 79 | |
Scott Baker | 31c3c0a | 2019-04-02 11:22:41 -0700 | [diff] [blame] | 80 | clean: |
| 81 | find . -name '*.pyc' | xargs rm -f |
| 82 | rm -rf \ |
| 83 | .tox \ |
| 84 | venv-service \ |
| 85 | xos/.coverage \ |
| 86 | xos/coverage.xml \ |
| 87 | xos/nose2-results.xml |