Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ IMAGE_PREFIX := quay.io/weaveworks
IMAGE_TAG := $(shell ./tools/image-tag)
GIT_REVISION := $(shell git rev-parse HEAD)
UPTODATE := .uptodate
GO_TEST_IMAGE := golang:1.12.1

# Building Docker images is now automated. The convention is every directory
# with a Dockerfile in it builds an image calls quay.io/weaveworks/<dirname>.
Expand Down Expand Up @@ -188,7 +189,7 @@ notification-eventmanager/$(UPTODATE): $(wildcard notification-eventmanager/migr
SUDO := $(shell docker info >/dev/null 2>&1 || echo "sudo -E")
BUILD_IN_CONTAINER := true
RM := --rm
GO_FLAGS := -ldflags "-extldflags \"-static\" -linkmode=external -s -w" -tags netgo -i
GO_FLAGS := -ldflags "-extldflags \"-static\" -s -w" -tags netgo -i
NETGO_CHECK = @strings $@ | grep cgo_stub\\\.go >/dev/null || { \
rm $@; \
echo "\nYour go standard library was built without the 'netgo' build tag."; \
Expand Down Expand Up @@ -272,13 +273,13 @@ $(CODECGEN_TARGETS): $(CODECGEN_EXE) $(call GET_CODECGEN_DEPS,vendor/github.com/
cd $(@D) && $(WITH_GO_HOST_ENV) $(shell pwd)/$(CODECGEN_EXE) -d $(CODECGEN_UID) -rt $(GO_BUILD_TAGS) -u -o $(@F) $(notdir $(call GET_CODECGEN_DEPS,$(@D)))

$(EXES): build/$(UPTODATE) $(PROTO_GOS)
go build $(GO_FLAGS) -o $@ ./$(@D)
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

%.pb.go: build/$(UPTODATE)
protoc -I ./vendor:./$(@D) --gogoslick_out=plugins=grpc:./$(@D) ./$(patsubst %.pb.go,%.proto,$@)

lint: build/$(UPTODATE)
lint: build/$(UPTODATE) $(PROTO_GOS) $(MOCK_GOS)
./tools/lint .

test: build/$(UPTODATE) $(PROTO_GOS) $(MOCK_GOS) $(CODECGEN_TARGETS)
Expand Down Expand Up @@ -320,7 +321,7 @@ notebooks-integration-test: $(NOTEBOOKS_UPTODATE)
-v $(shell pwd)/notebooks/db/migrations:/migrations \
--workdir /go/src/github.com/weaveworks/service/notebooks \
--link "$$DB_CONTAINER":configs-db.weave.local \
golang:1.9.2-stretch \
$(GO_TEST_IMAGE) \
/bin/bash -c "go test -tags integration -timeout 30s ./..."; \
status=$$?; \
test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \
Expand All @@ -333,7 +334,7 @@ users-integration-test: $(USERS_UPTODATE) $(PROTO_GOS) $(MOCK_GOS)
-v $(shell pwd)/users/db/migrations:/migrations \
--workdir /go/src/github.com/weaveworks/service/users \
--link "$$DB_CONTAINER":users-db.weave.local \
golang:1.9.2-stretch \
$(GO_TEST_IMAGE) \
/bin/bash -c "go test -tags integration -timeout 30s ./..."; \
status=$$?; \
test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \
Expand All @@ -345,7 +346,7 @@ pubsub-integration-test:
-v $(shell pwd):/go/src/github.com/weaveworks/service \
--net=host -p 127.0.0.1:1337:1337 \
--workdir /go/src/github.com/weaveworks/service/common/gcp/pubsub \
golang:1.9.2-stretch \
$(GO_TEST_IMAGE) \
/bin/bash -c "RUN_MANUAL_TEST=1 go test -tags integration -timeout 30s ./..."; \
status=$$?; \
test -n "$(CIRCLECI)" || docker rm -f "$$PUBSUB_EMU_CONTAINER"; \
Expand All @@ -357,7 +358,7 @@ kubectl-service-integration-test: kubectl-service/$(UPTODATE) kubectl-service/gr
-v $(shell pwd):/go/src/github.com/weaveworks/service \
--workdir /go/src/github.com/weaveworks/service/kubectl-service \
--link "$$SVC_CONTAINER":kubectl-service.weave.local \
golang:1.9.2-stretch \
$(GO_TEST_IMAGE) \
/bin/bash -c "go test -tags integration -timeout 30s ./..."; \
status=$$?; \
test -n "$(CIRCLECI)" || docker rm -f "$$SVC_CONTAINER"; \
Expand All @@ -369,7 +370,7 @@ gcp-service-integration-test: gcp-service/$(UPTODATE) gcp-service/grpc/gcp-servi
-v $(shell pwd):/go/src/github.com/weaveworks/service \
--workdir /go/src/github.com/weaveworks/service/gcp-service \
--link "$$SVC_CONTAINER":gcp-service.weave.local \
golang:1.9.2-stretch \
$(GO_TEST_IMAGE) \
/bin/bash -c "go test -tags integration -timeout 30s ./..."; \
status=$$?; \
test -n "$(CIRCLECI)" || docker rm -f "$$SVC_CONTAINER"; \
Expand Down
22 changes: 11 additions & 11 deletions billing-api/routes/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ func (z *zuoraStubInvoices) CreateInvoice(ctx context.Context, zuoraAccountNumbe

func createInvoice(status, fileURL string) zuora.Invoice {
return zuora.Invoice{
ID: "2c92c0955e0d9cb9015e0f8492c00ef5",
AccountName: "feisty-resonance-96",
AccountNumber: "Wbee8866756aee4702b5e4f9021a44a2",
InvoiceDate: "2017-08-23",
InvoiceNumber: "INV00000030",
DueDate: "2017-08-23",
InvoiceTargetDate: "2017-09-08",
Amount: 19.86,
Balance: 19.86,
ID: "2c92c0955e0d9cb9015e0f8492c00ef5",
AccountName: "feisty-resonance-96",
AccountNumber: "Wbee8866756aee4702b5e4f9021a44a2",
InvoiceDate: "2017-08-23",
InvoiceNumber: "INV00000030",
DueDate: "2017-08-23",
InvoiceTargetDate: "2017-09-08",
Amount: 19.86,
Balance: 19.86,
CreditBalanceAdjustmentAmount: 0,
Status: status,
Body: fileURL,
Status: status,
Body: fileURL,
InvoiceItems: []zuora.InvoiceItem{
{
ID: "2c92c0955e0d9cb9015e0f8492c40ef7",
Expand Down
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.10.8
FROM golang:1.12.1
RUN apt-get update && apt-get install -y \
python-pip \
python-requests \
Expand All @@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y \
libprotobuf-dev=3.0.0-9 && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN go clean -i net && \
go install -tags netgo std && \
CGO_ENABLED=0 go install -tags netgo std && \
go install -race -tags netgo std sync/atomic
RUN go get -tags netgo \
github.com/fzipp/gocyclo \
Expand Down
2 changes: 1 addition & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ echo "weave:*:::::::" >>/etc/shadow
echo "weave ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers

# Grant full access to paths where dependencies are typically installed:
chmod -R 777 /go/pkg
chmod -R 777 /go/pkg /usr/local/go/pkg

su weave -c "PATH=$PATH make -C $SRC_PATH BUILD_IN_CONTAINER=false $*"
2 changes: 1 addition & 1 deletion common/gcp/gke/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewKubeConfig(clusterName, endpoint, username, password, clusterCaCertifica
Name: clusterName,
Cluster: ClusterCfg{
CertificateAuthorityData: clusterCaCertificate,
Server: fmt.Sprintf("https://%v", endpoint),
Server: fmt.Sprintf("https://%v", endpoint),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion common/gcp/gke/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestCreateManuallyAndMarshalKubeConfig(t *testing.T) {
Name: "dev",
Cluster: gke.ClusterCfg{
CertificateAuthorityData: "foo",
Server: "https://192.168.0.1",
Server: "https://192.168.0.1",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion common/zuora/payments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestGetPaymentTransactionLog(t *testing.T) {
},
},
GatewayTransactionNumber: "",
Status: "Error",
Status: "Error",
}, payment)

txLog, err := client.GetPaymentTransactionLog(context.Background(), payment.ID)
Expand Down
6 changes: 3 additions & 3 deletions flux-api/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (s Server) MakeHandler(r *mux.Router) http.Handler {
transport.RegisterDaemonV11: s.registerV11,
transport.LogEvent: s.logEvent,
// UI routes
Status: s.status,
History: s.history,
Ping: s.ping,
Status: s.status,
History: s.history,
Ping: s.ping,
PostIntegrationsGithub: s.postIntegrationsGithub,
GetGithubRepos: s.getGithubRepos,
// Webhooks
Expand Down
2 changes: 1 addition & 1 deletion gcp-launcher-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func main() {
HTTPListenPort: cfg.port,
MetricsNamespace: common.PrometheusNamespace,
RegisterInstrumentation: true,
Log: logging.Logrus(log.StandardLogger()),
Log: logging.Logrus(log.StandardLogger()),
}
server, err := server.New(serverCfg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion gcp-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
GRPCListenPort: *grpcPort,
GRPCMiddleware: []googlegrpc.UnaryServerInterceptor{render.GRPCErrorInterceptor},
RegisterInstrumentation: true,
Log: logging.Logrus(log.StandardLogger()),
Log: logging.Logrus(log.StandardLogger()),
})
if err != nil {
log.Fatalf("Failed to create gcp-service's server: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion notebooks/db/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (d DB) Transaction(f func(DB) error) error {
if err != nil {
// Rollback error is ignored as we already have one in progress
if err2 := tx.Rollback(); err2 != nil {
log.Warn("transaction rollback: %v (ignored)", err2)
log.Warnf("transaction rollback: %v (ignored)", err2)
}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions notification-eventmanager/eventmanager/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (em *EventManager) notificationBatchToSendInput(batch []types.Notification)
for i, notif := range batch {
notifStr, err := notificationToString(notif)
if err != nil {
return nil, errors.Wrapf(err, "cannot marshal notification %s to string", notif)
return nil, errors.Wrapf(err, "cannot marshal notification %v to string", notif)
}
entry := &sqs.SendMessageBatchRequestEntry{
Id: aws.String(strconv.Itoa(i)),
Expand All @@ -114,7 +114,7 @@ func (em *EventManager) notificationBatchToSendInput(batch []types.Notification)
func notificationToString(n types.Notification) (string, error) {
raw, err := json.Marshal(n)
if err != nil {
return "", errors.Wrapf(err, "cannot marshal notification %s", n)
return "", errors.Wrapf(err, "cannot marshal notification %v", n)
}

return string(raw), nil
Expand Down
2 changes: 1 addition & 1 deletion notification-eventmanager/eventmanager/render/cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func PagerDutyFromAlert(wa types.WebhookAlert, etype, instanceName string) (json

msgRaw, err := json.Marshal(pdMsg)
if err != nil {
return nil, errors.Wrapf(err, "cannot marshal to json PagerDuty message: %s", pdMsg)
return nil, errors.Wrapf(err, "cannot marshal to json PagerDuty message: %v", pdMsg)
}

return msgRaw, nil
Expand Down
2 changes: 1 addition & 1 deletion notification-eventmanager/eventmanager/render/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func PagerDutyFromSlack(text, etype, instanceName, link, linkText string) (json.

msgRaw, err := json.Marshal(pdMsg)
if err != nil {
return nil, errors.Wrapf(err, "cannot marshal to json PagerDuty message: %s", pdMsg)
return nil, errors.Wrapf(err, "cannot marshal to json PagerDuty message: %v", pdMsg)
}

return msgRaw, nil
Expand Down
4 changes: 2 additions & 2 deletions notification-sender/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func (pds *PagerDutySender) Send(ctx context.Context, addr json.RawMessage, noti

var m types.PagerDutyMessage
if err := json.Unmarshal(notif.Data, &m); err != nil {
return errors.Wrapf(err, "cannot unmarshal PagerDuty data %s", notif.Data)
return errors.Wrapf(err, "cannot unmarshal PagerDuty data %v", notif.Data)
}

m.RoutingKey = key

b, err := json.Marshal(m)
if err != nil {
return errors.Wrapf(err, "cannot marshal PagerDuty message %s", m)
return errors.Wrapf(err, "cannot marshal PagerDuty message %v", m)
}

req, err := http.NewRequest("POST", endpoint, bytes.NewReader(b))
Expand Down
2 changes: 1 addition & 1 deletion tools/build/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11.1-stretch
FROM golang:1.12.1-stretch
RUN apt-get update && \
apt-get install -y \
curl \
Expand Down
36 changes: 26 additions & 10 deletions tools/lint
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ spell_check() {
}

lint_go() {
# This function is called on a whole directory containing Go files
local filename="$1"
local lint_result=0

Expand All @@ -73,7 +74,7 @@ lint_go() {
echo "${filename}: run gofmt -s -w ${filename}"
fi

go tool vet "${filename}" || lint_result=$?
go vet "${filename}" || lint_result=$?

# golint is completely optional. If you don't like it
# don't have it installed.
Expand Down Expand Up @@ -185,7 +186,7 @@ lint() {

case "$mimetype.$ext" in
text/x-shellscript.*) lint_sh "${filename}" || lint_result=1 ;;
*.go) lint_go "${filename}" || lint_result=1 ;;
*.go) ;; # done at directory level
*.tf) lint_tf "${filename}" || lint_result=1 ;;
*.md) lint_md "${filename}" || lint_result=1 ;;
*.py) lint_py "${filename}" || lint_result=1 ;;
Expand All @@ -208,7 +209,7 @@ lint_files() {
while read -r filename; do
lint "${filename}" || lint_result=1
done
exit $lint_result
return $lint_result
}

matches_any() {
Expand Down Expand Up @@ -239,18 +240,33 @@ filter_out() {
fi
}

list_files() {
lint_directory() {
local dirname="$1"
local lint_result=0
# This test is just checking if there are any Go files in the directory
if compgen -G "$dirname/*.go" >/dev/null; then
lint_go "${dirname}" || lint_result=1
fi
ls $dirname/* | filter_out "$LINT_IGNORE_FILE" | lint_files
return $lint_result
}

lint_directories() {
local lint_result=0
while read -r dirname; do
lint_directory "${dirname}" || lint_result=1
done
exit $lint_result
}

list_directories() {
if [ $# -gt 0 ]; then
find "$@" \( -name vendor -o -name .git \) -prune -o -type f
else
git ls-files --exclude-standard | grep -vE '(^|/)vendor/'
find "$@" \( -name vendor -o -name .git -o -name .cache -o -name .pkg \) -prune -o -type d
fi
}

if [ $# = 1 ] && [ -f "$1" ]; then
lint "$1"
elif [ -n "$PARALLEL" ]; then
list_files "$@" | filter_out "$LINT_IGNORE_FILE" | xargs -n1 -P16 "$0"
else
list_files "$@" | filter_out "$LINT_IGNORE_FILE" | lint_files
list_directories "$@" | lint_directories
fi
2 changes: 1 addition & 1 deletion users-sync/cmd/users-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func main() {
GRPCListenPort: *grpcPort,
GRPCMiddleware: []grpc.UnaryServerInterceptor{render.GRPCErrorInterceptor},
RegisterInstrumentation: true,
Log: logger,
Log: logger,
})
if err != nil {
logrus.Fatalf("Failed to create server: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion users/api/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func Test_CustomExternalIDOrganization_Validation(t *testing.T) {
user, otherOrg := getOrg(t)

for id, errMsg := range map[string]string{
"": "ID cannot be blank",
"": "ID cannot be blank",
"org with^/invalid&characters": "ID can only contain letters, numbers, hyphen, and underscore",
otherOrg.ExternalID: "ID is already taken",
} {
Expand Down
4 changes: 2 additions & 2 deletions users/client/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (a UserPermissionsMiddleware) Wrap(next http.Handler) http.Handler {

if MethodMatched && URIMatched {
if _, err := a.UsersClient.RequireOrgMemberPermissionTo(r.Context(), &users.RequireOrgMemberPermissionToRequest{
OrgID: &users.RequireOrgMemberPermissionToRequest_OrgExternalID{mux.Vars(r)["orgExternalID"]},
OrgID: &users.RequireOrgMemberPermissionToRequest_OrgExternalID{OrgExternalID: mux.Vars(r)["orgExternalID"]},
UserID: r.Header.Get(a.UserIDHeader),
PermissionID: p.PermissionID,
}); err != nil {
Expand All @@ -403,7 +403,7 @@ func (a ScopeCensorMiddleware) Wrap(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// If the user has no permission to view the token, we tell Scope to hide all the sensitive data for the request.
if _, err := a.UsersClient.RequireOrgMemberPermissionTo(r.Context(), &users.RequireOrgMemberPermissionToRequest{
OrgID: &users.RequireOrgMemberPermissionToRequest_OrgExternalID{mux.Vars(r)["orgExternalID"]},
OrgID: &users.RequireOrgMemberPermissionToRequest_OrgExternalID{OrgExternalID: mux.Vars(r)["orgExternalID"]},
UserID: r.Header.Get(a.UserIDHeader),
PermissionID: permission.ViewToken,
}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion users/cmd/users/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func main() {
GRPCListenPort: *grpcPort,
GRPCMiddleware: []grpc.UnaryServerInterceptor{render.GRPCErrorInterceptor},
RegisterInstrumentation: true,
Log: logging.Logrus(log.StandardLogger()),
Log: logging.Logrus(log.StandardLogger()),
})
if err != nil {
log.Fatalf("Failed to create server: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion users/marketing/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (c *Queue) OrganizationBillingConfigured(email string, orgExternalID string
c.Lock()
defer c.Unlock()
c.prospects = append(c.prospects, Prospect{
Email: email,
Email: email,
OrganizationBillingConfiguredExternalID: orgExternalID,
OrganizationBillingConfiguredName: orgName,
})
Expand Down