blob: 59fafcd930fabb2b494b62cdf3f63401746b5cc1 [file] [log] [blame]
Scott Baker12f1ef82019-10-14 13:06:14 -07001#
2# Copyright 2016 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# set default shell
18SHELL = bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat ./VERSION)
22
23DOCKER_LABEL_VCS_DIRTY = false
24ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
25 DOCKER_LABEL_VCS_DIRTY = true
26endif
27## Docker related
28DOCKER_EXTRA_ARGS ?=
29DOCKER_REGISTRY ?=
30DOCKER_REPOSITORY ?=
31DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true)
32PONSIMOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-olt
Andrea Campanella652db2e2019-12-17 15:29:53 -080033TYPE ?= minimal
Scott Baker12f1ef82019-10-14 13:06:14 -070034
35## Docker labels. Only set ref and commit date if committed
36DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
37DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
38DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
39DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
40
41DOCKER_BUILD_ARGS ?= \
42 ${DOCKER_EXTRA_ARGS} \
43 --build-arg org_label_schema_version="${VERSION}" \
44 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
45 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
46 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
47 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
48 --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
49
50DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
51 --build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \
52 --build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
53
54.PHONY: local-protos local-pyvoltha
55
56# This should to be the first and default target in this Makefile
57help:
58 @echo "Usage: make [<target>]"
59 @echo "where available targets are:"
60 @echo
61 @echo "build : Build the docker images."
62 @echo " - If this is the first time you are building, choose 'make build' option."
63 @echo "adapter_ponsim_olt : Build the ponsim olt adapter docker image"
64 @echo "venv : Build local Python virtualenv"
65 @echo "clean : Remove files created by the build and tests"
66 @echo "distclean : Remove venv directory"
67 @echo "docker-push : Push the docker images to an external repository"
68 @echo "lint-dockerfile : Perform static analysis on Dockerfiles"
69 @echo "lint : Shorthand for lint-style & lint-sanity"
70 @echo "test : Generate reports for all go tests"
71 @echo
72
73## Local Development Helpers
74local-protos:
75 @mkdir -p local_imports
76ifdef LOCAL_PROTOS
77 rm -rf local_imports/voltha-protos
78 mkdir -p local_imports/voltha-protos/dist
79 cp ../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
80endif
81
82local-pyvoltha:
83 @mkdir -p local_imports
84ifdef LOCAL_PYVOLTHA
85 rm -rf local_imports/pyvoltha
86 mkdir -p local_imports/pyvoltha/dist
87 cp ../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
88endif
89
90## Python venv dev environment
91
92VENVDIR := venv
93
94venv: distclean local-protos local-pyvoltha
95 virtualenv ${VENVDIR};\
96 source ./${VENVDIR}/bin/activate ; set -u ;\
97 rm -f ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
98 pip install -r requirements.txt
99ifdef LOCAL_PYVOLTHA
100 source ./${VENVDIR}/bin/activate ; set -u ;\
101 pip install local_imports/pyvoltha/dist/*.tar.gz
102endif
103ifdef LOCAL_PROTOS
104 source ./${VENVDIR}/bin/activate ; set -u ;\
105 pip install local_imports/voltha-protos/dist/*.tar.gz
106endif
107
108## Docker targets
109
110build: docker-build
111
112docker-build: adapter_ponsim_olt
113
114adapter_ponsim_olt: local-protos local-pyvoltha
115 docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${PONSIMOLT_IMAGENAME}:${DOCKER_TAG} -t ${PONSIMOLT_IMAGENAME}:latest -f docker/Dockerfile.adapter_ponsim_olt .
116
117docker-push:
118 docker push ${PONSIMOLT_IMAGENAME}:${DOCKER_TAG}
119
Andrea Campanella652db2e2019-12-17 15:29:53 -0800120docker-kind-load:
121 @if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi
122 kind load docker-image ${PONSIMOLT_IMAGENAME}:${DOCKER_TAG} --name=voltha-$(TYPE) --nodes $(shell kubectl get nodes --template='{{range .items}}{{.metadata.name}},{{end}}' | sed 's/,$$//')
123
Scott Baker12f1ef82019-10-14 13:06:14 -0700124## lint and unit tests
125
126PATH:=$(GOPATH)/bin:$(PATH)
127HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint)
128lint-dockerfile:
129ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint))
130 mkdir -p $(GOPATH)/bin
131 curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m)
132 chmod 755 $(GOPATH)/bin/hadolint
133endif
134 @echo "Running Dockerfile lint check ..."
135 @hadolint $$(find . -name "Dockerfile.*")
136 @echo "Dockerfile lint check OK"
137
138lint: lint-dockerfile
139
140test:
141 @ echo "Executing unit tests w/tox"
142 tox
143
144clean:
145 rm -rf local_imports
146 find . -name '*.pyc' | xargs rm -f
147
148distclean: clean
149 rm -rf ${VENVDIR}
150
151# end file