-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- cli for p2pmq (wip) - dockerfile - makefile - default config files - protoc gen script
- Loading branch information
Showing
10 changed files
with
219 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Build | ||
|
||
FROM golang:1.20 AS builder | ||
|
||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ | ||
git make g++ gcc-aarch64-linux-gnu wget \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG APP_VERSION | ||
ARG APP_NAME | ||
ARG BUILD_TARGET | ||
|
||
WORKDIR /p2pmq | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
COPY . . | ||
|
||
RUN GOOS=linux CGO_ENABLED=0 go build -tags netgo -a -v -o ./bin/${BUILD_TARGET} ./cmd/${BUILD_TARGET} | ||
|
||
# Runtime | ||
|
||
FROM alpine:latest as runner | ||
|
||
ARG BUILD_TARGET | ||
|
||
RUN apk --no-cache --upgrade add ca-certificates bash | ||
|
||
WORKDIR /p2pmq | ||
|
||
COPY --from=builder /p2pmq/.env* ./ | ||
COPY --from=builder /p2pmq/bin/${BUILD_TARGET} ./app |
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,111 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/amirylm/p2pmq/commons" | ||
"github.com/amirylm/p2pmq/core" | ||
logging "github.com/ipfs/go-log/v2" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "route-p2p", | ||
Usage: "p2p router", | ||
Flags: []cli.Flag{ | ||
// cli.IntFlag{ | ||
// Name: "grpc-port", | ||
// EnvVar: "GRPC_PORT", | ||
// Value: 12001, | ||
// }, | ||
// cli.IntFlag{ | ||
// Name: "monitor-port", | ||
// EnvVar: "MONITOR_PORT", | ||
// }, | ||
cli.StringFlag{ | ||
Name: "config", | ||
EnvVar: "P2PMQ_CONFIG", | ||
Value: "/p2pmq/p2pmq.json", | ||
}, | ||
cli.StringFlag{ | ||
Name: "loglevel", | ||
EnvVar: "P2PMQ_LOGLEVEL", | ||
Value: "info", | ||
}, | ||
cli.StringFlag{ | ||
Name: "libp2p-loglevel", | ||
EnvVar: "LIBP2P_LOGLEVEL", | ||
Value: "info", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) (err error) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
_ = logging.SetLogLevelRegex("p2p:.*", c.String("libp2p-loglevel")) | ||
_ = logging.SetLogLevelRegex("p2pmq.*", c.String("loglevel")) | ||
|
||
var d *core.Daemon | ||
if cfgPath := c.String("config"); len(cfgPath) > 0 { | ||
cfg, err := commons.ReadConfig(cfgPath) | ||
if err != nil { | ||
return err | ||
} | ||
d, err = core.NewDaemon(ctx, *cfg, nil, "node") | ||
if err != nil { | ||
return err | ||
} | ||
if err := d.Start(ctx); err != nil { | ||
return err | ||
} | ||
defer func() { | ||
_ = d.Close() | ||
}() | ||
} | ||
|
||
if d == nil { | ||
return fmt.Errorf("could not create daemon instance, please provide a config file") | ||
} | ||
|
||
<-ctx.Done() | ||
|
||
logging.Logger("p2pmq/cli").Info("closing node") | ||
|
||
return nil | ||
|
||
// svc := service.NewGrpc(ctx, c.String("name")) | ||
// defer svc.Close() | ||
|
||
// if monitorPort := c.Int("monitor-port"); monitorPort > 0 { | ||
// mux := http.NewServeMux() | ||
// monitoring.WithMetrics(mux) | ||
// monitoring.WithProfiling(mux) | ||
// monitoring.WithHealthCheck(mux, func() []error { | ||
// err := ctx.Err() | ||
// if err != nil { | ||
// return []error{err} | ||
// } | ||
// return nil | ||
// }) | ||
// go func() { | ||
// err := http.ListenAndServe(fmt.Sprintf(":%d", monitorPort), mux) | ||
// if err != nil { | ||
// panic(err) | ||
// } | ||
// }() | ||
// } | ||
|
||
// s := svc.GrpcServer() | ||
// return service.ListenGrpc(s, c.Int("grpc-port")) | ||
}, | ||
Commands: []cli.Command{}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,7 @@ | ||
listenAddrs: | ||
- /ip4/0.0.0.0/tcp/5001 | ||
discovery: | ||
serviceTag: p2pmq/kad | ||
mode: bootstrapper | ||
bootstrappers: | ||
# pubsub: |
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,8 @@ | ||
listenAddrs: | ||
- /ip4/0.0.0.0/tcp/0 | ||
discovery: | ||
serviceTag: p2pmq/kad | ||
mode: server | ||
bootstrappers: | ||
- /ip4/0.0.0.0/tcp/5001 | ||
pubsub: |
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,7 @@ | ||
#!/bin/bash | ||
|
||
protoc --go_out=. --go_opt=paths=source_relative \ | ||
--go-grpc_out=. --go-grpc_opt=paths=source_relative ./proto/*.proto | ||
|
||
protoc --go_out=. --go_opt=paths=source_relative \ | ||
--go-grpc_out=. --go-grpc_opt=paths=source_relative ./proto/**/*.proto |