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 |
| 19 | VERSION ?= $(shell cat ./VERSION) |
| 20 | GO_JUNIT_REPORT_VERSION ?= "0.9.1" |
| 21 | GOCOVER_COBERTURA_VERSION ?= "v0.0.0-20180217150009-aaee18c8195c" |
| 22 | GOLANG_VERSION ?= "1.12.15" |
| 23 | GOLANGCI_LINT_VERSION ?= "1.17.0" |
| 24 | HADOLINT_VERSION ?= "1.17.4" |
| 25 | PROTOC_VERSION ?= "3.7.0" |
| 26 | PROTOC_SHA256SUM ?= "a1b8ed22d6dc53c5b8680a6f1760a305b33ef471bece482e92728f00ba2a2969" |
| 27 | PROTOC_GEN_GO_VERSION ?= "1.3.1" |
| 28 | |
| 29 | # Docker related |
| 30 | DOCKER_LABEL_VCS_DIRTY = false |
| 31 | ifneq ($(shell git status --porcelain | wc -l | sed -e 's/ //g'),0) |
| 32 | DOCKER_LABEL_VCS_DIRTY = true |
| 33 | VERSION = latest |
| 34 | endif |
| 35 | |
| 36 | DOCKER_EXTRA_ARGS ?= |
| 37 | DOCKER_REGISTRY ?= voltha |
| 38 | DOCKER_REPOSITORY ?= voltha-ci-tools |
| 39 | IMAGENAME = ${DOCKER_REGISTRY}/${DOCKER_REPOSITORY} |
| 40 | |
| 41 | ## Docker labels. Only set ref and commit date if committed |
| 42 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url "$(shell git remote)" 2>/dev/null) |
| 43 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 44 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 45 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 46 | |
| 47 | DOCKER_BUILD_ARGS ?= \ |
| 48 | ${DOCKER_EXTRA_ARGS} \ |
| 49 | --build-arg org_label_schema_version="${VERSION}" \ |
| 50 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 51 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 52 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 53 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 54 | --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}" |
| 55 | |
| 56 | ## runnable tool containers |
| 57 | HADOLINT = docker run --rm --user $$(id -u):$$(id -g) -v $$PWD:/app ${IMAGENAME}:${VERSION}-hadolint hadolint |
| 58 | |
| 59 | lint: docker-lint |
| 60 | |
| 61 | docker-lint: hadolint |
| 62 | @echo "Linting Dockerfiles..." |
| 63 | @${HADOLINT} $(shell ls docker/*.Dockerfile) |
| 64 | @echo "Dockerfiles linted OK" |
| 65 | |
| 66 | |
| 67 | build: docker-build |
| 68 | |
| 69 | docker-build: go-junit-report gocover-cobertura golang golangci-lint hadolint protoc |
| 70 | |
| 71 | go-junit-report: |
| 72 | docker build ${DOCKER_BUILD_ARGS} \ |
| 73 | --build-arg GO_JUNIT_REPORT_VERSION=${GO_JUNIT_REPORT_VERSION} \ |
| 74 | -t ${IMAGENAME}:${VERSION}-go-junit-report \ |
| 75 | -t ${IMAGENAME}:latest-go-junit-report \ |
| 76 | -f docker/go-junit-report.Dockerfile . |
| 77 | |
| 78 | gocover-cobertura: |
| 79 | docker build ${DOCKER_BUILD_ARGS} \ |
| 80 | --build-arg GOCOVER_COBERTURA_VERSION=${GOCOVER_COBERTURA_VERSION} \ |
| 81 | -t ${IMAGENAME}:${VERSION}-gocover-cobertura \ |
| 82 | -t ${IMAGENAME}:latest-gocover-cobertura \ |
| 83 | -f docker/gocover-cobertura.Dockerfile . |
| 84 | |
| 85 | golang: |
| 86 | docker build ${DOCKER_BUILD_ARGS} \ |
| 87 | --build-arg GOLANG_VERSION=${GOLANG_VERSION} \ |
| 88 | -t ${IMAGENAME}:${VERSION}-golang \ |
| 89 | -t ${IMAGENAME}:latest-golang \ |
| 90 | -f docker/golang.Dockerfile . |
| 91 | |
| 92 | golangci-lint: |
| 93 | docker build ${DOCKER_BUILD_ARGS} \ |
| 94 | --build-arg GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} \ |
| 95 | -t ${IMAGENAME}:${VERSION}-golangci-lint \ |
| 96 | -t ${IMAGENAME}:latest-golangci-lint \ |
| 97 | -f docker/golangci-lint.Dockerfile . |
| 98 | |
| 99 | hadolint: |
| 100 | docker build ${DOCKER_BUILD_ARGS} \ |
| 101 | --build-arg HADOLINT_VERSION=${HADOLINT_VERSION} \ |
| 102 | -t ${IMAGENAME}:${VERSION}-hadolint \ |
| 103 | -t ${IMAGENAME}:latest-hadolint \ |
| 104 | -f docker/hadolint.Dockerfile . |
| 105 | |
| 106 | protoc: |
| 107 | docker build ${DOCKER_BUILD_ARGS} \ |
| 108 | --build-arg PROTOC_VERSION=${PROTOC_VERSION} \ |
| 109 | --build-arg PROTOC_SHA256SUM=${PROTOC_SHA256SUM} \ |
| 110 | --build-arg PROTOC_GEN_GO_VERSION=${PROTOC_GEN_GO_VERSION} \ |
| 111 | -t ${IMAGENAME}:${VERSION}-protoc \ |
| 112 | -t ${IMAGENAME}:latest-protoc \ |
| 113 | -f docker/protoc.Dockerfile . |
| 114 | |
| 115 | docker-push: |
| 116 | ifneq (false,$(DOCKER_LABEL_VCS_DIRTY)) |
| 117 | @echo "Local repo is dirty. Refusing to push." |
| 118 | @exit 1 |
| 119 | endif |
| 120 | docker push ${IMAGENAME}:${VERSION}-go-junit-report |
| 121 | docker push ${IMAGENAME}:${VERSION}-gocover-cobertura |
| 122 | docker push ${IMAGENAME}:${VERSION}-golang |
| 123 | docker push ${IMAGENAME}:${VERSION}-golangci-lint |
| 124 | docker push ${IMAGENAME}:${VERSION}-hadolint |
| 125 | docker push ${IMAGENAME}:${VERSION}-protoc |
| 126 | |