Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: runs against local helia #6

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,4 @@ analysis/plots/*.png

db.toml
/udgerdb_v3.dat
.envrc
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ An alternative IPFS implementation needs to support a couple of things:

## Contributing

Feel free to dive in! [Open an issue](https://github.com/RichardLitt/standard-readme/issues/new) or submit PRs.
Feel free to dive in! [Open an issue](https://github.com/plprobelab/tiros/issues/new) or submit PRs.

## License

Expand Down
41 changes: 40 additions & 1 deletion cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
"net/http"
"time"

shell "github.com/ipfs/go-ipfs-api"
Expand Down Expand Up @@ -262,8 +265,44 @@ func RunAction(c *cli.Context) error {
return nil
}

type versionResponse struct {
Version string
Commit string
}

func (t *tiros) GetHeliaVersion(c *cli.Context) (string, string, error) {
// TODO: use env vars for host location and port
// make http request to http://localhost:${PORT}/api/v0/version
// and return the version and commit
requestURL := fmt.Sprintf("http://localhost:%d/api/v0/version", 8888)
res, err := http.Get(requestURL)
if err != nil {
return "", "", fmt.Errorf("Failed to make http request to get version: %w", err)
}
resBody, err := io.ReadAll(res.Body)
if err != nil {
return "", "", fmt.Errorf("Failed to read version response body: %w", err)
}
log.Infoln("Response body:", string(resBody))

vObj := versionResponse{}
err = json.Unmarshal(resBody, &vObj)
if err != nil {
return "", "", fmt.Errorf("Failed to parse JSON response: %w", err)
}

return vObj.Version, vObj.Commit, nil
}
func (t *tiros) GetImplementationVersion(c *cli.Context) (string, string, error) {
if c.String("ipfs-implementation") == "HELIA" {
return t.GetHeliaVersion(c)
}
return t.ipfs.Version()
}

func (t *tiros) InitRun(c *cli.Context) (*models.Run, error) {
version, sha, err := t.ipfs.Version()
log.Infoln("Initializing run with implementation", c.String("ipfs-implementation"))
version, sha, err := t.GetImplementationVersion(c)
if err != nil {
return nil, fmt.Errorf("ipfs api offline: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"
name: tiros
services:
ipfs:
image: helia:latest
image: helia-http-gateway:latest
restart: unless-stopped
volumes:
- ipfs_path:/data/ipfs
Expand All @@ -11,15 +11,15 @@ services:
environment:
DEBUG: helia-server
ports:
- "0.0.0.0:8080:8080"
- "0.0.0.0:${HELIA_PORT:-8080}:8080"
chrome:
image: browserless/chrome:latest
ports:
- "3000:3000"
db:
image: postgres:14
ports:
- "0.0.0.0:5432:5432"
- "0.0.0.0:${TIROS_RUN_DATABASE_PORT:-5432}:5432"
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: tiros_test
Expand Down