Skip to content

Commit

Permalink
Update common files. (istio#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
geeknoid authored and istio-testing committed Aug 26, 2019
1 parent 954cb2b commit 5763321
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 61 deletions.
1 change: 0 additions & 1 deletion .commonfiles.sha

This file was deleted.

22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".

# Copyright 2019 Istio Authors
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,19 +22,18 @@
# allow optional per-repo overrides
-include Makefile.overrides.mk

RUN =

# Set the environment variable BUILD_WITH_CONTAINER to use a container
# to build the repo. The only dependencies in this mode are to have make and
# docker. If you'd rather build with a local tool chain instead, you'll need to
# figure out all the tools you need in your environment to make that work.
export BUILD_WITH_CONTAINER ?= 0

ifeq ($(BUILD_WITH_CONTAINER),1)
IMG = gcr.io/istio-testing/build-tools:2019-08-21T08-35-40
IMG = gcr.io/istio-testing/build-tools:2019-08-25T20-37-02
UID = $(shell id -u)
PWD = $(shell pwd)
GOBIN_SOURCE ?= $(GOPATH)/bin
export GOBIN ?= /work/out/bin
GOBIN ?= /work/out/bin

LOCAL_ARCH := $(shell uname -m)
ifeq ($(LOCAL_ARCH),x86_64)
Expand All @@ -46,23 +45,25 @@ GOARCH_LOCAL := arm
else
GOARCH_LOCAL := $(LOCAL_ARCH)
endif
export GOARCH ?= $(GOARCH_LOCAL)

GOARCH ?= $(GOARCH_LOCAL)

LOCAL_OS := $(shell uname)
ifeq ($(LOCAL_OS),Linux)
export GOOS_LOCAL = linux
GOOS_LOCAL = linux
else ifeq ($(LOCAL_OS),Darwin)
export GOOS_LOCAL = darwin
GOOS_LOCAL = darwin
else
$(error "This system's OS $(LOCAL_OS) isn't recognized/supported")
endif

export GOOS ?= $(GOOS_LOCAL)
GOOS ?= $(GOOS_LOCAL)

RUN = docker run -t -i --sig-proxy=true -u $(UID) --rm \
-e GOOS="$(GOOS)" \
-e GOARCH="$(GOARCH)" \
-e GOBIN="$(GOBIN)" \
-e BUILD_WITH_CONTAINER="$(BUILD_WITH_CONTAINER)" \
-v /etc/passwd:/etc/passwd:ro \
-v $(readlink /etc/localtime):/etc/localtime:ro \
$(CONTAINER_OPTIONS) \
Expand All @@ -73,6 +74,7 @@ RUN = docker run -t -i --sig-proxy=true -u $(UID) --rm \
-w /work $(IMG)
else
export GOBIN ?= ./out/bin
RUN =
endif

MAKE = $(RUN) make --no-print-directory -e -f Makefile.core.mk
Expand All @@ -82,3 +84,5 @@ MAKE = $(RUN) make --no-print-directory -e -f Makefile.core.mk

default:
@$(MAKE)

.PHONY: default
50 changes: 0 additions & 50 deletions Makefile.common.mk

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ generate-values: $(values_v1alpha2_pb_gos) $(values_v1alpha2_pb_docs) $(values_v
clean-values:
@rm -fr $(values_v1alpha2_pb_gos) $(values_v1alpha2_pb_docs) $(values_v1alpha2_pb_pythons)

include Makefile.common.mk
include common/Makefile.common.mk
1 change: 1 addition & 0 deletions common/.commonfiles.sha
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
924cf1256448b0869bf55646525e1439ec11f85c
60 changes: 60 additions & 0 deletions common/Makefile.common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".

# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FINDFILES=find . \( -path ./vendor -o -path ./.git \) -prune -o -type f
XARGS = xargs -0 -r

lint-dockerfiles:
@${FINDFILES} -name 'Dockerfile*' -print0 | ${XARGS} hadolint -c ./common/config/.hadolint.yml

lint-scripts:
@${FINDFILES} -name '*.sh' -print0 | ${XARGS} shellcheck

lint-yaml:
@${FINDFILES} \( -name '*.yml' -o -name '*.yaml' \) -print0 | ${XARGS} grep -L -e "{{" | xargs -r yamllint -c ./common/config/.yamllint.yml

lint-helm:
@${FINDFILES} -name 'Chart.yaml' -print0 | ${XARGS} -L 1 dirname | xargs -r helm lint --strict

lint-copyright-banner:
@${FINDFILES} \( -name '*.go' -o -name '*.cc' -o -name '*.h' -o -name '*.proto' -o -name '*.py' -o -name '*.sh' \) \( ! \( -name '*.gen.go' -o -name '*.pb.go' -o -name '*_pb2.py' \) \) -print0 |\
${XARGS} common/scripts/lint_copyright_banner.sh

lint-go:
@golangci-lint run -j 8 -c ./common/config/.golangci.yml

lint-python:
@${FINDFILES} -name '*.py' -print0 | ${XARGS} autopep8 --max-line-length 160 --exit-code -d

format-go:
@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | ${XARGS} goimports -w -local "istio.io"

format-python:
@${FINDFILES} -name '*.py' -print0 | ${XARGS} autopep8 --max-line-length 160 --aggressive --aggressive -i

update-common:
@git clone --depth 1 --single-branch --branch master https://github.com/istio/common-files
@cd common-files ; git rev-parse HEAD >files/common/.commonfiles.sha
@rm -fr common
@cp -r common-files/files/* .
@rm -fr common-files

.PHONY: lint-dockerfiles lint-scripts lint-yaml lint-copyright-banner lint-go lint-pyhton lint-helm format-go format-python update-common
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions common/scripts/gobuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
#
# Copyright Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script builds and version stamps the output

VERBOSE=${VERBOSE:-"0"}
V=""
if [[ "${VERBOSE}" == "1" ]];then
V="-x"
set -x
fi

SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

OUT=${1:?"output path"}
BUILDPATH=${2:?"path to build"}

set -e

BUILD_GOOS=${GOOS:-linux}
BUILD_GOARCH=${GOARCH:-amd64}
GOBINARY=${GOBINARY:-go}
BUILDINFO=${BUILDINFO:-""}
STATIC=${STATIC:-1}
LDFLAGS="-extldflags -static"
GOBUILDFLAGS=${GOBUILDFLAGS:-""}
# Split GOBUILDFLAGS by spaces into an array called GOBUILDFLAGS_ARRAY.
IFS=' ' read -r -a GOBUILDFLAGS_ARRAY <<< "$GOBUILDFLAGS"

GCFLAGS=${GCFLAGS:-}
export CGO_ENABLED=0

if [[ "${STATIC}" != "1" ]];then
LDFLAGS=""
fi

# gather buildinfo if not already provided
# For a release build BUILDINFO should be produced
# at the beginning of the build and used throughout
if [[ -z ${BUILDINFO} ]];then
BUILDINFO=$(mktemp)
"${SCRIPTPATH}/report_build_info.sh" > "${BUILDINFO}"
fi

# BUILD LD_EXTRAFLAGS
LD_EXTRAFLAGS=""
while read -r line; do
LD_EXTRAFLAGS="${LD_EXTRAFLAGS} -X ${line}"
done < "${BUILDINFO}"

time GOOS=${BUILD_GOOS} GOARCH=${BUILD_GOARCH} ${GOBINARY} build \
${V} "${GOBUILDFLAGS_ARRAY[@]}" ${GCFLAGS:+-gcflags "${GCFLAGS}"} \
-o "${OUT}" \
-ldflags "${LDFLAGS} ${LD_EXTRAFLAGS}" "${BUILDPATH}"
39 changes: 39 additions & 0 deletions common/scripts/lint_copyright_banner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".

# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

ec=0
for fn in "$@"; do
if ! grep -L -q -e "Apache License, Version 2" "${fn}"; then
echo "Missing license: ${fn}"
ec=1
fi

if ! grep -L -q -e "Copyright" "${fn}"; then
echo "Missing copyright: ${fn}"
ec=1
fi
done

exit $ec
54 changes: 54 additions & 0 deletions common/scripts/report_build_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if BUILD_GIT_REVISION=$(git rev-parse HEAD 2> /dev/null); then
if ! git diff-index --quiet HEAD; then
BUILD_GIT_REVISION=${BUILD_GIT_REVISION}"-dirty"
fi
else
BUILD_GIT_REVISION=unknown
fi

# Check for local changes
if git diff-index --quiet HEAD --; then
tree_status="Clean"
else
tree_status="Modified"
fi

# XXX This needs to be updated to accommodate tags added after building, rather than prior to builds
RELEASE_TAG=$(git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --exact-match 2> /dev/null || echo "")

# security wanted VERSION='unknown'
VERSION="${BUILD_GIT_REVISION}"
if [[ -n "${RELEASE_TAG}" ]]; then
VERSION="${RELEASE_TAG}"
elif [[ -n ${ISTIO_VERSION} ]]; then
VERSION="${ISTIO_VERSION}"
fi

DOCKER_HUB="docker.io/istio"
if [[ -n ${ISTIO_DOCKER_HUB} ]]; then
DOCKER_HUB="${ISTIO_DOCKER_HUB}"
fi

# used by common/scripts/gobuild.sh
echo "istio.io/pkg/version.buildVersion=${VERSION}"
echo "istio.io/pkg/version.buildGitRevision=${BUILD_GIT_REVISION}"
echo "istio.io/pkg/version.buildUser=$(whoami)"
echo "istio.io/pkg/version.buildHost=$(hostname -f)"
echo "istio.io/pkg/version.buildDockerHub=${DOCKER_HUB}"
echo "istio.io/pkg/version.buildStatus=${tree_status}"

0 comments on commit 5763321

Please sign in to comment.