Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
euforia committed Jul 20, 2018
1 parent 2c4a374 commit 3017d0b
Show file tree
Hide file tree
Showing 18 changed files with 399 additions and 349 deletions.
17 changes: 6 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,25 @@ clean:
rm -rf dist
rm -f $(NAME)

.PHONY: deps
deps:
go get github.com/c4milo/github-release
go get github.com/golang/dep/cmd/dep
dep ensure -v

.PHONY: test
test:
go test -cover $(SOURCE_PACKAGES)


$(NAME):
$(BUILD_CMD) -o $(NAME) $(SOURCE_FILES)

# linux is always done last as it is used in the container build
dist:
mkdir dist
GOOS=linux $(BUILD_CMD) $(DIST_OPTS) -o dist/$(NAME)-linux $(SOURCE_FILES)
GOOS=darwin $(BUILD_CMD) $(DIST_OPTS) -o dist/$(NAME)-darwin $(SOURCE_FILES)

dist/$(NAME)-darwin.tgz:
cd dist && tar -czf $(NAME)-darwin.tgz $(NAME)-darwin

dist/$(NAME)-linux.tgz:
cd dist && tar -czf $(NAME)-linux.tgz $(NAME)-linux
for goos in darwin linux; do \
GOOS=$${goos} $(BUILD_CMD) $(DIST_OPTS) -o dist/$(NAME) $(SOURCE_FILES); \
tar -czf dist/$(NAME)-$${goos}.tgz -C dist $(NAME); done

.PHONY: release
release: dist dist/$(NAME)-darwin.tgz dist/$(NAME)-linux.tgz


5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ simpifying various integration points

## Getting Started

### Pre-requisites

The following are required for thrap:
- Docker

### Installation

Download the appropriate binary based on your platform from [here](https://github.com/euforia/thrap/releases)
Expand Down
2 changes: 1 addition & 1 deletion api.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
VOLUME /secrets.hcl
WORKDIR /
EXPOSE 10000
COPY --from=build /go/src/github.com/euforia/thrap/dist/thrap-linux /usr/bin/thrap
COPY --from=build /go/src/github.com/euforia/thrap/dist/thrap /usr/bin/thrap
RUN thrap configure --no-prompt
CMD ["thrap", "agent"]
1 change: 0 additions & 1 deletion asm/basic_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func makeDevComp(compID string, lang thrapb.LanguageID) *thrapb.Component {
},
Secrets: &thrapb.Secrets{
Destination: consts.DefaultSecretsFile,
Format: consts.DefaultSecretsFileFormat,
},
}
}
9 changes: 1 addition & 8 deletions asm/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import (
"github.com/euforia/thrap/thrapb"
)

// type baseComp struct {
// cfg *thrapb.Container
// comp *thrapb.Component
// }

// ComponentAssembler implements a component assembly interface
type ComponentAssembler interface {
Dockerfile() *dockerfile.Dockerfile
Assemble(scope.Variables) error
Expand All @@ -36,9 +32,6 @@ type BuildCompAsm struct {
// Working/Context directory
ctxDir string

// Assembled files after rendering
// files map[string][]byte

// HICL language vm
vm *pseudo.VM
}
Expand Down
16 changes: 16 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"google.golang.org/grpc"

"github.com/euforia/thrap/consts"
"github.com/euforia/thrap/utils"
"github.com/euforia/thrap/vars"

"github.com/pkg/errors"
Expand Down Expand Up @@ -124,3 +125,18 @@ func writeJSON(v interface{}) {
b, _ := json.MarshalIndent(v, "", " ")
fmt.Printf("%s\n", b)
}

func loadCore() (*core.Core, error) {
conf := &core.Config{DataDir: consts.DefaultDataDir}

lpath, _ := utils.GetLocalPath("")

var err error

conf.ThrapConfig, err = config.ReadProjectConfig(lpath)
if err != nil {
return nil, err
}

return core.NewCore(conf)
}
95 changes: 73 additions & 22 deletions cli/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"io"
"os"
"text/tabwriter"
"time"

"github.com/euforia/thrap/consts"
"github.com/euforia/thrap/core"
"github.com/euforia/thrap/manifest"
"github.com/euforia/thrap/thrapb"
Expand All @@ -25,6 +25,7 @@ func commandStack() *cli.Command {
commandStackRegister(),
commandStackCommit(),
commandStackBuild(),
commandStackArtifacts(),
commandStackDeploy(),
commandStackStatus(),
commandStackLogs(),
Expand Down Expand Up @@ -61,12 +62,12 @@ func commandStackBuild() *cli.Command {
return err
}

core, err := core.NewCore(&core.Config{DataDir: consts.DefaultDataDir})
cr, err := loadCore()
if err != nil {
return err
}

stm := core.Stack()
stm := cr.Stack()

return stm.Build(context.Background(), stack)
},
Expand All @@ -87,7 +88,7 @@ func commandStackStop() *cli.Command {
return utils.FlattenErrors(errs)
}

core, err := core.NewCore(&core.Config{DataDir: consts.DefaultDataDir})
core, err := loadCore()
if err != nil {
return err
}
Expand Down Expand Up @@ -122,7 +123,7 @@ func commandStackDestroy() *cli.Command {
return utils.FlattenErrors(errs)
}

core, err := core.NewCore(&core.Config{DataDir: consts.DefaultDataDir})
core, err := loadCore()
if err != nil {
return err
}
Expand Down Expand Up @@ -155,38 +156,88 @@ func commandStackStatus() *cli.Command {
return utils.FlattenErrors(errs)
}

// fmt.Println("Version:", stack.Version)

core, err := core.NewCore(&core.Config{DataDir: consts.DefaultDataDir})
core, err := loadCore()
if err != nil {
return err
}

stm := core.Stack()
resp := stm.Status(context.Background(), stack)

tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', tabwriter.StripEscape)
fmt.Fprintf(tw, "Component\tImage\tStatus\tDetails\n")
fmt.Fprintf(tw, "---------\t-----\t------\t-------\n")
for _, s := range resp {
fmt.Println()
printStackStatus(stm, stack)
fmt.Println()

d := s.Details
st := d.State
return nil
},
}
}

