blob: 95ff9bc08ee0078ca4bb2b31a944004cbc27cafb [file] [log] [blame]
Scott Bakered938b82019-12-10 09:27:53 -08001# 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
17SHELL = bash -e -o pipefail
18
19# Variables
20VERSION ?= $(shell cat ../../VERSION)
21
22VOLTHA_PROTOS_VERSION ?= v2.1.2
23
24DOCKER_LABEL_VCS_DIRTY = false
25ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
26 DOCKER_LABEL_VCS_DIRTY = true
27endif
28## Docker related
29DOCKER_EXTRA_ARGS ?=
30DOCKER_REGISTRY ?=
31DOCKER_REPOSITORY ?=
32DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true)
33IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-kafka-dump
34
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 --build-arg VOLTHA_PROTOS_VERSION="${VOLTHA_PROTOS_VERSION}"
50
51# This should to be the first and default target in this Makefile
52help:
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
67build: docker-build
68
69docker-build: voltha-kafka-dump
70
71voltha-kafka-dump:
72 docker build $(DOCKER_BUILD_ARGS) -t ${IMAGENAME}:${DOCKER_TAG} -t ${IMAGENAME}:latest -f Dockerfile .
73
74docker-push:
75 docker push ${IMAGENAME}:${DOCKER_TAG}
76
77## lint and unit tests
78
79PATH:=$(GOPATH)/bin:$(PATH)
80HADOLINT=$(shell PATH=$(GOPATH):$(PATH) which hadolint)
81lint-dockerfile:
82ifeq (,$(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
86endif
87 @echo "Running Dockerfile lint check ..."
88 @hadolint $$(find . -name "Dockerfile")
89 @echo "Dockerfile lint check OK"
90
91lint: lint-dockerfile
92
93# end file