-
Notifications
You must be signed in to change notification settings - Fork 27
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
🆕 Devcontainer support, Docker support and IPv6 inside container fix #191
base: main
Are you sure you want to change the base?
Changes from 9 commits
2b92213
121dee7
d8e7f27
540968c
55f404a
0a72c77
6cc45bf
d5f37a3
8be8cfa
807db30
2a4d874
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "slrp dev", | ||
"image": "mcr.microsoft.com/devcontainers/go:1-1.20-bookworm", | ||
"postCreateCommand": ".devcontainer/postcreate.sh", | ||
"remoteUser": "root", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"foxundermoon.shell-format", | ||
"GitHub.copilot", | ||
"eamodio.gitlens", | ||
"ms-vscode.makefile-tools", | ||
"ms-azuretools.vscode-docker" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
NVM_VERSION="0.38.0" | ||
NODE_VERSION="20" | ||
|
||
# # If you're developing in a container behind a VPNed/MDM-managed machine you might get "self signed certs in chain" error. | ||
# # This snippet below bypasses that (ssl is required later for nvm installation) | ||
# apt update && apt install -y git | ||
# git config --global http.sslVerify false | ||
|
||
echo "[ + ] Running post-create script. Installing the following:" | ||
echo "[ + ] NVM version: $NVM_VERSION" | ||
echo "[ + ] NodeJS version: $NODE_VERSION" | ||
echo "[ + ] ==============================" | ||
|
||
# Check if we don't have nvm, if no - install it | ||
echo "[ + ] Installing nvm at v$NVM_VERSION" | ||
|
||
curl -k -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$NVM_VERSION/install.sh | bash | ||
# Activate nvm | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
|
||
# Refresh bash | ||
source ~/.bashrc | ||
|
||
# Install node at a set versions | ||
echo "[ + ] Installing NodeJS at v$NODE_VERSION" | ||
nvm install $NODE_VERSION && nvm use $NODE_VERSION | ||
|
||
echo "[ + ] Installing UI dependencies and building..." | ||
# Change to the "ui" directory | ||
cd ui && npm install && cd ../ | ||
|
||
echo "[ + ] Installing Go dependencies and building..." | ||
make build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
// Run the main.go program | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "debug", | ||
"program": "${workspaceFolder}/main.go", | ||
"env": {}, | ||
"args": [] | ||
}, | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
FROM alpine | ||
# Install node and deps to build the frontend | ||
FROM node:20.11-bookworm AS NODE_INSTALL | ||
WORKDIR /app | ||
COPY . . | ||
RUN npm --prefix ui install && \ | ||
npm --prefix ui run build | ||
|
||
ENV PWD="/app" | ||
# Install go and deps to build the backend | ||
FROM golang:1.20.13-bookworm AS BUILD | ||
WORKDIR /app | ||
COPY --from=NODE_INSTALL /app . | ||
RUN make build-go-for-docker | ||
|
||
# Final image | ||
FROM alpine:latest | ||
# SLRP configuration environment variables | ||
ENV SLRP_APP_STATE="$PWD/.slrp/data" | ||
ENV SLRP_APP_SYNC="1m" | ||
ENV SLRP_LOG_LEVEL="info" | ||
ENV SLRP_LOG_FORMAT="pretty" | ||
ENV SLRP_SERVER_ADDR="0.0.0.0:8089" | ||
ENV SLRP_SERVER_READ_TIMEOUT="15s" | ||
ENV SLRP_MITM_ADDR="0.0.0.0:8090" | ||
ENV SLRP_MITM_READ_TIMEOUT="15s" | ||
ENV SLRP_MITM_IDLE_TIMEOUT="15s" | ||
ENV SLRP_MITM_WRITE_TIMEOUT="15s" | ||
ENV SLRP_CHECKER_TIMEOUT="5s" | ||
ENV SLRP_CHECKER_STRATEGY="simple" | ||
ENV SLRP_HISTORY_LIMIT="1000" | ||
|
||
WORKDIR $PWD | ||
COPY slrp $PWD | ||
|
||
RUN mkdir ./.slrp | ||
|
||
ENV SLRP_APP_STATE="/opt/.slrp/data" \ | ||
SLRP_APP_SYNC="1m" \ | ||
SLRP_LOG_LEVEL="info" \ | ||
SLRP_LOG_FORMAT="pretty" \ | ||
SLRP_SERVER_ADDR="0.0.0.0:8089" \ | ||
SLRP_SERVER_READ_TIMEOUT="15s" \ | ||
SLRP_MITM_ADDR="0.0.0.0:8090" \ | ||
SLRP_MITM_READ_TIMEOUT="15s" \ | ||
SLRP_MITM_IDLE_TIMEOUT="15s" \ | ||
SLRP_MITM_WRITE_TIMEOUT="15s" \ | ||
SLRP_CHECKER_TIMEOUT="5s" \ | ||
SLRP_CHECKER_STRATEGY="simple" \ | ||
SLRP_HISTORY_LIMIT="1000" | ||
WORKDIR /opt | ||
COPY --from=BUILD /app/main /opt/slrp | ||
RUN mkdir -p ./.slrp/data | ||
EXPOSE 8089 8090 | ||
|
||
CMD ["./slrp"] | ||
CMD ["/opt/slrp"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,14 @@ build: build-ui | |
go mod vendor | ||
go build -ldflags "-s -w" main.go | ||
|
||
# When running inside Alpine images there are no classic OS packages/binaries enabled, hence - we compile statically (CGO) | ||
build-go-for-docker: | ||
go mod vendor | ||
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags "-s -w" -o main main.go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use cgo here at all, pls remove There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will add the comment where needed ;) |
||
|
||
docker: | ||
docker build -t slrp:latest . | ||
|
||
quick: | ||
go build | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,17 @@ SLRP - rotating open proxy multiplexer | |
* Packaged as a single executable binary, that also includes Web UI | ||
|
||
# Usage | ||
For all methods, wait couple of minutes for the pool to pick up. Check the dashboard at [http://localhost:8089/](http://localhost:8089/) for progress. | ||
|
||
Download service, start it up, wait couple of minutes for the pool to pick up. Now run `curl --proxy-insecure -D - -x http://127.0.0.1:8090 -k http://httpbin.org/get` couple of times and see different origins and user agent headers. | ||
## Via binary | ||
Download the binary from the releases, which can be found [here](https://github.com/nfx/slrp/releases) | ||
|
||
## Via Docker | ||
> Assuming you have docker and make present | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be an extra So instead of this: It should be this: The There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). So the correct example is: Or this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated 👍 |
||
|
||
# Concepts | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,8 +247,18 @@ func NewProxyFromURL(url string) Proxy { | |
} | ||
|
||
func NewProxy(addr string, t string) Proxy { | ||
// Check if the address is valid or contains "[::]"; This happens when running inside a docker container | ||
// It means that the address is listening on all interfaces but via IPv6, which is not supported by the | ||
// 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be a call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed 👍 |
||
addr = strings.Replace(addr, "[::]", "0.0.0.0", 1) | ||
} | ||
|
||
addrPort, err := netip.ParseAddrPort(addr) | ||
if err != nil { | ||
fmt.Println("Error parsing address:", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be a call to |
||
return 0 | ||
} | ||
p, ok := protoMap[t] | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
(runsource ~/.bashrc
) properly.Since this is only for the devcontainer, I think it's fine security-wise