if s.Error != nil {
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", s.ID, d.Config.Image, st.Status, s.Error)
} else {
fmt.Fprintf(tw, "%s\t%s\t%s\t%v\n", s.ID, d.Config.Image, st.Status, d.NetworkSettings.Ports)
}
func commandStackArtifacts() *cli.Command {
return &cli.Command{
Name: "artifacts",
Aliases: []string{"arts"},
Usage: "List stack artifacts",
Action: func(ctx *cli.Context) error {

stack, err := manifest.LoadManifest("")
if err != nil {
return err
}
if errs := stack.Validate(); len(errs) > 0 {
return utils.FlattenErrors(errs)
}
tw.Flush()

core, err := loadCore()
if err != nil {
return err
}

stm := core.Stack()

fmt.Println()
printStackImages(stm, stack)
fmt.Println()

return nil
},
}
}

func printStackImages(stm *core.Stack, stack *thrapb.Stack) {
imgs := stm.Images(stack)
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', tabwriter.StripEscape)
fmt.Fprintf(tw, "Name\tID\tCreated\tSize\n")
fmt.Fprintf(tw, "----\t--\t-------\t----\n")
for _, img := range imgs {
for _, tag := range img.Tags {
d := time.Now().Sub(img.Created)
fmt.Fprintf(tw, "%s\t%s\t%s ago\t%d MB\n", tag, img.ID.Hex()[:12], d.Round(time.Second), img.Size/(1024*1024))
}

}
tw.Flush()
}

func printStackStatus(stm *core.Stack, stack *thrapb.Stack) {
resp := stm.Status(context.Background(), stack)
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', tabwriter.StripEscape)
fmt.Fprintf(tw, "Component\tImage\tStatus\tDetails\n")
fmt.Fprintf(tw, "---------\t-----\t------\t-------\n")
for _, s := range resp {

d := s.Details
st := d.State

if s.Error != nil {
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", s.ID, d.Config.Image, st.Status, s.Error)
} else {
fmt.Fprintf(tw, "%s\t%s\t%s\t%v\n", s.ID, d.Config.Image, st.Status, d.NetworkSettings.Ports)
}

}
tw.Flush()
}

func commandStackLogs() *cli.Command {
return &cli.Command{
Name: "logs",
Expand All @@ -203,7 +254,7 @@ func commandStackLogs() *cli.Command {
return utils.FlattenErrors(errs)
}

core, err := core.NewCore(&core.Config{DataDir: consts.DefaultDataDir})
core, err := loadCore()
if err != nil {
return err
}
Expand Down
34 changes: 34 additions & 0 deletions config/orchestrator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package config

// OrchestratorConfig holds oconfigurations for a orchestration
type OrchestratorConfig struct {
ID string `hcl:"id" hcle:"omit"`
Addr string `hcl:"addr" hcle:"omitempty"`
}

// Clone returns a copy of the config
func (conf *OrchestratorConfig) Clone() *OrchestratorConfig {
if conf == nil {
return nil
}
return &OrchestratorConfig{
ID: conf.ID,
Addr: conf.Addr,
}
}

// Merge merges the other config into the one. Only non-empty fields are
// considered
func (conf *OrchestratorConfig) Merge(other *OrchestratorConfig) {
if other == nil {
return
}

if other.ID != "" {
conf.ID = other.ID
}

if other.Addr != "" {
conf.Addr = other.Addr
}
}

0 comments on commit 3017d0b

Please sign in to comment.