- Configuration has been saved successfuly. - You may need to restart TrueBlocks DAppNode package. -
-
- Error while saving the configuration: unknown
.
-
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3918b1e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM golang:1.20-alpine as builder + +RUN apk --no-cache add g++ gcc make cmake git nano libcurl python3 python3-dev \ + curl bash curl-dev linux-headers sqlite-dev sed + +WORKDIR /root + +# ARG UPSTREAM_VER=feature/docker-version +# ADD https://api.github.com/repos/TrueBlocks/trueblocks-core/git/refs/heads/$UPSTREAM_VER version.json + +# UPDATE_VERSION_HERE +ARG UPSTREAM_VER=v0.70.0-beta +# ARG UPSTREAM_VER=develop +RUN git clone -b "${UPSTREAM_VER}" --single-branch --progress --depth 1 \ + https://github.com/TrueBlocks/trueblocks-core.git && \ + cd trueblocks-core && \ + cat src/libs/CMakeLists.txt | grep -v "test-libs" >x && \ + cat x >src/libs/CMakeLists.txt && \ + cat src/CMakeLists.txt | grep -v "examples" | grep -v dev_tools >x && \ + cat x >src/CMakeLists.txt && \ + rm -f x && \ + mkdir -p build && \ + cd build && \ + cmake ../src && \ + make -j 5 + +FROM alpine:latest + +RUN apk --no-cache add gzip libstdc++ libgcc libcurl python3 python3-dev procps bash curl nano findutils + +COPY --from=builder /root/trueblocks-core/bin /usr/local/bin +COPY --from=builder /root/.local/bin/chifra /root/.local/bin/chifra +COPY --from=builder /root/.local/share/trueblocks /root/.local/share/trueblocks + +ARG SERVE_PORT=8080 +EXPOSE ${SERVE_PORT} + +CMD ["chifra", "daemon", "--api", "on", "--scrape", "index"] diff --git a/configuration/docker/Dockerfile b/configuration/docker/Dockerfile deleted file mode 100644 index 14a3416..0000000 --- a/configuration/docker/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -# Latest golang as builder -FROM golang:1.18-alpine as builder - -# Install build depenedencies -RUN apk --no-cache add git nano - -# Set workdir -WORKDIR /root - -# Try to get upstream version (default v0.44.0-beta) -ARG UPSTREAM_VER=v0.44.0-beta - -# Clone and make TrueBlocks Core -# make -j 5 is a fairly safe number -RUN git clone -b "${UPSTREAM_VER}" --single-branch --progress --depth 1 \ - https://github.com/TrueBlocks/trueblocks-dappnode.git && \ - cd trueblocks-dappnode/configuration && go build -o server - -# Switch to alpine container -FROM alpine:latest - -# Install binary dependencies and nice to haves -RUN apk --no-cache add nano - -# Copy files from builder -COPY --from=builder /root/trueblocks-dappnode/configuration/server /app/server -COPY --from=builder /root/trueblocks-dappnode/configuration/static /app/static - -EXPOSE 80 - -# Run entrypoint -ENTRYPOINT /app/server --static /app/static diff --git a/configuration/go.mod b/configuration/go.mod deleted file mode 100644 index 5f86150..0000000 --- a/configuration/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/TrueBlocks/trueblocks-dappnode/configuration - -go 1.18 diff --git a/configuration/main.go b/configuration/main.go deleted file mode 100644 index b9ccfea..0000000 --- a/configuration/main.go +++ /dev/null @@ -1,243 +0,0 @@ -package main - -import ( - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "log" - "net/http" - "os" - "path" - "strconv" - "strings" -) - -type ConfigurationItem struct { - Name string - Rpc string - ChainId string - Symbol string - IpfsGateway string - LocalExplorer string - RemoteExplorer string - ScraperArgs string - ScraperFile string -} - -type GlobalConfiguration struct { - RunScraper bool - InitBlooms bool - InitIndex bool - MonitorArgs string - MonitorFile string - EtherscanKey string - DefaultGateway string -} - -type ConfigurationPost struct { - Global GlobalConfiguration - Chains []ConfigurationItem -} - -func EnvsFromConfiguration(item ConfigurationItem) string { - var b strings.Builder - - prefix := fmt.Sprintf("export TB_CHAINS_%s_", strings.ToUpper(item.Name)) - b.WriteString(prefix + "CHAINID=" + item.ChainId + "\n") - b.WriteString(prefix + "RPCPROVIDER=" + item.Rpc + "\n") - b.WriteString(prefix + "SYMBOL=" + item.Symbol + "\n") - - if item.IpfsGateway != "" { - b.WriteString(prefix + "IPFSGATEWAY=" + item.IpfsGateway + "\n") - } - if item.LocalExplorer != "" { - b.WriteString(prefix + "LOCALEXPLORER=" + item.LocalExplorer + "\n") - } - if item.RemoteExplorer != "" { - b.WriteString(prefix + "REMOTEEXPLORER=" + item.RemoteExplorer + "\n") - } - if item.ScraperArgs != "" { - b.WriteString(fmt.Sprintf("export SCRAPER_%s_ARGS=%s\n", strings.ToUpper(item.Name), normalizeUserInput(item.ScraperArgs))) - } - if item.ScraperFile != "" { - b.WriteString(fmt.Sprintf("export SCRAPER_%s_FILE=%s\n", strings.ToUpper(item.Name), normalizeUserInput(item.ScraperFile))) - } - - return b.String() -} - -func WriteEnvFile(path string, contents string) (err error) { - file, err := os.Create(path) - defer func() { - err := file.Close() - if err != nil { - panic(err) - } - }() - if err != nil { - return - } - - _, err = file.WriteString(contents) - if err != nil { - return - } - - return nil -} - -func normalizeUserInput(content string) string { - return strconv.Quote(content) -} - -func SaveConfiguration(path string, config ConfigurationPost) (err error) { - lines := []string{ - "#!/bin/bash", - fmt.Sprint("export RUN_SCRAPER=", config.Global.RunScraper), - fmt.Sprint("export BOOTSTRAP_BLOOM_FILTERS=", config.Global.InitBlooms), - fmt.Sprint("export BOOTSTRAP_FULL_INDEX=", config.Global.InitIndex), - fmt.Sprint("export TB_KEYS_ETHERSCAN_APIKEY=", normalizeUserInput(config.Global.EtherscanKey)), - fmt.Sprint("export TB_SETTINGS_DEFAULTGATEWAY=", config.Global.DefaultGateway), - } - if config.Global.MonitorArgs != "" { - lines = append(lines, fmt.Sprint("export MONITORS_ARGS=", normalizeUserInput(config.Global.MonitorArgs))) - } - if config.Global.MonitorFile != "" { - lines = append(lines, fmt.Sprint("export MONITORS_FILE=", normalizeUserInput(config.Global.MonitorFile))) - } - - for _, item := range config.Chains { - lines = append(lines, EnvsFromConfiguration(item)) - } - err = WriteEnvFile(path, strings.Join(lines, "\n")) - return err -} - -func SaveEntrypointScript(path string, config ConfigurationPost) (err error) { - scraperOpts := "off" - if (config.Global.RunScraper && config.Global.InitBlooms) { - scraperOpts = "blooms" - } - if (config.Global.RunScraper && config.Global.InitIndex) { - scraperOpts = "full-index" - } - cmdOpts := []string{ - "chifra daemon", - "--api on", - "--scrape", - scraperOpts, - "--monitor", - } - - script := []string{ - "#!/bin/bash", - "", - strings.Join(cmdOpts, " "), - "", - } - - err = WriteEnvFile(path, strings.Join(script, "\n")) - if err != nil { - return err - } - err = os.Chmod(path, 0700) - return err -} - -func SaveJson(path string, config ConfigurationPost) (err error) { - contents, err := json.MarshalIndent(config, "", " ") - if err != nil { - return - } - - file, err := os.Create(path) - if err != nil { - return - } - - file.Write(contents) - return nil -} - -func ReadJson(path string) (contents []byte, err error) { - contents, err = ioutil.ReadFile(path) - if err != nil { - return - } - - return -} - -func makeConfigurationHandler(outputDir string) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodPost && r.Method != http.MethodGet { - http.Error(w, "unsupported method", http.StatusMethodNotAllowed) - return - } - - if r.Method == http.MethodPost { - log.Println("POST /configuration") - - p := ConfigurationPost{} - - err := json.NewDecoder(r.Body).Decode(&p) - if err != nil { - log.Println("error", err) - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - err = SaveConfiguration(path.Join(outputDir, "configuration.sh"), p) - if err != nil { - http.Error(w, fmt.Sprintf("Could not save configuration file: %s", err), http.StatusInternalServerError) - return - } - err = SaveEntrypointScript(path.Join(outputDir, "entrypoint.sh"), p) - if err != nil { - http.Error(w, fmt.Sprintf("Could not update entrypoint script: %s", err), http.StatusInternalServerError) - return - } - err = SaveJson(path.Join(outputDir, "configuration.json"), p) - if err != nil { - http.Error(w, fmt.Sprintf("Could not save JSON configuration file: %s", err), http.StatusInternalServerError) - return - } - } - - if r.Method == http.MethodGet { - log.Println("GET /configuration") - - data, err := ReadJson(path.Join(outputDir, "configuration.json")) - if err != nil { - http.Error(w, fmt.Sprintf("Could not read JSON configuration file: %s", err), http.StatusInternalServerError) - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(data) - } - } -} - -func main() { - var outputPath string - var port string - var staticDir string - - flag.StringVar(&outputPath, "dir", "/output/", "Path to output directory") - flag.StringVar(&port, "port", "80", "Port to listen on") - flag.StringVar(&staticDir, "static", "./static", "Directory to serve static files from") - flag.Parse() - log.Println("Will save output to", outputPath) - - http.HandleFunc("/configuration", makeConfigurationHandler(outputPath)) - - fs := http.FileServer(http.Dir(staticDir)) - http.Handle("/", fs) - - log.Print("Listening on ", port) - err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil) - if err != nil { - log.Fatal(err) - } -} diff --git a/configuration/static/index.html b/configuration/static/index.html deleted file mode 100644 index b0cd429..0000000 --- a/configuration/static/index.html +++ /dev/null @@ -1,712 +0,0 @@ - - -
- -- This tool makes it easier to configure TrueBlocks Core DAppNode package. You can add or remove chains and change monitor watch options. -
-- Remember to restart our DAppNode package after changing the configuration -
-- If you need help, let us know on Discord or create new issue. -
-- Configuration has been saved successfuly. - You may need to restart TrueBlocks DAppNode package. -
-
- Error while saving the configuration: unknown
.
-