Scott Baker | ed938b8 | 2019-12-10 09:27:53 -0800 | [diff] [blame^] | 1 | # Copyright 2019-present 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 | |
| 16 | # set default shell |
| 17 | SHELL = bash -e -o pipefail |
| 18 | |
| 19 | # Variables |
| 20 | VERSION ?= $(shell cat ../../VERSION) |
| 21 | |
| 22 | VOLTHA_PROTOS_VERSION ?= v2.1.2 |
| 23 | |
| 24 | DOCKER_LABEL_VCS_DIRTY = false |
| 25 | ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 26 | DOCKER_LABEL_VCS_DIRTY = true |
| 27 | endif |
| 28 | ## Docker related |
| 29 | DOCKER_EXTRA_ARGS ?= |
| 30 | DOCKER_REGISTRY ?= |
| 31 | DOCKER_REPOSITORY ?= |
| 32 | DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true) |
| 33 | IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-kafka-dump |
| 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 | --build-arg VOLTHA_PROTOS_VERSION="${VOLTHA_PROTOS_VERSION}" |
| 50 | |
| 51 | # This should to be the first and default target in this Makefile |
| 52 | help: |
| 53 | @echo "Usage: make [<target>]" |
| 54 | @echo "where available targets are:" |
| 55 | @echo |
| 56 | @echo "build : Build the docker images." |
| 57 | @echo " - If this is the first time you are building, choose 'make build' option." |
| 58 | @echo "clean : Remove files created by the build and tests" |
| 59 | @echo "distclean : Remove venv directory" |
| 60 | @echo "docker-push : Push the docker images to an external repository" |
| 61 | @echo "lint-dockerfile : Perform static analysis on Dockerfiles" |
| 62 | @echo "lint : Shorthand for lint-dockerfile" |
| 63 | @echo |
| 64 | |
| 65 | ## Docker targets |
| 66 | |
| 67 | build: docker-build |
| 68 | |
| 69 | docker-build: voltha-kafka-dump |
| 70 | |
| 71 | voltha-kafka-dump: |
| 72 | docker build $(DOCKER_BUILD_ARGS) -t ${IMAGENAME}:${DOCKER_TAG} -t ${IMAGENAME}:latest -f Dockerfile . |
| 73 | |
| 74 | docker-push: |
| 75 | docker push ${IMAGENAME}:${DOCKER_TAG} |
| 76 | |
| 77 | ## lint and unit tests |
| 78 | |
| 79 | PATH:=$(GOPATH)/bin:$(PATH) |
| 80 | HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint) |
| 81 | lint-dockerfile: |
| 82 | ifeq (,$(shell PATH=$(GOPATH):$(PATH) which hadolint)) |
| 83 | mkdir -p $(GOPATH)/bin |
| 84 | curl -o $(GOPATH)/bin/hadolint -sNSL https://github.com/hadolint/hadolint/releases/download/v1.17.1/hadolint-$(shell uname -s)-$(shell uname -m) |
| 85 | chmod 755 $(GOPATH)/bin/hadolint |
| 86 | endif |
| 87 | @echo "Running Dockerfile lint check ..." |
| 88 | @hadolint $$(find . -name "Dockerfile") |
| 89 | @echo "Dockerfile lint check OK" |
| 90 | |
| 91 | lint: lint-dockerfile |
| 92 | |
| 93 | # end file |