Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 1 | # 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 |
| 16 | SHELL = bash -e -o pipefail |
| 17 | |
| 18 | ## Variables |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 19 | VERSION ?= $(shell cat ./VERSION) |
| 20 | GO_JUNIT_REPORT_VERSION ?= "0.9.1" |
| 21 | GOCOVER_COBERTURA_VERSION ?= "v0.0.0-20180217150009-aaee18c8195c" |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 22 | GOLANG_VERSION ?= "1.16.3" |
Elia Battiston | e4baada | 2022-03-09 12:16:19 +0100 | [diff] [blame] | 23 | GOLANGCI_LINT_VERSION ?= "1.44.2" |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 24 | HADOLINT_VERSION ?= "1.17.5" |
| 25 | PROTOC_VERSION ?= "3.7.0" |
| 26 | PROTOC_SHA256SUM ?= "a1b8ed22d6dc53c5b8680a6f1760a305b33ef471bece482e92728f00ba2a2969" |
| 27 | PROTOC_GEN_GO_VERSION ?= "1.3.2" |
Zack Williams | 88200d3 | 2020-04-02 13:36:41 -0700 | [diff] [blame] | 28 | PROTOC_GEN_GRPC_GATEWAY_VERSION ?= "1.14.3" |
Andrea Campanella | 271afae | 2021-04-28 14:17:22 +0200 | [diff] [blame] | 29 | PROTOC_GEN_CPP_VERSION ?= "1.31.1" |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 30 | |
| 31 | # Docker related |
| 32 | DOCKER_LABEL_VCS_DIRTY = false |
| 33 | ifneq ($(shell git status --porcelain | wc -l | sed -e 's/ //g'),0) |
| 34 | DOCKER_LABEL_VCS_DIRTY = true |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 35 | endif |
| 36 | |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 37 | DOCKER ?= docker |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 38 | DOCKER_EXTRA_ARGS ?= |
Kent Hagerman | c548705 | 2020-01-28 15:36:19 -0500 | [diff] [blame] | 39 | DOCKER_REGISTRY ?= |
| 40 | DOCKER_REPOSITORY ?= voltha/ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 41 | DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true) |
Kent Hagerman | c548705 | 2020-01-28 15:36:19 -0500 | [diff] [blame] | 42 | IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ci-tools |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 43 | |
| 44 | ## Docker labels. Only set ref and commit date if committed |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 45 | DOCKER_LABEL_VCS_URL = $(shell git remote get-url "$(shell git remote)" 2>/dev/null) |
Kent Hagerman | c548705 | 2020-01-28 15:36:19 -0500 | [diff] [blame] | 46 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 47 | DOCKER_LABEL_BUILD_DATE = $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
Kent Hagerman | c548705 | 2020-01-28 15:36:19 -0500 | [diff] [blame] | 48 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 49 | |
| 50 | DOCKER_BUILD_ARGS ?= \ |
| 51 | ${DOCKER_EXTRA_ARGS} \ |
| 52 | --build-arg org_label_schema_version="${VERSION}" \ |
| 53 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 54 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 55 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 56 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 57 | --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}" |
| 58 | |
| 59 | ## runnable tool containers |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 60 | HADOLINT = ${DOCKER} run --rm --user $$(id -u):$$(id -g) -v $$PWD:/app ${IMAGENAME}:${VERSION}-hadolint hadolint |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 61 | |
Kent Hagerman | c548705 | 2020-01-28 15:36:19 -0500 | [diff] [blame] | 62 | lint: docker-lint |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 63 | |
| 64 | docker-lint: hadolint |
| 65 | @echo "Linting Dockerfiles..." |
| 66 | @${HADOLINT} $(shell ls docker/*.Dockerfile) |
| 67 | @echo "Dockerfiles linted OK" |
| 68 | |
| 69 | |
| 70 | build: docker-build |
| 71 | |
Matteo Scandolo | c333f52 | 2021-03-30 09:25:27 -0700 | [diff] [blame] | 72 | docker-build: go-junit-report gocover-cobertura golang golangci-lint hadolint protoc python onos-config-loader |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 73 | |
| 74 | go-junit-report: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 75 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 76 | --build-arg GOLANG_VERSION=${GOLANG_VERSION} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 77 | --build-arg GO_JUNIT_REPORT_VERSION=${GO_JUNIT_REPORT_VERSION} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 78 | -t ${IMAGENAME}:${DOCKER_TAG}-go-junit-report \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 79 | -t ${IMAGENAME}:latest-go-junit-report \ |
| 80 | -f docker/go-junit-report.Dockerfile . |
| 81 | |
| 82 | gocover-cobertura: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 83 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Matteo Scandolo | 5cb1cce | 2020-11-19 17:39:13 -0800 | [diff] [blame] | 84 | --build-arg GOLANG_VERSION=${GOLANG_VERSION} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 85 | --build-arg GOCOVER_COBERTURA_VERSION=${GOCOVER_COBERTURA_VERSION} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 86 | -t ${IMAGENAME}:${DOCKER_TAG}-gocover-cobertura \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 87 | -t ${IMAGENAME}:latest-gocover-cobertura \ |
| 88 | -f docker/gocover-cobertura.Dockerfile . |
| 89 | |
| 90 | golang: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 91 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 92 | --build-arg GOLANG_VERSION=${GOLANG_VERSION} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 93 | -t ${IMAGENAME}:${DOCKER_TAG}-golang \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 94 | -t ${IMAGENAME}:latest-golang \ |
| 95 | -f docker/golang.Dockerfile . |
| 96 | |
Andrey Pozolotin | 49a3545 | 2020-08-14 22:14:51 +0200 | [diff] [blame] | 97 | python: |
| 98 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 99 | -t ${IMAGENAME}:${DOCKER_TAG}-python \ |
Andrey Pozolotin | 49a3545 | 2020-08-14 22:14:51 +0200 | [diff] [blame] | 100 | -t ${IMAGENAME}:latest-python \ |
| 101 | -f docker/python.Dockerfile . |
| 102 | |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 103 | golangci-lint: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 104 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 105 | --build-arg GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 106 | -t ${IMAGENAME}:${DOCKER_TAG}-golangci-lint \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 107 | -t ${IMAGENAME}:latest-golangci-lint \ |
| 108 | -f docker/golangci-lint.Dockerfile . |
| 109 | |
| 110 | hadolint: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 111 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 112 | --build-arg HADOLINT_VERSION=${HADOLINT_VERSION} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 113 | -t ${IMAGENAME}:${DOCKER_TAG}-hadolint \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 114 | -t ${IMAGENAME}:latest-hadolint \ |
| 115 | -f docker/hadolint.Dockerfile . |
| 116 | |
| 117 | protoc: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 118 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 119 | --build-arg GOLANG_VERSION=${GOLANG_VERSION} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 120 | --build-arg PROTOC_VERSION=${PROTOC_VERSION} \ |
| 121 | --build-arg PROTOC_SHA256SUM=${PROTOC_SHA256SUM} \ |
| 122 | --build-arg PROTOC_GEN_GO_VERSION=${PROTOC_GEN_GO_VERSION} \ |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 123 | --build-arg PROTOC_GEN_GRPC_GATEWAY_VERSION=${PROTOC_GEN_GRPC_GATEWAY_VERSION} \ |
Andrea Campanella | a13b2c5 | 2021-04-26 11:38:51 +0000 | [diff] [blame] | 124 | --build-arg PROTOC_GEN_CPP_VERSION=${PROTOC_GEN_CPP_VERSION} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 125 | -t ${IMAGENAME}:${DOCKER_TAG}-protoc \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 126 | -t ${IMAGENAME}:latest-protoc \ |
| 127 | -f docker/protoc.Dockerfile . |
| 128 | |
Matteo Scandolo | 9d34a0f | 2021-03-29 15:26:56 -0700 | [diff] [blame] | 129 | onos-config-loader: |
| 130 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 131 | -t ${IMAGENAME}:${DOCKER_TAG}-onos-config-loader \ |
Matteo Scandolo | 9d34a0f | 2021-03-29 15:26:56 -0700 | [diff] [blame] | 132 | -t ${IMAGENAME}:latest-onos-config-loader \ |
| 133 | -f docker/onos-config-loader.Dockerfile . |
| 134 | |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 135 | docker-push: |
| 136 | ifneq (false,$(DOCKER_LABEL_VCS_DIRTY)) |
| 137 | @echo "Local repo is dirty. Refusing to push." |
| 138 | @exit 1 |
| 139 | endif |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 140 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-go-junit-report |
| 141 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-gocover-cobertura |
| 142 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-golang |
| 143 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-golangci-lint |
| 144 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-hadolint |
| 145 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-protoc |
| 146 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-python |
| 147 | ${DOCKER} push ${IMAGENAME}:${DOCKER_TAG}-onos-config-loader |