Skip to content

Commit

Permalink
Use bingo for tools (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <[email protected]>
  • Loading branch information
kakkoyun authored Nov 19, 2020
1 parent acb908d commit 03be030
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .bingo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# Ignore everything
*

# But not these files:
!.gitignore
!*.mod
!README.md
!Variables.mk
!variables.env

*tmp.mod
13 changes: 13 additions & 0 deletions .bingo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Project Development Dependencies.

This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo.

* Run `bingo get` to install all tools having each own module file in this directory.
* Run `bingo get <tool>` to install <tool> that have own module file in this directory.
* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $(<upper case tool name>) variable where <tool> is the .bingo/<tool>.mod.
* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies.

## Requirements

* Go 1.14+
42 changes: 42 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.3. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
GO ?= $(shell which go)

# Bellow generated variables ensure that every time a tool under each variable is invoked, the correct version
# will be used; reinstalling only if needed.
# For example for gojsontoyaml variable:
#
# In your main Makefile (for non array binaries):
#
#include .bingo/Variables.mk # Assuming -dir was set to .bingo .
#
#command: $(GOJSONTOYAML)
# @echo "Running gojsontoyaml"
# @$(GOJSONTOYAML) <flags/args..>
#
GOJSONTOYAML := $(GOBIN)/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c
$(GOJSONTOYAML): .bingo/gojsontoyaml.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c"
@cd .bingo && $(GO) build -mod=mod -modfile=gojsontoyaml.mod -o=$(GOBIN)/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c "github.com/brancz/gojsontoyaml"

JB := $(GOBIN)/jb-v0.4.0
$(JB): .bingo/jb.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/jb-v0.4.0"
@cd .bingo && $(GO) build -mod=mod -modfile=jb.mod -o=$(GOBIN)/jb-v0.4.0 "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb"

JSONNET := $(GOBIN)/jsonnet-v0.16.0
$(JSONNET): .bingo/jsonnet.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/jsonnet-v0.16.0"
@cd .bingo && $(GO) build -mod=mod -modfile=jsonnet.mod -o=$(GOBIN)/jsonnet-v0.16.0 "github.com/google/go-jsonnet/cmd/jsonnet"

JSONNETFMT := $(GOBIN)/jsonnetfmt-v0.16.0
$(JSONNETFMT): .bingo/jsonnetfmt.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/jsonnetfmt-v0.16.0"
@cd .bingo && $(GO) build -mod=mod -modfile=jsonnetfmt.mod -o=$(GOBIN)/jsonnetfmt-v0.16.0 "github.com/google/go-jsonnet/cmd/jsonnetfmt"

1 change: 1 addition & 0 deletions .bingo/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files.
5 changes: 5 additions & 0 deletions .bingo/gojsontoyaml.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/brancz/gojsontoyaml v0.0.0-20200602132005-3697ded27e8c
5 changes: 5 additions & 0 deletions .bingo/jb.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/jsonnet-bundler/jsonnet-bundler v0.4.0 // cmd/jb
5 changes: 5 additions & 0 deletions .bingo/jsonnet.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/google/go-jsonnet v0.16.0 // cmd/jsonnet
5 changes: 5 additions & 0 deletions .bingo/jsonnetfmt.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/google/go-jsonnet v0.16.0 // cmd/jsonnetfmt
18 changes: 18 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.3. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
GOBIN=${GOBIN:=$(go env GOBIN)}

if [ -z "$GOBIN" ]; then
GOBIN="$(go env GOPATH)/bin"
fi


GOJSONTOYAML="$GOBIN/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c"

JB="$GOBIN/jb-v0.4.0"

JSONNET="$GOBIN/jsonnet-v0.16.0"

JSONNETFMT="$GOBIN/jsonnetfmt-v0.16.0"

14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL=/usr/bin/env bash -o pipefail
include .bingo/Variables.mk

VERSION := $(strip $(shell [ -d .git ] && git describe --always --tags --dirty))
BUILD_DATE := $(shell date -u +"%Y-%m-%d")
Expand All @@ -8,9 +9,7 @@ VCS_REF := $(strip $(shell [ -d .git ] && git rev-parse --short HEAD))
DOCKER_REPO ?= quay.io/observatorium/observatorium-operator

BIN_DIR ?= $(shell pwd)/tmp/bin

CONTROLLER_GEN ?= $(BIN_DIR)/controller-gen
JB ?= $(BIN_DIR)/jb

# Generate manifests e.g. CRD, RBAC etc.
manifests: example/manifests/observatorium.yaml manifests/crds/core.observatorium.io_observatoria.yaml
Expand All @@ -19,7 +18,7 @@ manifests/crds/core.observatorium.io_observatoria.yaml: $(CONTROLLER_GEN) $(find
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=manifests/crds

example/manifests/observatorium.yaml: example/main.jsonnet
jsonnet -J jsonnet/vendor example/main.jsonnet | gojsontoyaml > example/manifests/observatorium.yaml
$(JSONNET) -J jsonnet/vendor example/main.jsonnet | $(GOJSONTOYAML) > example/manifests/observatorium.yaml

# Run go fmt against code
fmt:
Expand Down Expand Up @@ -65,8 +64,9 @@ $(BIN_DIR):
$(CONTROLLER_GEN): $(BIN_DIR)
GO111MODULE="on" go build -o $@ sigs.k8s.io/controller-tools/cmd/controller-gen

$(JB): $(BIN_DIR)
go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
GO111MODULE="on" go build -o $@ github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb

JSONNET_SRC = $(shell find . -type f -not -path './*vendor/*' \( -name '*.libsonnet' -o -name '*.jsonnet' \))
JSONNETFMT_CMD := $(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s

.PHONY: jsonnet-fmt
jsonnet-fmt: | $(JSONNETFMT)
PATH=$$PATH:$(BIN_DIR):$(FIRST_GOPATH)/bin echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNETFMT_CMD) -i
3 changes: 1 addition & 2 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
package main

import (
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
_ "github.com/brancz/locutus"
_ "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb"
_ "github.com/observatorium/observatorium/test/tls"
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
)

0 comments on commit 03be030

Please sign in to comment.