Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glide, makefile, and circleCI #3

Merged
merged 17 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
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
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
jobs:
build:
working_directory: /go/src/github.com/envoyproxy/go-control-plane
docker:
- image: rshriram/envoy-go-build:956131ed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pin to a generic image?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the standard go image from circle CI does not have protoc and glide installed. So, i had to create this. I thought that once we land this, we can (a) try to reuse lyft/envoy-build (with some improvements), or push this as a standard build image to dockerhub.

steps:
- checkout
- run: make check
- run: make depend.install
- run: make compile
- run: make test
3 changes: 3 additions & 0 deletions .circleci/custom-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM circleci/golang:1.9
COPY ./install-deps.sh /tmp/
RUN /tmp/install-deps.sh
16 changes: 16 additions & 0 deletions .circleci/custom-image/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
VERSION=3.4.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we setting this version var here? It's not used anywhere. Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh.. I hardcoded it everywhere else.. good catch

# Make sure you grab the latest version
curl -OL https://github.com/google/protobuf/releases/download/v3.4.0/protoc-3.4.0-linux-x86_64.zip

# Unzip
unzip protoc-3.4.0-linux-x86_64.zip -d protoc3

# Move protoc to /usr/local/bin/
sudo mv protoc3/bin/* /usr/local/bin/

# Move protoc3/include to /usr/local/include/
sudo mv protoc3/include/* /usr/local/include/

# Install glide
curl https://glide.sh/get | sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/bazel-*
vendor
bin
build
.idea*
*.iml
*.bak
Expand Down
120 changes: 120 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
.DEFAULT_GOAL := compile

#------------------------------------------------------------------------------
# Variables
#------------------------------------------------------------------------------

SHELL := /bin/bash
BINDIR := bin
BUILDDIR := build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit -- indentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its GH doing the weird thing.. IT looks correct on the terminal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's tabs

DOCKERDIR := docker
RELEASEDIR := release
OUTPUT_NAME := envoyctl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be go-control-plane?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

envoyctl is so cool! :( .. Either way, I thought that this would change rapidly, when we start putting in CLIs in cmd/ folder.. We need one per CLI tool.

GOHOSTOS := $(shell go env GOHOSTOS)

ifndef GOOS
GOOS := $(GOHOSTOS)
endif

ifndef GOARCH
GOARCH := $(shell go env GOHOSTARCH)
endif

GOFILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GODIRS = $(shell go list -f '{{.Dir}}' ./... | grep -vFf <(go list -f '{{.Dir}}' ./vendor/...))
GOPKGS = $(shell go list ./... | grep -vFf <(go list ./vendor/...))

APP_VER := $(shell git describe --always 2> /dev/null || echo "unknown")

# linker flags to set build info variables
BUILD_SYM := github.com/envoyproxy/go-control-plane/pkg/version
LDFLAGS += -X $(BUILD_SYM).version=$(APP_VER)
LDFLAGS += -X $(BUILD_SYM).gitRevision=$(shell git rev-parse --short HEAD 2> /dev/null || echo unknown)
LDFLAGS += -X $(BUILD_SYM).branch=$(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo unknown)
LDFLAGS += -X $(BUILD_SYM).buildUser=$(shell whoami || echo nobody)@$(shell hostname -f || echo builder)
LDFLAGS += -X $(BUILD_SYM).buildDate=$(shell date +%Y-%m-%dT%H:%M:%S%:z)
LDFLAGS += -X $(BUILD_SYM).goVersion=$(word 3,$(shell go version))

.PHONY: compile
compile:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this target should be renamed build

@go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(OUTPUT_NAME)

.PHONY: proto
proto:
@go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
@protoc --go_out=plugins=grpc:pkg/ vendor/github.com/envoyproxy/data-plane-api/api/*.proto \
--proto_path=vendor/github.com/envoyproxy/data-plane-api \
--proto_path=vendor/github.com/googleapis/googleapis/
@protoc --go_out=plugins=grpc:pkg/ vendor/github.com/envoyproxy/data-plane-api/api/filter/*.proto \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right. When I run this command I get a file with imports like this

package envoy_api_v2_filter

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import envoy_api_v21 "api"
import envoy_api_v22 "api"
import envoy_api_v24 "api"

These should be github.com/envoyproxy/go-control-plane/pkg/envoy/api

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the same issue as golang/protobuf#63

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this @davecheney .. I think I will take this line out for now, since @kyessenov is generating protos using bazel (using same proto version as envoy repo), and our plan is to commit these protos into the repo, so that others can just import this library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--proto_path=vendor/github.com/envoyproxy/data-plane-api \
--proto_path=vendor/github.com/googleapis/googleapis/

clean:
@echo "--> cleaning compiled objects and binaries"
@go clean -tags netgo -i $(GOPKGS)
@rm -rf $(BINDIR)/*
@rm -rf $(BUILDDIR)/*
@rm -rf $(RELEASEDIR)/*

.PHONY: test
test:
@echo "--> running unit tests"
@go test -v $(GOPKGS)

.PHONY: check
check: format.check vet lint

format: tools.goimports
@echo "--> formatting code with 'goimports' tool"
@goimports -w -l $(GOFILES)

format.check: tools.goimports
@echo "--> checking code formatting with 'goimports' tool"
@goimports -l $(GOFILES) | sed -e "s/^/\?\t/" | tee >(test -z)

vet: tools.govet
@echo "--> checking code correctness with 'go vet' tool"
@go vet $(GOPKGS)

lint: tools.golint
@echo "--> checking code style with 'golint' tool"
@echo $(GODIRS) | xargs -n 1 golint

#------------------
#-- dependencies
#------------------
.PHONY: depend.update depend.install

depend.update:
@echo "--> updating dependencies from glide.yaml"
@glide update --strip-vendor

depend.install:
@echo "--> installing dependencies from glide.lock "
@glide install --strip-vendor

#---------------
#-- tools
#---------------
.PHONY: tools tools.goimports tools.golint tools.govet

tools: tools.goimports tools.golint tools.govet

tools.goimports:
@command -v goimports >/dev/null ; if [ $$? -ne 0 ]; then \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Go dependencies I think the existence check can be removed and go get -u should be used

echo "--> installing goimports"; \
go get golang.org/x/tools/cmd/goimports; \
fi

tools.govet:
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
echo "--> installing govet"; \
go get golang.org/x/tools/cmd/vet; \
fi

tools.golint:
@command -v golint >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing golint"; \
go get github.com/golang/lint/golint; \
fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an installer for Glide?

tools.glide:
	@command -v glide 1>/dev/null ; if [ $$? -ne 0 ]; then \
		echo "--> installing glide"; \
		curl https://glide.sh/get | sh; \
    fi

73 changes: 73 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package: github.com/envoyproxy/go-control-plane
import:
- package: golang.org/x/net
subpackages:
- context
- package: github.com/envoyproxy/data-plane-api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, not needed in glide

version: master
- package: github.com/googleapis/googleapis
version: 5c6df0cd18c6a429eab739fb711c27f6e1393366
- package: github.com/google/protobuf
version: 78cb804063716767966cdcd86c66500df342ad33
- package: github.com/golang/protobuf
version: ab9f9a6dab164b7d1246e0e688b0ab7b94d8553e
subpackages:
- jsonpb
- ptypes
testImport:
- package: github.com/stretchr/testify
subpackages:
- assert
- package: github.com/golang/mock
subpackages:
- gomock
- package: github.com/onsi/gomega
- package: gopkg.in/yaml.v2
version: master
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"

"github.com/envoyproxy/go-control-plane/pkg/version"
)

func main() {
fmt.Printf("Hello Envoy %s!\n", version.Build.Version)
}
66 changes: 66 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2017 Envoyproxy 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.
//
// Package version provides build time version information.
package version

import (
"time"
)

// Build variable exposes the build-time information
var Build BuildInfo

// BuildInfo provides build information and metadata.
// It is Populated by Makefile at build-time using -ldflags -X.
// Symbol names are reported by 'go tool nm <binary object>".
// Note that unless the cluster of instances is completely homogeneous, different instances can return
// different values.
type BuildInfo struct {
Version string `json:"version"`
GitRevision string `json:"revision"`
Branch string `json:"branch"`
BuildUser string `json:"user"`
BuildDate time.Time `json:"date"`
GoVersion string `json:"go"`
}

var (
version string
gitRevision string
branch string
buildUser string
buildDate string
goVersion string
)

// Unfortunately, it seems that struct fields cannot be assigned directly using ldflags, so we resort to setting
// package scope (local) variables and then assigning their corresponding external values at initialization
func init() {
if version == "" { // this is most likely running in a test...
Build.Version = "unknown"
Build.GitRevision = "unknown"
Build.Branch = "unknown"
Build.BuildUser = "unknown"
Build.BuildDate = time.Time{}
Build.GoVersion = "unknown"
} else {
Build.Version = version
Build.GitRevision = gitRevision
Build.Branch = branch
Build.BuildUser = buildUser
Build.BuildDate, _ = time.Parse(time.RFC3339, buildDate)
Build.GoVersion = goVersion
}
}