Skip to content

🆕 Devcontainer support, Docker support and IPv6 inside container fix#191

Open
aviadhahami wants to merge 11 commits intonfx:mainfrom
aviadhahami:main
Open

🆕 Devcontainer support, Docker support and IPv6 inside container fix#191
aviadhahami wants to merge 11 commits intonfx:mainfrom
aviadhahami:main

Conversation

@aviadhahami
Copy link
Copy Markdown

@aviadhahami aviadhahami commented Jan 29, 2024

Heya! I wanted to fix some bugs in this project (ie #178 #181 ) but I wasn't able to consistently build this project.
So first - I added devcontainer support a580a8f

see devcontainers

Then, I addressed #170 by updating the Dockerfile to fully build and ship the project as a linked binary inside an Alpine image.
I then also fixed #178.

So, the current status is that the code is usable via docker and we can also work on the same env via devcontainer.
Will update the readme with an example command to run via docker

Awesome project btw!

Follow-up work:
I am unable, as of now, to fix #181 and I keep hitting the same error. Any idea? might be around HTTPS

@aviadhahami aviadhahami changed the title 🆕 new: devcontainer support 🆕 devcontainer support Jan 29, 2024
@aviadhahami aviadhahami changed the title 🆕 devcontainer support 🆕 Devcontainer support, Docker support and IPv6 inside container fix Jan 29, 2024
@CyrilDesch
Copy link
Copy Markdown

CyrilDesch commented Feb 3, 2024

You have problem with the UI. When go to http://localhost:8089/, we have "missing UI"
I found the solution, I made a pull request on your repo to resolve Dockerfile (and explain the problem)


build-go-for-docker:
go mod vendor
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags "-s -w" -o main main.go
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use cgo here at all, pls remove

Copy link
Copy Markdown
Author

@aviadhahami aviadhahami Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, tho when running the project on Alpine it fails unless compiling w/ CGO.
The CGO is also used here: https://github.com/nfx/slrp/blob/main/.goreleaser.yaml#L13.
This topic specifically was previously discussed here: #90 (comment)

"...but slrp must be build with static linkage CGO_ENABLED=0 I believe..."

wdyt?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the situation where a code comment could have avoided a review comment 😉

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add the comment where needed ;)

// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forward the 8089 and 8090 ports

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add them explicitly but note that once the project is running they are auto-forwarded by vscode.
Adding these two port will make them perma-accessible, which is what I wanted to avoid.

Would you like me to add them permanently?

Attaching a screenshot of how the vscode panel looks once the project is running in debug mode
image

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/postcreate.sh",

// Configure tool-specific properties.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are not required

// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need root?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w/o the container can't init nvm (run source ~/.bashrc) properly.
Since this is only for the devcontainer, I think it's fine security-wise

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"name": "Go",
"name": "slrp dev",

Maybe this?

"image": "mcr.microsoft.com/devcontainers/go:1-1.20-bookworm",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove


# Check if we don't have nvm, if no - install it
echo "[ + ] Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull nvm version to a variable

@aviadhahami
Copy link
Copy Markdown
Author

@nfx addressed your comments and rebased on top of your master :) take a look lmk what u think

Copy link
Copy Markdown
Owner

@nfx nfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly lgtm, but I have to manually look at the introduced third party dependencies before merging.

Thanks for your help 🎊

@nfx
Copy link
Copy Markdown
Owner

nfx commented Feb 23, 2024

@CyrilDesch You have to make a PR from your repo to this repo 😉

@aviadhahami
Copy link
Copy Markdown
Author

update: rebased and addressed review comments.

@nfx - @CyrilDesch already PRed to my repo (🎉 ), commit is 0a72c77

README.md Outdated
Run `make docker`. Once done, invoke with `docker run -p 8089:8089 -p 8090:8090 -v $HOME/.slrp/data:/data nfx/slrp:latest`

Once running, you can access the UI at [http://localhost:8089/](http://localhost:8089/) and the proxy at [http://localhost:8090/](http://localhost:8090/)
Test using a simple curl command `curl --proxy-insecure -D - -x http:// http://127.0.0.1:8090 -k http://httpbin.org/get` couple of times and see different origins and user agent headers.
Copy link
Copy Markdown

@muzso muzso Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be an extra http:// in the curl example command.

So instead of this:
curl --proxy-insecure -D - -x http:// http://127.0.0.1:8090 -k http://httpbin.org/get

It should be this:
curl --proxy-insecure -D - -x http://127.0.0.1:8090 -k http://httpbin.org/get

The -k curl option is only necessary if the target URL uses https, so either the -k can be dropped, or the target URL changed into https://httpbin.org/get.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using slrp as a proxy seems to require a https connection (to the proxy).
The --proxy-insecure option in the example suggests this as well.
But the example uses plain http:// for the proxy URL.

So the correct example is:
curl --proxy-insecure -D - -x "https://127.0.0.1:8090" "http://httpbin.org/get"

Or this:
curl --proxy-insecure -D - -x "https://127.0.0.1:8090" -k "https://httpbin.org/get"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍

pmux/proxy.go Outdated
// proxy package(or so). Hence we replace it with 0.0.0.0
if strings.Contains(addr, "[::]") {
// Set it to 0.0.0.0 but maintain the port
fmt.Println("Encountered [::]: in address, replacing with 0.0.0.0")
Copy link
Copy Markdown

@muzso muzso Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a call to log.Info() instead of directly writing to stdout?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 👍

pmux/proxy.go Outdated

addrPort, err := netip.ParseAddrPort(addr)
if err != nil {
fmt.Println("Error parsing address:", err)
Copy link
Copy Markdown

@muzso muzso Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a call to log.Info() instead of directly writing to stdout?

Using log instead of stdout
@aviadhahami
Copy link
Copy Markdown
Author

Hey @nfx - any updates on this? :)

@accforgithubtest
Copy link
Copy Markdown

Hey @nfx - any indications of when this might be merged pls ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty reply from server Can't run v0.3.0 binary in Docker: panic: As4 called on IPv6 address

5 participants