-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chris Doherty <[email protected]>
- Loading branch information
1 parent
f20a793
commit 2946cc3
Showing
5 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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" | ||
) | ||
|
||
// NewAgent builds a command that launches the agent component. | ||
func NewAgent() *cobra.Command { | ||
var opts struct { | ||
AgentID string | ||
TinkServerAddr string | ||
} | ||
|
||
// TODO(chrisdoherty4) Handle signals | ||
cmd := cobra.Command{ | ||
Use: "tink-agent", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
zl, err := zap.NewProduction() | ||
if err != nil { | ||
return fmt.Errorf("init logger: %w", err) | ||
} | ||
logger := zapr.NewLogger(zl) | ||
|
||
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 | ||
} |