Skip to content

Commit

Permalink
integrate Makefile; add protobuf.path to config
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjarosch committed Jul 19, 2019
1 parent 626747c commit 644efbc
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 51 deletions.
14 changes: 7 additions & 7 deletions a_main-packr.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cmd

import (
"fmt"
"github.com/lukasjarosch/godin/internal/bundle/transport"
"os"

"github.com/lukasjarosch/godin/internal/bundle/transport"

"github.com/lukasjarosch/godin/internal/bundle"

"strings"
Expand Down Expand Up @@ -226,7 +227,7 @@ func updateCmd(cmd *cobra.Command, args []string) {
}

// Makefile // TODO: remove and move to init
makefile := template.NewGenerator(template.MakefileOptions())
makefile := template.NewGenerator(template.MakefileOptions(tplContext))
if err := makefile.GenerateFile(TemplateFilesystem); err != nil {
logrus.Error(fmt.Sprintf("failed to generate Makefile: %s", err.Error()))
} else {
Expand Down
1 change: 1 addition & 0 deletions internal/godin/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (p *Project) InitializeConfiguration() {
config.Set("service.module", prompt.ServiceModule())
config.Set("protobuf.service", prompt.ProtoServiceName())
config.Set("protobuf.package", prompt.ProtoPackage())
config.Set("protobuf.path", prompt.ProtoPath())
config.Set("docker.registry", prompt.DockerRegistry())

SaveConfiguration()
Expand Down
16 changes: 16 additions & 0 deletions internal/prompt/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ func ProtoPackage() string {
return protoPackage
}

func ProtoPath() string {
prompt := NewPrompt(
"Absolute path to the .proto file which defines the service",
"/home/lukas/devel/work/protobuf",
Validate(
MinLengthThree(),
ProtoFileExtension(),
),
)
protoPath, err := prompt.Run()
if err != nil {
os.Exit(1)
}
return protoPath
}

func DockerRegistry() string {
prompt := NewPrompt(
"Enter your docker registry",
Expand Down
9 changes: 9 additions & 0 deletions internal/prompt/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@ func CamelCase() promptui.ValidateFunc {
}
return nil
}
}

func ProtoFileExtension() promptui.ValidateFunc {
return func(s string) error {
if !strings.HasSuffix(s, ".proto") {
return fmt.Errorf("must point to a .proto file")
}
return nil
}
}
6 changes: 4 additions & 2 deletions internal/template/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewContextFromConfig() Context {
Protobuf: Protobuf{
Package: config.GetString("protobuf.package"),
Service: config.GetString("protobuf.service"),
Path: config.GetString("protobuf.path"),
},
Project: Project{
Created: config.GetTime("project.created"),
Expand Down Expand Up @@ -164,6 +165,7 @@ type Service struct {
type Protobuf struct {
Package string
Service string
Path string
}

type Transport struct {
Expand All @@ -178,8 +180,8 @@ type Docker struct {
type Subscriber struct {
Handler string
Subscription rabbitmq.Subscription
Protobuf struct {
Import string
Protobuf struct {
Import string
Message string
}
}
Expand Down
8 changes: 1 addition & 7 deletions internal/template/godin.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ func K8sServiceOptions() GenerateOptions {
return opts
}

func MakefileOptions() GenerateOptions {
ctx := Context{
Service: Service{
Name: config.GetString("service.name"),
Namespace: config.GetString("service.namespace"),
},
}
func MakefileOptions(ctx Context) GenerateOptions {
opts := fileOptions["makefile"]
opts.Context = ctx

Expand Down
43 changes: 11 additions & 32 deletions templates/makefile.tpl
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
SERVICE_NAME=ticket

GOBASE=$(shell pwd)
GOBIN=$(GOBASE)/bin
GODIRS = $(shell go list -f '{{.Dir}}' ./...)
KUBE_CONTEXT=$(cat ~/.kube/config | grep "current-context:" | sed "s/current-context: //")

COMMIT=$(shell git rev-parse --short HEAD)

DOCKER_IMAGE="docker.coozzy.ch/ticket-ticket"
DOCKER_IMAGE="docker.coozzy.ch/<< .Service.Namespace >>-<< .Service.Name >>"
DOCKER_TAG="v-${COMMIT}-dev"

MODULE="bitbucket.org/jdbergmann/ticket/ticket"
PROTO_SRC="/home/lukas/devel/work/protobuf/ticket/ticket"
PROTO_DST="proto"
PROTO_SRC="<< .Protobuf.Path >>"

.PHONY: build
build:
@echo "--> building"
@go build -o ${GOBIN}/ticket ./cmd/ticket/main.go
@go build -o ${GOBIN}/<< .Service.Name >> ./cmd/<< .Service.Name >>/main.go

.PHONY: run
run:
echo "--> starting locally"
@LOG_LEVEL=${LOG_LEVEL} AMQP_CONNECTION=${AMQP_CONNECTION} AMQP_EXCHANGE=${AMQP_EXCHANGE} go run cmd/ticket/main.go
@echo "--> starting locally"
@LOG_LEVEL=debug go run cmd/<< .Service.Name >>/main.go

.PHONY: grpcui
grpcui:
grpcui -proto ${PROTO_SRC}/ticket.proto -port 5000 -plaintext localhost:50051
grpcui:
@grpcui -proto ${PROTO_SRC} -port 5000 -plaintext localhost:50051

.PHONY: clean
clean:
echo "--> cleaning up binaries"
go clean -tags netgo -i ./...
rm -rf $(GOBIN)/*

.PHONY: clean
skaffold:
@echo "--> starting skaffold, make sure minikube is running"
@skaffold dev
@echo "--> cleaning up binaries"
@go clean -tags netgo -i ./...
@rm -rf $(GOBIN)/*

.PHONY: docker
docker:
Expand All @@ -49,19 +37,10 @@ docker-run:
@echo "--> starting container ${DOCKER_IMAGE}:${DOCKER_TAG}"
@docker run \
--rm \
--name ${ticket} \
--name << .Service.Name >> \
--network host \
${DOCKER_IMAGE}:${DOCKER_TAG}

.PHONY: proto
proto:
@rm -rf ${PROTO_DST}
@echo "--> fetching proto from ${PROTO_SRC}"
@make -C ${PROTO_SRC} go
@mkdir ${PROTO_DST}
@echo "--< moving stubs into ${PROTO_DST}"
@cp ${PROTO_SRC}/go/* ${PROTO_DST}

.PHONY: check
check: format.check lint

Expand Down
3 changes: 2 additions & 1 deletion templates/partials/amqp/encode_decode/publish_encode.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- define "amqp_publish_encode" }}
// {{ .Name }}Encoder is called just before publishing an event to '{{ .Publishing.Topic }}' and encodes
// the DAO to protobuf.
// the DAO to protobuf. Godin doesn't know what you will pass to this function, so ensure that you
// use a runtime-assertion to ensure that you've got the correct type.
func {{ .Name }}Encoder(event interface{}) (*pb.{{ .Publishing.ProtobufMessage }}, error) {
var encoded pb.{{ .Publishing.ProtobufMessage }}

Expand Down

0 comments on commit 644efbc

Please sign in to comment.