Scott Baker | 12f1ef8 | 2019-10-14 13:06:14 -0700 | [diff] [blame] | 1 | # |
| 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 |
| 18 | SHELL = bash -e -o pipefail |
| 19 | |
| 20 | # Variables |
| 21 | VERSION ?= $(shell cat ./VERSION) |
| 22 | |
| 23 | DOCKER_LABEL_VCS_DIRTY = false |
| 24 | ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 25 | DOCKER_LABEL_VCS_DIRTY = true |
| 26 | endif |
| 27 | ## Docker related |
| 28 | DOCKER_EXTRA_ARGS ?= |
| 29 | DOCKER_REGISTRY ?= |
| 30 | DOCKER_REPOSITORY ?= |
| 31 | DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true) |
| 32 | PONSIMOLT_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-adapter-ponsim-olt |
Andrea Campanella | 652db2e | 2019-12-17 15:29:53 -0800 | [diff] [blame] | 33 | TYPE ?= minimal |
Scott Baker | 12f1ef8 | 2019-10-14 13:06:14 -0700 | [diff] [blame] | 34 | |
| 35 | ## Docker labels. Only set ref and commit date if committed |
| 36 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 37 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 38 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 39 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 40 | |
| 41 | DOCKER_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 | |
| 50 | DOCKER_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 |
| 57 | help: |
| 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 |
| 74 | local-protos: |
| 75 | @mkdir -p local_imports |
| 76 | ifdef 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/ |
| 80 | endif |
| 81 | |
| 82 | local-pyvoltha: |
| 83 | @mkdir -p local_imports |
| 84 | ifdef 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/ |
| 88 | endif |
| 89 | |
| 90 | ## Python venv dev environment |
| 91 | |
| 92 | VENVDIR := venv |
| 93 | |
| 94 | venv: 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 |
| 99 | ifdef LOCAL_PYVOLTHA |
| 100 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 101 | pip install local_imports/pyvoltha/dist/*.tar.gz |
| 102 | endif |
| 103 | ifdef LOCAL_PROTOS |
| 104 | source ./${VENVDIR}/bin/activate ; set -u ;\ |
| 105 | pip install local_imports/voltha-protos/dist/*.tar.gz |
| 106 | endif |
| 107 | |
| 108 | ## Docker targets |
| 109 | |
| 110 | build: docker-build |
| 111 | |
| 112 | docker-build: adapter_ponsim_olt |
| 113 | |
| 114 | adapter_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 | |
| 117 | docker-push: |
| 118 | docker push ${PONSIMOLT_IMAGENAME}:${DOCKER_TAG} |
| 119 | |
Andrea Campanella | 652db2e | 2019-12-17 15:29:53 -0800 | [diff] [blame] | 120 | docker-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 Baker | 12f1ef8 | 2019-10-14 13:06:14 -0700 | [diff] [blame] | 124 | ## lint and unit tests |
| 125 | |
| 126 | PATH:=$(GOPATH)/bin:$(PATH) |
| 127 | HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint) |
| 128 | lint-dockerfile: |
| 129 | ifeq (,$(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 |
| 133 | endif |
| 134 | @echo "Running Dockerfile lint check ..." |
| 135 | @hadolint $$(find . -name "Dockerfile.*") |
| 136 | @echo "Dockerfile lint check OK" |
| 137 | |
| 138 | lint: lint-dockerfile |
| 139 | |
| 140 | test: |
| 141 | @ echo "Executing unit tests w/tox" |
| 142 | tox |
| 143 | |
| 144 | clean: |
| 145 | rm -rf local_imports |
| 146 | find . -name '*.pyc' | xargs rm -f |
| 147 | |
| 148 | distclean: clean |
| 149 | rm -rf ${VENVDIR} |
| 150 | |
| 151 | # end file |