Skip to content

Commit

Permalink
Make ipni-gc excutable into the gc subcommand of storetheindex (#2522)
Browse files Browse the repository at this point in the history
* Make ipni-gc excutable into the gc subcommand of storetheindex

There is no need for ipni-gc to be a separate executable, particularly since it runs on the same nodes that run storetheindex. Therefore, ipni-gc is better suited as a gc subcommand of storetheindex.

* Only copy one executable into image
  • Loading branch information
gammazero authored Feb 16, 2024
1 parent 5002b64 commit b83087c
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 78 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ COPY go.* .
RUN go mod download
COPY . .

RUN CGO_ENABLED=0 go build && CGO_ENABLED=0 go build ./ipni-gc/cmd/ipnigc
RUN CGO_ENABLED=0 go build

# Debug non-root image used as base in order to provide easier administration and debugging.
FROM gcr.io/distroless/static-debian12:debug-nonroot
COPY --from=builder /storetheindex/storetheindex /usr/local/bin/
COPY --from=builder /storetheindex/ipnigc /usr/local/bin/

# Default port configuration:
# - 3000 Finder interface
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ BIN := storetheindex

.PHONY: all build clean test

all: vet test build gc
all: vet test build

build:
go build

docker: Dockerfile clean
docker build . --force-rm -f Dockerfile -t storetheindex:$(shell git rev-parse --short HEAD)

gc:
go build ./ipni-gc/cmd/ipnigc

install:
go install

Expand All @@ -27,4 +24,3 @@ vet:

clean:
go clean
rm -f ipnigc
16 changes: 16 additions & 0 deletions command/gc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package command

import (
"github.com/ipni/storetheindex/command/gc"
"github.com/urfave/cli/v2"
)

var GCCmd = &cli.Command{
Name: "gc",
Usage: "IPNI indexer garbage collector",
Description: "Remove deleted indexes from value store.",
Subcommands: []*cli.Command{
gc.DaemonCmd,
gc.ProviderCmd,
},
}
12 changes: 6 additions & 6 deletions ipni-gc/cmd/ipnigc/daemon.go → command/gc/daemon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gc

import (
"context"
Expand All @@ -10,14 +10,14 @@ import (
"github.com/ipni/go-libipni/pcache"
"github.com/ipni/storetheindex/config"
"github.com/ipni/storetheindex/filestore"
"github.com/ipni/storetheindex/ipni-gc/reaper"
"github.com/ipni/storetheindex/gc/reaper"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/urfave/cli/v2"
)

var daemonCmd = &cli.Command{
var DaemonCmd = &cli.Command{
Name: "daemon",
Usage: "Run ipni-gc daemon to do periocid GC for all providers",
Usage: "Run gc daemon to do periocid GC for all providers",
Flags: daemonFlags,
Action: daemonAction,
}
Expand Down Expand Up @@ -50,13 +50,13 @@ var daemonFlags = []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Aliases: []string{"ll"},
Usage: "Set log level for ipni-gc",
Usage: "Set log level for gc",
Value: "info",
},
&cli.StringFlag{
Name: "log-level-other",
Aliases: []string{"llo"},
Usage: "Set log level for other loggers that are not ipni-gc",
Usage: "Set log level for other loggers that are not gc",
Value: "error",
},
&cli.IntFlag{
Expand Down
19 changes: 10 additions & 9 deletions ipni-gc/cmd/ipnigc/provider.go → command/gc/provider.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gc

import (
"errors"
Expand All @@ -11,16 +11,17 @@ import (
"github.com/ipni/go-libipni/pcache"
"github.com/ipni/storetheindex/config"
"github.com/ipni/storetheindex/filestore"
"github.com/ipni/storetheindex/ipni-gc/reaper"
"github.com/ipni/storetheindex/gc/reaper"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/urfave/cli/v2"
)

var log = logging.Logger("ipni-gc")

const defaultIndexerURL = "http://localhost:3000"
const gcLoggerName = "ipni-gc"

var log = logging.Logger(gcLoggerName)

var providerCmd = &cli.Command{
var ProviderCmd = &cli.Command{
Name: "provider",
Usage: "Run ipni garbage collection for specified providers",
Flags: providerFlags,
Expand Down Expand Up @@ -58,13 +59,13 @@ var providerFlags = []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Aliases: []string{"ll"},
Usage: "Set log level for ipni-gc",
Usage: "Set log level for gc",
Value: "info",
},
&cli.StringFlag{
Name: "log-level-other",
Aliases: []string{"llo"},
Usage: "Set log level for other loggers that are not ipni-gc",
Usage: "Set log level for other loggers that are not gc",
Value: "error",
},
&cli.IntFlag{
Expand Down Expand Up @@ -182,7 +183,7 @@ func providerAction(cctx *cli.Context) error {
fmt.Fprintln(os.Stderr, "Provider", pid, "not found.")
fmt.Fprintln(os.Stderr, "To delete providers that is not found use the -dnf flag.")
} else {
fmt.Fprintf(os.Stderr, "ipni-gc failed for provider %s: %s\n", pid, err)
fmt.Fprintf(os.Stderr, "gc failed for provider %s: %s\n", pid, err)
}
continue
}
Expand Down Expand Up @@ -217,7 +218,7 @@ func setLoggingConfig(level, otherLevel string) error {
return err
}

err = logging.SetLogLevel("ipni-gc", level)
err = logging.SetLogLevel(gcLoggerName, level)
if err != nil {
return err
}
Expand Down
8 changes: 3 additions & 5 deletions e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ func testEndToEndWithReferenceProvider(t *testing.T, publisherProto string) {
// install storetheindex
indexer := filepath.Join(e.Dir, "storetheindex")
e.Run("go", "install", ".")
e.Run("go", "install", "./ipni-gc/cmd/ipnigc")

provider := filepath.Join(e.Dir, "provider")
dhstore := filepath.Join(e.Dir, "dhstore")
ipni := filepath.Join(e.Dir, "ipni")
ipnigc := filepath.Join(e.Dir, "ipnigc")

cwd, err := os.Getwd()
require.NoError(t, err)
Expand Down Expand Up @@ -200,7 +198,7 @@ func testEndToEndWithReferenceProvider(t *testing.T, publisherProto string) {
"2DrjgbFY1BnkgZwA3oL7ijiDn7sJMf4bhhQNTtDqgZP826vGzv",
} {
findOutput := e.Run(ipni, "find", "--no-priv", "-i", "http://localhost:3000", "-mh", mh)
t.Logf("import output:\n%s\n", findOutput)
t.Logf("find output:\n%s\n", findOutput)

if bytes.Contains(findOutput, []byte("not found")) {
return false
Expand Down Expand Up @@ -333,7 +331,7 @@ func testEndToEndWithReferenceProvider(t *testing.T, publisherProto string) {
"2DrjgbFY1BnkgZwA3oL7ijiDn7sJMf4bhhQNTtDqgZP826vGzv",
} {
findOutput := e.Run(ipni, "find", "--no-priv", "-i", "http://localhost:3000", "-mh", mh)
t.Logf("import output:\n%s\n", findOutput)
t.Logf("find output:\n%s\n", findOutput)
if !bytes.Contains(findOutput, []byte("not found")) {
return false
}
Expand All @@ -359,7 +357,7 @@ func testEndToEndWithReferenceProvider(t *testing.T, publisherProto string) {
if testing.Verbose() {
logLevel = "debug"
}
outgc := string(e.Run(ipnigc, "provider", "-pid", providerID, "-ll", logLevel,
outgc := string(e.Run(indexer, "gc", "provider", "-pid", providerID, "-ll", logLevel,
"-i", "http://localhost:3200",
"-i", "http://localhost:3000",
"-sync-segment-size", "2",
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ipni-gc/reaper/reaper_test.go → gc/reaper/reaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ipni/go-libipni/pcache"
"github.com/ipni/storetheindex/carstore"
"github.com/ipni/storetheindex/filestore"
"github.com/ipni/storetheindex/ipni-gc/reaper"
"github.com/ipni/storetheindex/gc/reaper"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
Expand Down
50 changes: 0 additions & 50 deletions ipni-gc/cmd/ipnigc/main.go

This file was deleted.

1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func main() {
command.AdminCmd,
command.AssignerCmd,
command.DaemonCmd,
command.GCCmd,
command.InitCmd,
command.LoadtestCmd,
command.LogCmd,
Expand Down

0 comments on commit b83087c

Please sign in to comment.