blob: 1376fbe1b25078b0bc8b20a5c61232afaf616f13 [file] [log] [blame]
Zack Williams9731cdc2019-11-22 15:42:30 -07001# Copyright 2016 the original author or authors.
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# set default shell
16SHELL = bash -e -o pipefail
17
18# Variables
19VERSION ?= $(shell cat ./VERSION)
20
21DOCKER_LABEL_VCS_DIRTY = false
22ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
23 DOCKER_LABEL_VCS_DIRTY = true
24endif
25
26## Docker related
27DOCKER_EXTRA_ARGS ?=
28DOCKER_REGISTRY ?=
29DOCKER_REPOSITORY ?=
30DOCKER_TAG ?= $(VERSION)$(shell [[ $(DOCKER_LABEL_VCS_DIRTY) == "true" ]] && echo "-dirty" || true)
31IMAGENAME := $(DOCKER_REGISTRY)$(DOCKER_REPOSITORY)voltha-ofagent:$(DOCKER_TAG)
32
33## Docker labels. Only set ref and commit date if committed
34DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
35DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
36DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
37DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
38
39DOCKER_BUILD_ARGS ?= \
40 $(DOCKER_EXTRA_ARGS) \
41 --build-arg org_label_schema_version="$(VERSION)" \
42 --build-arg org_label_schema_vcs_url="$(DOCKER_LABEL_VCS_URL)" \
43 --build-arg org_label_schema_vcs_ref="$(DOCKER_LABEL_VCS_REF)" \
44 --build-arg org_label_schema_build_date="$(DOCKER_LABEL_BUILD_DATE)" \
45 --build-arg org_opencord_vcs_commit_date="$(DOCKER_LABEL_COMMIT_DATE)" \
46 --build-arg org_opencord_vcs_dirty="$(DOCKER_LABEL_VCS_DIRTY)"
47
48DOCKER_BUILD_ARGS_LOCAL ?= $(DOCKER_BUILD_ARGS) \
49 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
50 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS)
51
52.PHONY: rw_core ro_core local-protos local-pyvoltha
53
54# This should to be the first and default target in this Makefile
55help:
56 @echo "Usage: make [<target>]"
57 @echo "where available targets are:"
58 @echo
59 @echo "docker-build : Build the docker images."
60 @echo "docker-push : Push the docker images to an external repository"
61 @echo "venv : Build local Python virtualenv"
62 @echo "clean : Remove files created by the build and tests"
63 @echo "distclean : Remove venv directory"
64 @echo "lint : Shorthand for lint-style & lint-sanity"
65 @echo "test : Generate reports for all go tests"
66 @echo
67
68local-protos:
69 mkdir -p local_imports
70ifdef LOCAL_PROTOS
71 mkdir -p local_imports/voltha-protos/dist
72 cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
73endif
74
75local-pyvoltha:
76 mkdir -p local_imports
77ifdef LOCAL_PYVOLTHA
78 mkdir -p local_imports/pyvoltha/dist
79 cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
80endif
81
82## lint and unit tests
83
84VENVDIR := venv-ofagent
85
86$(VENVDIR):
87 virtualenv-2.7 $@;\
88 source ./$@/bin/activate ; set -u ;\
89 pip install -r requirements.txt
90
91lint: lint-dockerfile
92
93test:
94 tox
95
96## Docker targets
97lint-dockerfile:
98 @echo "Running Dockerfile lint check ..."
99 @hadolint $$(find . -name "Dockerfile")
100 @echo "Dockerfile lint check OK"
101
102docker-build: local-protos local-pyvoltha
103 docker build $(DOCKER_BUILD_ARGS) \
104 -t $(IMAGENAME) \
105 --build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
106 --build-arg LOCAL_PROTOS=$(LOCAL_PROTOS) \
107 --build-arg org_label_schema_version="$(VERSION)" \
108 --build-arg org_label_schema_vcs_url="$(DOCKER_LABEL_VCS_URL)" \
109 --build-arg org_label_schema_vcs_ref="$(DOCKER_LABEL_VCS_REF)" \
110 --build-arg org_label_schema_build_date="$(DOCKER_LABEL_BUILD_DATE)" \
111 --build-arg org_opencord_vcs_commit_date="$(DOCKER_LABEL_COMMIT_DATE)" \
112 -f Dockerfile .
113
114docker-push:
115 docker push ${IMAGENAME}
116
117# cleanup
118clean:
119 rm -rf python/local_imports
120
121clean-all: clean
122 rm -rf $(VENVDIR)