From ac0c43cb43a652ccfa0a649f7d4bce56fed72a76 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 3 Jan 2025 17:18:23 +0000 Subject: [PATCH 1/5] Factor out formatting method --- devtools/store/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/devtools/store/main.go b/devtools/store/main.go index 8bd4d16..dfb9089 100644 --- a/devtools/store/main.go +++ b/devtools/store/main.go @@ -25,6 +25,15 @@ func init() { } +func formatItem(k []byte, v []byte) (string, error) { + o, err := debug.FromKey(k) + if err != nil { + return "", err + } + s := fmt.Sprintf("%vValue: %v\n\n", o, string(v)) + return s, nil +} + func main() { config.LoadConfig() @@ -64,12 +73,12 @@ func main() { if k == nil { break } - o, err := debug.FromKey(k) + r, err := formatItem(k, v) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "format db item error: %v", err) os.Exit(1) } - fmt.Printf("%vValue: %v\n\n", o, string(v)) + fmt.Printf(r) } err = store.Close() From daec816a3e0ba47629f6ee400ea7b5fe4cce51d5 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 3 Jan 2025 17:21:52 +0000 Subject: [PATCH 2/5] Move store devtools location --- devtools/store/{ => dump}/main.go | 0 devtools/{gen => store/generate}/main.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename devtools/store/{ => dump}/main.go (100%) rename devtools/{gen => store/generate}/main.go (100%) diff --git a/devtools/store/main.go b/devtools/store/dump/main.go similarity index 100% rename from devtools/store/main.go rename to devtools/store/dump/main.go diff --git a/devtools/gen/main.go b/devtools/store/generate/main.go similarity index 100% rename from devtools/gen/main.go rename to devtools/store/generate/main.go From 4836162f40bcd652b9658d786e0482b1df299d05 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Mon, 6 Jan 2025 10:51:20 +0300 Subject: [PATCH 3/5] ci: add ssh build --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 3a5da7d..827dcee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ WORKDIR /build RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM" RUN go mod download RUN go build -tags logtrace -o ussd-africastalking -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go +RUN go build -tags logtrace -o ussd-ssh -ldflags="-X main.build=${BUILD} -s -w" cmd/ssh/main.go FROM debian:bookworm-slim @@ -30,6 +31,7 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /service COPY --from=build /build/ussd-africastalking . +COPY --from=build /build/ussd-ssh . COPY --from=build /build/LICENSE . COPY --from=build /build/README.md . COPY --from=build /build/services ./services From a312ea5b84465af2d7b7d5ecb4a196f3133f27c2 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Mon, 6 Jan 2025 11:09:51 +0300 Subject: [PATCH 4/5] feat: inject build string in ssh binary, expose default ssh port --- Dockerfile | 1 + cmd/ssh/main.go | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 827dcee..d68733c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,5 +39,6 @@ COPY --from=build /build/.env.example . RUN mv .env.example .env EXPOSE 7123 +EXPOSE 7122 CMD ["./ussd-africastalking"] \ No newline at end of file diff --git a/cmd/ssh/main.go b/cmd/ssh/main.go index 0227616..ae046a5 100644 --- a/cmd/ssh/main.go +++ b/cmd/ssh/main.go @@ -4,9 +4,9 @@ import ( "context" "flag" "fmt" - "path" "os" "os/signal" + "path" "sync" "syscall" @@ -18,10 +18,12 @@ import ( ) var ( - wg sync.WaitGroup - keyStore db.Db + wg sync.WaitGroup + keyStore db.Db logg = logging.NewVanilla() scriptDir = path.Join("services", "registration") + + build = "dev" ) func main() { @@ -76,7 +78,7 @@ func main() { fmt.Fprintf(os.Stderr, "keystore file open error: %v", err) os.Exit(1) } - defer func () { + defer func() { logg.TraceCtxf(ctx, "shutdown auth key store reached") err = authKeyStore.Close() if err != nil { @@ -90,14 +92,14 @@ func main() { signal.Notify(cterm, os.Interrupt, syscall.SIGTERM) runner := &ssh.SshRunner{ - Cfg: cfg, - Debug: engineDebug, - FlagFile: pfp, - DbDir: dbDir, + Cfg: cfg, + Debug: engineDebug, + FlagFile: pfp, + DbDir: dbDir, ResourceDir: resourceDir, - SrvKeyFile: sshKeyFile, - Host: host, - Port: port, + SrvKeyFile: sshKeyFile, + Host: host, + Port: port, } go func() { select { @@ -109,7 +111,7 @@ func main() { if err != nil { logg.ErrorCtxf(ctx, "runner stop error", "err", err) } - + }() runner.Run(ctx, authKeyStore) } From 824d39908ba46ec25d181997f7bf7759c325f281 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Mon, 6 Jan 2025 11:19:36 +0300 Subject: [PATCH 5/5] ci: fix missing ssh dir --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index a118f64..2c2b83b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ /** !/cmd/africastalking +!/cmd/ssh !/common !/config !/initializers