blob: 15664eb18631532647191ac852dc1fa3cb0c7942 [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
Kent Hagerman1f99b662020-03-10 17:22:11 -040019VERSION ?= $(shell cat ./VERSION)
20GO_JUNIT_REPORT_VERSION ?= "0.9.1"
21GOCOVER_COBERTURA_VERSION ?= "v0.0.0-20180217150009-aaee18c8195c"
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +000022GOLANG_VERSION ?= "1.16.3"
Kent Hagerman1f99b662020-03-10 17:22:11 -040023GOLANGCI_LINT_VERSION ?= "1.23.6"
24HADOLINT_VERSION ?= "1.17.5"
25PROTOC_VERSION ?= "3.7.0"
26PROTOC_SHA256SUM ?= "a1b8ed22d6dc53c5b8680a6f1760a305b33ef471bece482e92728f00ba2a2969"
27PROTOC_GEN_GO_VERSION ?= "1.3.2"
Zack Williams88200d32020-04-02 13:36:41 -070028PROTOC_GEN_GRPC_GATEWAY_VERSION ?= "1.14.3"
Kent Hagermanda41d742020-01-07 14:55:56 -050029
30# Docker related
31DOCKER_LABEL_VCS_DIRTY = false
32ifneq ($(shell git status --porcelain | wc -l | sed -e 's/ //g'),0)
33 DOCKER_LABEL_VCS_DIRTY = true
Kent Hagermanda41d742020-01-07 14:55:56 -050034endif
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/
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +000040DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true)
Kent Hagermanc5487052020-01-28 15:36:19 -050041IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ci-tools
Kent Hagermanda41d742020-01-07 14:55:56 -050042
43## Docker labels. Only set ref and commit date if committed
Zack Williamsfd620942020-01-28 11:18:38 -070044DOCKER_LABEL_VCS_URL = $(shell git remote get-url "$(shell git remote)" 2>/dev/null)
Kent Hagermanc5487052020-01-28 15:36:19 -050045DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
Zack Williamsfd620942020-01-28 11:18:38 -070046DOCKER_LABEL_BUILD_DATE = $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
Kent Hagermanc5487052020-01-28 15:36:19 -050047DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
Kent Hagermanda41d742020-01-07 14:55:56 -050048
49DOCKER_BUILD_ARGS ?= \
50 ${DOCKER_EXTRA_ARGS} \
51 --build-arg org_label_schema_version="${VERSION}" \
52 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
53 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
54 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
55 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
56 --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
57
58## runnable tool containers
Zack Williamsfd620942020-01-28 11:18:38 -070059HADOLINT = ${DOCKER} run --rm --user $$(id -u):$$(id -g) -v $$PWD:/app ${IMAGENAME}:${VERSION}-hadolint hadolint
Kent Hagermanda41d742020-01-07 14:55:56 -050060
Kent Hagermanc5487052020-01-28 15:36:19 -050061lint: docker-lint
Kent Hagermanda41d742020-01-07 14:55:56 -050062
63docker-lint: hadolint
64 @echo "Linting Dockerfiles..."
65 @${HADOLINT} $(shell ls docker/*.Dockerfile)
66 @echo "Dockerfiles linted OK"
67
68
69build: docker-build
70
Matteo Scandoloc333f522021-03-30 09:25:27 -070071docker-build: go-junit-report gocover-cobertura golang golangci-lint hadolint protoc python onos-config-loader
Kent Hagermanda41d742020-01-07 14:55:56 -050072
73go-junit-report:
Zack Williamsfd620942020-01-28 11:18:38 -070074 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +000075 --build-arg GOLANG_VERSION=${GOLANG_VERSION} \
Kent Hagermanda41d742020-01-07 14:55:56 -050076 --build-arg GO_JUNIT_REPORT_VERSION=${GO_JUNIT_REPORT_VERSION} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +000077 -t ${IMAGENAME}:${DOCKER_TAG}-go-junit-report \
Kent Hagermanda41d742020-01-07 14:55:56 -050078 -t ${IMAGENAME}:latest-go-junit-report \
79 -f docker/go-junit-report.Dockerfile .
80
81gocover-cobertura:
Zack Williamsfd620942020-01-28 11:18:38 -070082 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Matteo Scandolo5cb1cce2020-11-19 17:39:13 -080083 --build-arg GOLANG_VERSION=${GOLANG_VERSION} \
Kent Hagermanda41d742020-01-07 14:55:56 -050084 --build-arg GOCOVER_COBERTURA_VERSION=${GOCOVER_COBERTURA_VERSION} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +000085 -t ${IMAGENAME}:${DOCKER_TAG}-gocover-cobertura \
Kent Hagermanda41d742020-01-07 14:55:56 -050086 -t ${IMAGENAME}:latest-gocover-cobertura \
87 -f docker/gocover-cobertura.Dockerfile .
88
89golang:
Zack Williamsfd620942020-01-28 11:18:38 -070090 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -050091 --build-arg GOLANG_VERSION=${GOLANG_VERSION} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +000092 -t ${IMAGENAME}:${DOCKER_TAG}-golang \
Kent Hagermanda41d742020-01-07 14:55:56 -050093 -t ${IMAGENAME}:latest-golang \
94 -f docker/golang.Dockerfile .
95
Andrey Pozolotin49a35452020-08-14 22:14:51 +020096python:
97 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +000098 -t ${IMAGENAME}:${DOCKER_TAG}-python \
Andrey Pozolotin49a35452020-08-14 22:14:51 +020099 -t ${IMAGENAME}:latest-python \
100 -f docker/python.Dockerfile .
101
Kent Hagermanda41d742020-01-07 14:55:56 -0500102golangci-lint:
Zack Williamsfd620942020-01-28 11:18:38 -0700103 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -0500104 --build-arg GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +0000105 -t ${IMAGENAME}:${DOCKER_TAG}-golangci-lint \
Kent Hagermanda41d742020-01-07 14:55:56 -0500106 -t ${IMAGENAME}:latest-golangci-lint \
107 -f docker/golangci-lint.Dockerfile .
108
109hadolint:
Zack Williamsfd620942020-01-28 11:18:38 -0700110 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
Kent Hagermanda41d742020-01-07 14:55:56 -0500111 --build-arg HADOLINT_VERSION=${HADOLINT_VERSION} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +0000112 -t ${IMAGENAME}:${DOCKER_TAG}-hadolint \
Kent Hagermanda41d742020-01-07 14:55:56 -0500113 -t ${IMAGENAME}:latest-hadolint \
114 -f docker/hadolint.Dockerfile .
115
116protoc:
Zack Williamsfd620942020-01-28 11:18:38 -0700117 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +0000118 --build-arg GOLANG_VERSION=${GOLANG_VERSION} \
Kent Hagermanda41d742020-01-07 14:55:56 -0500119 --build-arg PROTOC_VERSION=${PROTOC_VERSION} \
120 --build-arg PROTOC_SHA256SUM=${PROTOC_SHA256SUM} \
121 --build-arg PROTOC_GEN_GO_VERSION=${PROTOC_GEN_GO_VERSION} \
Kent Hagerman1f99b662020-03-10 17:22:11 -0400122 --build-arg PROTOC_GEN_GRPC_GATEWAY_VERSION=${PROTOC_GEN_GRPC_GATEWAY_VERSION} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +0000123 -t ${IMAGENAME}:${DOCKER_TAG}-protoc \
Kent Hagermanda41d742020-01-07 14:55:56 -0500124 -t ${IMAGENAME}:latest-protoc \
125 -f docker/protoc.Dockerfile .
126
Matteo Scandolo9d34a0f2021-03-29 15:26:56 -0700127onos-config-loader:
128 ${DOCKER} build ${DOCKER_BUILD_ARGS} \
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +0000129 -t ${IMAGENAME}:${DOCKER_TAG}-onos-config-loader \
Matteo Scandolo9d34a0f2021-03-29 15:26:56 -0700130 -t ${IMAGENAME}:latest-onos-config-loader \
131 -f docker/onos-config-loader.Dockerfile .
132
Kent Hagermanda41d742020-01-07 14:55:56 -0500133docker-push:
134ifneq (false,$(DOCKER_LABEL_VCS_DIRTY))
135 @echo "Local repo is dirty. Refusing to push."
136 @exit 1
137endif
David K. Bainbridgee33a5bc2021-04-06 20:30:58 +0000138 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-go-junit-report
139 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-gocover-cobertura
140 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-golang
141 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-golangci-lint
142 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-hadolint
143 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-protoc
144 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-python
145 ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-onos-config-loader