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" |
Zack Williams | 88200d3 | 2020-04-02 13:36:41 -0700 | [diff] [blame] | 22 | GOLANG_VERSION ?= "1.13.9" |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 23 | GOLANGCI_LINT_VERSION ?= "1.23.6" |
| 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" |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 29 | |
| 30 | # Docker related |
| 31 | DOCKER_LABEL_VCS_DIRTY = false |
| 32 | ifneq ($(shell git status --porcelain | wc -l | sed -e 's/ //g'),0) |
| 33 | DOCKER_LABEL_VCS_DIRTY = true |
| 34 | VERSION = latest |
| 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/ |
| 41 | IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ci-tools |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 42 | |
| 43 | ## Docker labels. Only set ref and commit date if committed |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 44 | 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] | 45 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 46 | 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] | 47 | 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] | 48 | |
| 49 | DOCKER_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 Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 59 | 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] | 60 | |
Kent Hagerman | c548705 | 2020-01-28 15:36:19 -0500 | [diff] [blame] | 61 | lint: docker-lint |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 62 | |
| 63 | docker-lint: hadolint |
| 64 | @echo "Linting Dockerfiles..." |
| 65 | @${HADOLINT} $(shell ls docker/*.Dockerfile) |
| 66 | @echo "Dockerfiles linted OK" |
| 67 | |
| 68 | |
| 69 | build: docker-build |
| 70 | |
Andrey Pozolotin | 49a3545 | 2020-08-14 22:14:51 +0200 | [diff] [blame^] | 71 | docker-build: go-junit-report gocover-cobertura golang golangci-lint hadolint protoc python |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 72 | |
| 73 | go-junit-report: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 74 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 75 | --build-arg GO_JUNIT_REPORT_VERSION=${GO_JUNIT_REPORT_VERSION} \ |
| 76 | -t ${IMAGENAME}:${VERSION}-go-junit-report \ |
| 77 | -t ${IMAGENAME}:latest-go-junit-report \ |
| 78 | -f docker/go-junit-report.Dockerfile . |
| 79 | |
| 80 | gocover-cobertura: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 81 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 82 | --build-arg GOCOVER_COBERTURA_VERSION=${GOCOVER_COBERTURA_VERSION} \ |
| 83 | -t ${IMAGENAME}:${VERSION}-gocover-cobertura \ |
| 84 | -t ${IMAGENAME}:latest-gocover-cobertura \ |
| 85 | -f docker/gocover-cobertura.Dockerfile . |
| 86 | |
| 87 | golang: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 88 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 89 | --build-arg GOLANG_VERSION=${GOLANG_VERSION} \ |
| 90 | -t ${IMAGENAME}:${VERSION}-golang \ |
| 91 | -t ${IMAGENAME}:latest-golang \ |
| 92 | -f docker/golang.Dockerfile . |
| 93 | |
Andrey Pozolotin | 49a3545 | 2020-08-14 22:14:51 +0200 | [diff] [blame^] | 94 | python: |
| 95 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
| 96 | -t ${IMAGENAME}:${VERSION}-python \ |
| 97 | -t ${IMAGENAME}:latest-python \ |
| 98 | -f docker/python.Dockerfile . |
| 99 | |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 100 | golangci-lint: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 101 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 102 | --build-arg GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} \ |
| 103 | -t ${IMAGENAME}:${VERSION}-golangci-lint \ |
| 104 | -t ${IMAGENAME}:latest-golangci-lint \ |
| 105 | -f docker/golangci-lint.Dockerfile . |
| 106 | |
| 107 | hadolint: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 108 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 109 | --build-arg HADOLINT_VERSION=${HADOLINT_VERSION} \ |
| 110 | -t ${IMAGENAME}:${VERSION}-hadolint \ |
| 111 | -t ${IMAGENAME}:latest-hadolint \ |
| 112 | -f docker/hadolint.Dockerfile . |
| 113 | |
| 114 | protoc: |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 115 | ${DOCKER} build ${DOCKER_BUILD_ARGS} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 116 | --build-arg PROTOC_VERSION=${PROTOC_VERSION} \ |
| 117 | --build-arg PROTOC_SHA256SUM=${PROTOC_SHA256SUM} \ |
| 118 | --build-arg PROTOC_GEN_GO_VERSION=${PROTOC_GEN_GO_VERSION} \ |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 119 | --build-arg PROTOC_GEN_GRPC_GATEWAY_VERSION=${PROTOC_GEN_GRPC_GATEWAY_VERSION} \ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 120 | -t ${IMAGENAME}:${VERSION}-protoc \ |
| 121 | -t ${IMAGENAME}:latest-protoc \ |
| 122 | -f docker/protoc.Dockerfile . |
| 123 | |
| 124 | docker-push: |
| 125 | ifneq (false,$(DOCKER_LABEL_VCS_DIRTY)) |
| 126 | @echo "Local repo is dirty. Refusing to push." |
| 127 | @exit 1 |
| 128 | endif |
Zack Williams | fd62094 | 2020-01-28 11:18:38 -0700 | [diff] [blame] | 129 | ${DOCKER} push ${IMAGENAME}:${VERSION}-go-junit-report |
| 130 | ${DOCKER} push ${IMAGENAME}:${VERSION}-gocover-cobertura |
| 131 | ${DOCKER} push ${IMAGENAME}:${VERSION}-golang |
| 132 | ${DOCKER} push ${IMAGENAME}:${VERSION}-golangci-lint |
| 133 | ${DOCKER} push ${IMAGENAME}:${VERSION}-hadolint |
| 134 | ${DOCKER} push ${IMAGENAME}:${VERSION}-protoc |
Andrey Pozolotin | 49a3545 | 2020-08-14 22:14:51 +0200 | [diff] [blame^] | 135 | ${DOCKER} push ${IMAGENAME}:${VERSION}-python |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 136 | |