Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
*: update build scripts
  • Loading branch information
abhinavdahiya committed Aug 14, 2018
commit ddeb140857b9c59216d0c55d8167d7e5a0bfe325
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.swp
bin/
.DS_Store
_output
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM openshift/origin-release:golang-1.10
FROM golang:1.10.3 AS build-env

COPY . /go/src/github.com/openshift/cluster-version-operator
RUN cd /go/src/github.com/openshift/cluster-version-operator && \
make
WORKDIR /go/src/github.com/openshift/cluster-version-operator
RUN ./hack/build-go.sh

FROM scratch
COPY --from=build-env /go/src/github.com/openshift/cluster-version-operator/_output/linux/amd64/cluster-version-operator /bin/cluster-version-operator

FROM centos:7
COPY --from=0 /go/src/github.com/openshift/cluster-version-operator/bin/cvo /usr/bin/
CMD /usr/bin/cvo
ENTRYPOINT ["/bin/cluster-version-operator"]
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

33 changes: 33 additions & 0 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -eu

REPO=github.com/openshift/cluster-version-operator
GOFLAGS=${GOFLAGS:-}
GLDFLAGS=${GLDFLAGS:-}

eval $(go env | grep -e "GOHOSTOS" -e "GOHOSTARCH")

GOOS=${GOOS:-${GOHOSTOS}}
GOARCH=${GOACH:-${GOHOSTARCH}}

# Go to the root of the repo
cd "$(git rev-parse --show-cdup)"

if [ -z ${VERSION+a} ]; then
echo "Using version from git..."
VERSION=$(git describe --abbrev=8 --dirty --always)
fi

GLDFLAGS+="-X ${REPO}/pkg/version.Raw=${VERSION}"

eval $(go env)

if [ -z ${BIN_PATH+a} ]; then
export BIN_PATH=_output/${GOOS}/${GOARCH}
fi

mkdir -p ${BIN_PATH}

echo "Building ${REPO} (${VERSION})"
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build ${GOFLAGS} -ldflags "${GLDFLAGS}" -o ${BIN_PATH}/cluster-version-operator ${REPO}/cmd/...
13 changes: 13 additions & 0 deletions hack/update-vendor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
#
# This script updates Go vendoring using dep.

set -euo pipefail

# Go to the root of the repo
cd "$(git rev-parse --show-cdup)"

# Run dep.
dep ensure

(cd hack && ./update-codegen.sh)
34 changes: 34 additions & 0 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/..

DIFFROOT="${SCRIPT_ROOT}/pkg"
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg"
_tmp="${SCRIPT_ROOT}/_tmp"

cleanup() {
rm -rf "${_tmp}"
}
trap "cleanup" EXIT SIGINT

cleanup

mkdir -p "${TMP_DIFFROOT}"
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"

"${SCRIPT_ROOT}/hack/update-codegen.sh"
echo "diffing ${DIFFROOT} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}"
if [[ $ret -eq 0 ]]
then
echo "${DIFFROOT} up to date."
else
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh"
exit 1
fi
51 changes: 51 additions & 0 deletions hack/verify-style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
#
# This script invokes tools that should be run prior to pushing
# a repo, such as linters. This is designed to prevent running
# CI on code that will have to be changed.

set -uo pipefail

if [[ ! $(which go) ]]; then
echo "go not found on PATH. To install:"
echo "https://golang.org/dl/"
exit 1
fi
if [[ ! $(which golint) ]]; then
echo "golint not found on PATH. To install:"
echo "go get -u github.com/golang/lint/golint"
exit 1
fi
if [[ ! $(which yamllint) ]]; then
echo "yamllint not found on PATH. To install:"
echo "https://github.com/adrienverge/yamllint"
exit 1
fi

rc=0
trap 'rc=$?' ERR

# Go to the root of the repo
cd "$(git rev-parse --show-cdup)"

GOFILES=$(find . -path ./vendor -prune -o -name '*.go' | grep -v vendor)
GOPKGS=$(go list ./... | grep -v '/vendor/' | grep -v '/generated/')

echo "Running gofmt..."
gofmt -s -d $GOFILES

echo "Running go vet..."
go vet $GOPKGS

echo "Running golint..."
golint -set_exit_status $GOPKGS

echo "Running yamllint..."
YAMLS=$(find . -path ./vendor -prune -o -name '*.yaml' | grep -v vendor)
yamllint -c hack/yamllint-config.yaml -s $YAMLS

echo "Running verify code-generators"
(cd hack && ./verify-codegen.sh)

echo "Done!"
exit ${rc}
31 changes: 31 additions & 0 deletions hack/yamllint-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

extends: default

rules:
braces:
level: warning
max-spaces-inside: 1
brackets:
level: warning
max-spaces-inside: 1
colons:
level: warning
commas:
level: warning
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
level: warning
hyphens:
level: warning
indentation:
level: warning
indent-sequences: consistent
line-length: disable
truthy: disable

ignore: |
# The following have yaml-syntax-breaking templating, but are covered
# by other yaml files in the unit tests.