-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add bore tunnel provider #8
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
847846d
feat(bore): add bore tunnel provider
sthbryan fd706b1
feat(bore): add bore to provider selector UI
sthbryan a376adc
refactor(bore): enhance archive extraction functions to support binar…
sthbryan f990b0b
fix(bore): update installation logic to support architecture-specific…
sthbryan f4edbec
refactor(cloudflared): use DownloadWithProgress and ExtractArchive
sthbryan a0ad308
fix(cloudflared): implement AutoInstaller for download progress UI
sthbryan 6d4448c
fix(api): add bore to /api/providers endpoint
sthbryan 8a688fc
refactor: extract bore version
sthbryan d274d86
refactor: handle error on closing output
sthbryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,133 @@ | ||
| package bore | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "regexp" | ||
| "runtime" | ||
| "strings" | ||
|
|
||
| "github.com/sthbryan/ftm/internal/config" | ||
| "github.com/sthbryan/ftm/internal/providers" | ||
| ) | ||
|
|
||
| type BoreProvider struct { | ||
| installer *Installer | ||
| } | ||
|
|
||
| func New() providers.Provider { | ||
| configDir, _ := os.UserHomeDir() | ||
| if configDir == "" { | ||
| configDir = "." | ||
| } | ||
| baseDir := filepath.Join(configDir, ".config", "foundry-tunnel", "bin") | ||
|
|
||
| return &BoreProvider{ | ||
| installer: NewInstaller(baseDir), | ||
| } | ||
| } | ||
|
|
||
| func (p *BoreProvider) Name() string { | ||
| return "bore" | ||
| } | ||
|
|
||
| func (p *BoreProvider) BinaryName() string { | ||
| if runtime.GOOS == "windows" { | ||
| return "bore.exe" | ||
| } | ||
| return "bore" | ||
| } | ||
|
|
||
| func (p *BoreProvider) IsInstalled() bool { | ||
| if _, err := exec.LookPath(p.BinaryName()); err == nil { | ||
| return true | ||
| } | ||
| return p.installer.IsInstalled() | ||
| } | ||
|
|
||
| func (p *BoreProvider) Install(progress chan<- providers.DownloadProgress) error { | ||
| return p.installer.Install(progress) | ||
| } | ||
|
|
||
| func (p *BoreProvider) FindBinary() string { | ||
| if path, err := exec.LookPath(p.BinaryName()); err == nil { | ||
| return path | ||
| } | ||
|
|
||
| if p.installer.IsInstalled() { | ||
| return p.installer.BoreBin() | ||
| } | ||
|
|
||
| home, _ := os.UserHomeDir() | ||
| candidates := []string{ | ||
| filepath.Join(home, ".config", "foundry-tunnel", "bin", p.BinaryName()), | ||
| "/usr/local/bin/" + p.BinaryName(), | ||
| "/usr/bin/" + p.BinaryName(), | ||
| } | ||
|
|
||
| if runtime.GOOS == "windows" { | ||
| candidates = []string{ | ||
| p.BinaryName(), | ||
| filepath.Join(os.Getenv("ProgramFiles"), "bore", p.BinaryName()), | ||
| } | ||
| } | ||
|
|
||
| for _, path := range candidates { | ||
| if _, err := os.Stat(path); err == nil { | ||
| return path | ||
| } | ||
| } | ||
|
|
||
| return "" | ||
| } | ||
|
|
||
| func (p *BoreProvider) Start(ctx context.Context, tunnel config.TunnelConfig, logWriter io.Writer) (*providers.Process, error) { | ||
| binary := p.FindBinary() | ||
| if binary == "" { | ||
| if err := p.installer.Install(nil); err != nil { | ||
| return nil, fmt.Errorf("failed to install bore: %w", err) | ||
| } | ||
| binary = p.installer.BoreBin() | ||
| } | ||
|
|
||
| ctx, cancel := context.WithCancel(ctx) | ||
|
|
||
| args := []string{ | ||
| "local", | ||
| fmt.Sprintf("%d", tunnel.LocalPort), | ||
| "--to", "bore.pub", | ||
| } | ||
|
|
||
| cmd := exec.CommandContext(ctx, binary, args...) | ||
| cmd.Stdout = logWriter | ||
| cmd.Stderr = logWriter | ||
|
|
||
| if err := cmd.Start(); err != nil { | ||
| cancel() | ||
| return nil, fmt.Errorf("failed to start bore: %w", err) | ||
| } | ||
|
|
||
| return &providers.Process{ | ||
| Cancel: cancel, | ||
| }, nil | ||
| } | ||
|
|
||
| var boreURLRegex = regexp.MustCompile(`bore\.pub:\d+`) | ||
|
|
||
| func (p *BoreProvider) ParseURL(line string) string { | ||
| matches := boreURLRegex.FindString(line) | ||
| if matches != "" { | ||
| return matches | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func (p *BoreProvider) IsReady(line string) bool { | ||
| lineLower := strings.ToLower(line) | ||
| return strings.Contains(lineLower, "bore.pub") && | ||
| (strings.Contains(lineLower, "listening") || strings.Contains(lineLower, "port")) | ||
| } | ||
This file contains hidden or 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,119 @@ | ||
| package bore | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
|
|
||
| "github.com/sthbryan/ftm/internal/providers" | ||
| ) | ||
|
|
||
| const boreVersion = "v0.6.0" | ||
|
|
||
| type Installer struct { | ||
| BaseDir string | ||
| } | ||
|
|
||
| func NewInstaller(baseDir string) *Installer { | ||
| return &Installer{BaseDir: baseDir} | ||
| } | ||
|
|
||
| func (i *Installer) BoreBin() string { | ||
| if runtime.GOOS == "windows" { | ||
| return filepath.Join(i.BaseDir, "bore.exe") | ||
| } | ||
| return filepath.Join(i.BaseDir, "bore") | ||
| } | ||
|
|
||
| func (i *Installer) IsInstalled() bool { | ||
| if _, err := os.Stat(i.BoreBin()); err == nil { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (i *Installer) Install(progress chan<- providers.DownloadProgress) error { | ||
| if err := os.MkdirAll(i.BaseDir, 0755); err != nil { | ||
| return fmt.Errorf("failed to create base dir: %w", err) | ||
| } | ||
|
|
||
| if i.IsInstalled() { | ||
| return nil | ||
| } | ||
|
|
||
| platform := runtime.GOOS | ||
| arch := runtime.GOARCH | ||
|
|
||
| var url string | ||
| var filename string | ||
|
|
||
| switch platform { | ||
| case "darwin": | ||
| switch arch { | ||
| case "arm64": | ||
| filename = "bore-" + boreVersion + "-aarch64-apple-darwin.tar.gz" | ||
| url = "https://github.com/ekzhang/bore/releases/download/" + boreVersion + "/" + filename | ||
| case "amd64": | ||
| filename = "bore-" + boreVersion + "-x86_64-apple-darwin.tar.gz" | ||
| url = "https://github.com/ekzhang/bore/releases/download/" + boreVersion + "/" + filename | ||
| default: | ||
| return fmt.Errorf("unsupported architecture for macOS: %s (supported: arm64, amd64)", arch) | ||
| } | ||
| case "linux": | ||
| switch arch { | ||
| case "arm64": | ||
| filename = "bore-" + boreVersion + "-aarch64-unknown-linux-musl.tar.gz" | ||
| url = "https://github.com/ekzhang/bore/releases/download/" + boreVersion + "/" + filename | ||
| case "amd64": | ||
| filename = "bore-" + boreVersion + "-x86_64-unknown-linux-musl.tar.gz" | ||
| url = "https://github.com/ekzhang/bore/releases/download/" + boreVersion + "/" + filename | ||
| default: | ||
| return fmt.Errorf("unsupported architecture for Linux: %s (supported: arm64, amd64)", arch) | ||
| } | ||
| case "windows": | ||
| if arch == "amd64" { | ||
| filename = "bore-" + boreVersion + "-x86_64-pc-windows-msvc.zip" | ||
| url = "https://github.com/ekzhang/bore/releases/download/" + boreVersion + "/" + filename | ||
| } else { | ||
| return fmt.Errorf("unsupported architecture for Windows: %s (supported: amd64)", arch) | ||
| } | ||
|
sthbryan marked this conversation as resolved.
sthbryan marked this conversation as resolved.
|
||
| default: | ||
| return fmt.Errorf("unsupported platform: %s", platform) | ||
| } | ||
|
sthbryan marked this conversation as resolved.
|
||
|
|
||
| destArchive := filepath.Join(i.BaseDir, filename) | ||
|
|
||
| if progress != nil { | ||
| progress <- providers.DownloadProgress{ | ||
| Percent: 10, | ||
| Current: 0, | ||
| Total: 100, | ||
| Name: "bore", | ||
| } | ||
| } | ||
|
|
||
| if err := providers.DownloadWithProgress(url, destArchive, progress, "bore"); err != nil { | ||
| return fmt.Errorf("failed to download bore: %w", err) | ||
| } | ||
|
|
||
| defer os.Remove(destArchive) | ||
|
|
||
| if err := providers.ExtractArchive(destArchive, i.BaseDir, "bore"); err != nil { | ||
| return fmt.Errorf("failed to extract bore: %w", err) | ||
| } | ||
|
sthbryan marked this conversation as resolved.
|
||
|
|
||
| if _, err := os.Stat(i.BoreBin()); err != nil { | ||
| return fmt.Errorf("binary not found after install: %w", err) | ||
| } | ||
|
|
||
| if progress != nil { | ||
| progress <- providers.DownloadProgress{ | ||
| Percent: 100, | ||
| Done: true, | ||
| Name: "bore", | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.