Skip to content

Commit

Permalink
Add tink-agent binary
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Doherty <[email protected]>
  • Loading branch information
chrisdoherty4 committed Jun 22, 2023
1 parent fb1d172 commit 365f016
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ help: ## Print this help
VERSION ?= $(shell git rev-parse --short HEAD)

# Define all the binaries we build for this project that get packaged into containers.
BINARIES := tink-server tink-worker tink-controller virtual-worker
BINARIES := tink-server tink-agent tink-worker tink-controller virtual-worker

.PHONY: build
build: $(BINARIES) ## Build all tink binaries. Cross build by setting GOOS and GOARCH.
Expand Down
10 changes: 10 additions & 0 deletions cmd/tink-agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:3.15

ARG TARGETOS
ARG TARGETARCH

RUN apk add --no-cache --update --upgrade ca-certificates

COPY bin/tink-agent-${TARGETOS}-${TARGETARCH} /usr/bin/tink-agent

ENTRYPOINT ["/usr/bin/tink-agent"]
13 changes: 13 additions & 0 deletions cmd/tink-agent/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"os"

"github.com/tinkerbell/tink/internal/cli"
)

func main() {
if err := cli.NewAgent().Execute(); err != nil {
os.Exit(-1)
}
}
56 changes: 56 additions & 0 deletions internal/cli/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cli

import (
"fmt"

"github.com/go-logr/zapr"
"github.com/spf13/cobra"
"github.com/tinkerbell/tink/internal/agent"
"github.com/tinkerbell/tink/internal/agent/runtime"
"github.com/tinkerbell/tink/internal/agent/transport"
"github.com/tinkerbell/tink/internal/proto/workflow/v2"
"go.uber.org/zap"
"google.golang.org/grpc"
)

type agentOpts struct {
AgentID string
TinkServerAddr string
}

// NewAgent builds a command that launches the agent component.
func NewAgent() *cobra.Command {
var opts agentOpts

cmd := cobra.Command{
Use: "tink-agent",
RunE: func(cmd *cobra.Command, args []string) error {
logger := zapr.NewLogger(zap.Must(zap.NewProduction()))

rntime, err := runtime.NewDocker()
if err != nil {
return fmt.Errorf("create runtime: %w", err)
}

conn, err := grpc.DialContext(cmd.Context(), opts.TinkServerAddr)
if err != nil {
return fmt.Errorf("dial tink server: %w", err)
}
defer conn.Close()
trnport := transport.NewGRPC(logger, workflow.NewWorkflowServiceClient(conn))

return (&agent.Agent{
Log: logger,
ID: opts.AgentID,
Transport: trnport,
Runtime: rntime,
}).Start(cmd.Context())
},
}

flgs := cmd.Flags()
flgs.StringVar(&opts.AgentID, "agent-id", "", "An ID that uniquely identifies the agent instance")
flgs.StringVar(&opts.TinkServerAddr, "tink-server-addr", "127.0.0.1:42113", "Tink server address")

return &cmd
}

0 comments on commit 365f016

Please sign in to comment.