blob: 37bb9b625a170852991e122b4db429ba6ac994a1 [file] [log] [blame]
Scott Baker81739502019-10-14 16:53:10 -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)
32PONSIMONU_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-onu
33
34## Docker labels. Only set ref and commit date if committed
35DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
36DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
37DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
38DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
39
40DOCKER_BUILD_ARGS ?= \
41 ${DOCKER_EXTRA_ARGS} \
42 --build-arg org_label_schema_version="${VERSION}" \
43 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
44 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
45 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
46 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
47 --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
48
49DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
50 --build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \
51 --build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
52
53.PHONY: local-protos local-pyvoltha
54
55# This should to be the first and default target in this Makefile
56help:
57 @echo "Usage: make [<target>]"
58 @echo "where available targets are:"
59 @echo
60 @echo "build : Build the docker images."
61 @echo " - If this is the first time you are building, choose 'make build' option."
62 @echo "adapter_ponsim_onu : Build the ponsim onu adapter docker image"
63 @echo "venv : Build local Python virtualenv"
64 @echo "clean : Remove files created by the build and tests"
65 @echo "distclean : Remove venv directory"
66 @echo "docker-push : Push the docker images to an external repository"
67 @echo "lint-dockerfile : Perform static analysis on Dockerfiles"
68 @echo "lint : Shorthand for lint-style & lint-sanity"
69 @echo "test : Generate reports for all go tests"
70 @echo
71
72## Local Development Helpers
73local-protos:
74 @mkdir -p local_imports
75ifdef LOCAL_PROTOS
76 rm -rf local_imports/voltha-protos
77 mkdir -p local_imports/voltha-protos/dist
78 cp ../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
79endif
80
81local-pyvoltha:
82 @mkdir -p local_imports
83ifdef LOCAL_PYVOLTHA
84 rm -rf local_imports/pyvoltha
85 mkdir -p local_imports/pyvoltha/dist
86 cp ../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
87endif
88
89## Python venv dev environment
90
91VENVDIR := venv
92
93venv: distclean local-protos local-pyvoltha
94 virtualenv ${VENVDIR};\
95 source ./${VENVDIR}/bin/activate ; set -u ;\
96 rm -f ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
97 pip install -r requirements.txt
98ifdef LOCAL_PYVOLTHA
99 source ./${VENVDIR}/bin/activate ; set -u ;\
100 pip install local_imports/pyvoltha/dist/*.tar.gz
101endif
102ifdef LOCAL_PROTOS
103 source ./${VENVDIR}/bin/activate ; set -u ;\
104 pip install local_imports/voltha-protos/dist/*.tar.gz
105endif
106
107## Docker targets
108
109build: docker-build
110
111docker-build: adapter_ponsim_onu
112
113adapter_ponsim_onu: local-protos local-pyvoltha
114 docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${PONSIMONU_IMAGENAME}:${DOCKER_TAG} -t ${PONSIMONU_IMAGENAME}:latest -f docker/Dockerfile.adapter_ponsim_onu .
115
116docker-push:
117 docker push ${PONSIMONU_IMAGENAME}:${DOCKER_TAG}
118
119## lint and unit tests
120
121PATH:=$(GOPATH)/bin:$(PATH)
122HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint)
123lint-dockerfile:
124ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint))
125 mkdir -p $(GOPATH)/bin
126 curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m)
127 chmod 755 $(GOPATH)/bin/hadolint
128endif
129 @echo "Running Dockerfile lint check ..."
130 @hadolint $$(find . -name "Dockerfile.*")
131 @echo "Dockerfile lint check OK"
132
133lint: lint-dockerfile
134
135test:
136 @ echo "Executing unit tests w/tox"
137 tox
138
139clean:
140 rm -rf local_imports
141 find . -name '*.pyc' | xargs rm -f
142
143distclean: clean
144 rm -rf ${VENVDIR}
145
146# end file