blob: d727746ae3b9b050a12dc81407a24c9774665869 [file] [log] [blame]
Kent Hagermanda41d742020-01-07 14:55:56 -05001# Copyright 2020-present Open Networking Foundation
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# set default shell options
16SHELL = bash -e -o pipefail
17
18## Variables
19VERSION ?= $(shell cat ./VERSION)
20GO_JUNIT_REPORT_VERSION ?= "0.9.1"
21GOCOVER_COBERTURA_VERSION ?= "v0.0.0-20180217150009-aaee18c8195c"
22GOLANG_VERSION ?= "1.12.15"
23GOLANGCI_LINT_VERSION ?= "1.17.0"
24HADOLINT_VERSION ?= "1.17.4"
25PROTOC_VERSION ?= "3.7.0"
26PROTOC_SHA256SUM ?= "a1b8ed22d6dc53c5b8680a6f1760a305b33ef471bece482e92728f00ba2a2969"
27PROTOC_GEN_GO_VERSION ?= "1.3.1"
28
29# Docker related
30DOCKER_LABEL_VCS_DIRTY = false
31ifneq ($(shell git status --porcelain | wc -l | sed -e 's/ //g'),0)
32 DOCKER_LABEL_VCS_DIRTY = true
33 VERSION = latest
34endif
35
Zack Williamsfd620942020-01-28 11:18:38 -070036DOCKER ?= docker
Kent Hagermanda41d742020-01-07 14:55:56 -050037DOCKER_EXTRA_ARGS ?=
Kent Hagermanc5487052020-01-28 15:36:19 -050038DOCKER_REGISTRY ?=
39DOCKER_REPOSITORY ?= voltha/
40IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ci-tools
Kent Hagermanda41d742020-01-07 14:55:56 -050041
42## Docker labels. Only set ref and commit date if committed
Zack Williamsfd620942020-01-28 11:18:38 -070043DOCKER_LABEL_VCS_URL = $(shell git remote get-url "$(shell git remote)" 2>/dev/null)
Kent Hagermanc5487052020-01-28 15:36:19 -050044DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
Zack Williamsfd620942020-01-28 11:18:38 -070045DOCKER_LABEL_BUILD_DATE = $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
Kent Hagermanc5487052020-01-28 15:36:19 -050046DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
Kent Hagermanda41d742020-01-07 14:55:56 -050047
48DOCKER_BUILD_ARGS ?= \
49 ${DOCKER_EXTRA_ARGS} \
50 --build-arg org_label_schema_version="${VERSION}" \
51 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
52 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
53 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
54 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
55 --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
56
57## runnable tool containers
Zack Williamsfd620942020-01-28 11:18:38 -070058HADOLINT = ${DOCKER} run --rm --user $$(id -u):$$(id -g) -v $$PWD:/app ${IMAGENAME}:${VERSION}-hadolint hadolint
Kent Hagermanda41d742020-01-07 14:55:56 -050059
Kent Hagermanc5487052020-01-28 15:36:19 -050060lint: docker-lint
Kent Hagermanda41d742020-01-07 14:55:56 -050061
62docker-lint: hadolint
63 @echo "Linting Dockerfiles..."
64 @${HADOLINT} $(shell ls docker/*.Dockerfile)
65 @echo "Dockerfiles linted OK"
66
67
68build: docker-build
69
70docker-build: go-junit-report gocover-cobertura golang golangci-lint hadolint protoc
71
72go-junit-report:
Zack Williamsfd620942020-01-28 11:18:38 -070073 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -050074 --build-arg GO_JUNIT_REPORT_VERSION=${GO_JUNIT_REPORT_VERSION} \
75 -t ${IMAGENAME}:${VERSION}-go-junit-report \
76 -t ${IMAGENAME}:latest-go-junit-report \
77 -f docker/go-junit-report.Dockerfile .
78
79gocover-cobertura:
Zack Williamsfd620942020-01-28 11:18:38 -070080 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -050081 --build-arg GOCOVER_COBERTURA_VERSION=${GOCOVER_COBERTURA_VERSION} \
82 -t ${IMAGENAME}:${VERSION}-gocover-cobertura \
83 -t ${IMAGENAME}:latest-gocover-cobertura \
84 -f docker/gocover-cobertura.Dockerfile .
85
86golang:
Zack Williamsfd620942020-01-28 11:18:38 -070087 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -050088 --build-arg GOLANG_VERSION=${GOLANG_VERSION} \
89 -t ${IMAGENAME}:${VERSION}-golang \
90 -t ${IMAGENAME}:latest-golang \
91 -f docker/golang.Dockerfile .
92
93golangci-lint:
Zack Williamsfd620942020-01-28 11:18:38 -070094 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -050095 --build-arg GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} \
96 -t ${IMAGENAME}:${VERSION}-golangci-lint \
97 -t ${IMAGENAME}:latest-golangci-lint \
98 -f docker/golangci-lint.Dockerfile .
99
100hadolint:
Zack Williamsfd620942020-01-28 11:18:38 -0700101 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -0500102 --build-arg HADOLINT_VERSION=${HADOLINT_VERSION} \
103 -t ${IMAGENAME}:${VERSION}-hadolint \
104 -t ${IMAGENAME}:latest-hadolint \
105 -f docker/hadolint.Dockerfile .
106
107protoc:
Zack Williamsfd620942020-01-28 11:18:38 -0700108 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -0500109 --build-arg PROTOC_VERSION=${PROTOC_VERSION} \
110 --build-arg PROTOC_SHA256SUM=${PROTOC_SHA256SUM} \
111 --build-arg PROTOC_GEN_GO_VERSION=${PROTOC_GEN_GO_VERSION} \
112 -t ${IMAGENAME}:${VERSION}-protoc \
113 -t ${IMAGENAME}:latest-protoc \
114 -f docker/protoc.Dockerfile .
115
116docker-push:
117ifneq (false,$(DOCKER_LABEL_VCS_DIRTY))
118 @echo "Local repo is dirty. Refusing to push."
119 @exit 1
120endif
Zack Williamsfd620942020-01-28 11:18:38 -0700121 ${DOCKER} push ${IMAGENAME}:${VERSION}-go-junit-report
122 ${DOCKER} push ${IMAGENAME}:${VERSION}-gocover-cobertura
123 ${DOCKER} push ${IMAGENAME}:${VERSION}-golang
124 ${DOCKER} push ${IMAGENAME}:${VERSION}-golangci-lint
125 ${DOCKER} push ${IMAGENAME}:${VERSION}-hadolint
126 ${DOCKER} push ${IMAGENAME}:${VERSION}-protoc
Kent Hagermanda41d742020-01-07 14:55:56 -0500127