-
Notifications
You must be signed in to change notification settings - Fork 683
Plain mode: support port forwarding #3699
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
Draft
Horiodino
wants to merge
4
commits into
lima-vm:master
Choose a base branch
from
Horiodino:port-forwarding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
# SPDX-FileCopyrightText: Copyright The Lima Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -euxo pipefail | ||
|
||
INSTANCE=nonplain-static-port-forward | ||
TEMPLATE=hack/test-templates/static-port-forward.yaml | ||
|
||
limactl delete -f $INSTANCE || true | ||
|
||
limactl start --name=$INSTANCE --tty=false $TEMPLATE | ||
|
||
limactl shell $INSTANCE -- bash -c 'until [ -e /run/nginx.pid ]; do sleep 1; done' | ||
limactl shell $INSTANCE -- bash -c 'until systemctl is-active --quiet test-server-9080; do sleep 1; done' | ||
limactl shell $INSTANCE -- bash -c 'until systemctl is-active --quiet test-server-9070; do sleep 1; done' | ||
|
||
curl -sSf http://127.0.0.1:9090 | grep -i 'nginx' && echo 'Static port forwarding (9090) works in normal mode!' | ||
curl -sSf http://127.0.0.1:9080 | grep -i 'Dynamic port 9080' && echo 'Dynamic port forwarding (9080) works in normal mode!' | ||
curl -sSf http://127.0.0.1:9070 | grep -i 'Dynamic port 9070' && echo 'Dynamic port forwarding (9070) works in normal mode!' | ||
|
||
limactl delete -f $INSTANCE | ||
echo "All tests passed for normal mode - both static and dynamic ports work!" | ||
# EOF |
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,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
# SPDX-FileCopyrightText: Copyright The Lima Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -euxo pipefail | ||
|
||
INSTANCE=plain-static-port-forward | ||
TEMPLATE=hack/test-templates/static-port-forward.yaml | ||
|
||
limactl delete -f $INSTANCE || true | ||
|
||
limactl start --name=$INSTANCE --plain=true --tty=false $TEMPLATE | ||
|
||
limactl shell $INSTANCE -- bash -c 'until [ -e /run/nginx.pid ]; do sleep 1; done' | ||
|
||
curl -sSf http://127.0.0.1:9090 | grep -i 'nginx' && echo 'Static port forwarding (9090) works in plain mode!' | ||
|
||
if curl -sSf http://127.0.0.1:9080 2>/dev/null; then | ||
echo 'ERROR: Dynamic port 9080 should not be forwarded in plain mode!' | ||
exit 1 | ||
else | ||
echo 'Dynamic port 9080 is correctly NOT forwarded in plain mode.' | ||
fi | ||
|
||
if curl -sSf http://127.0.0.1:9070 2>/dev/null; then | ||
echo 'ERROR: Dynamic port 9070 should not be forwarded in plain mode!' | ||
exit 1 | ||
else | ||
echo 'Dynamic port 9070 is correctly NOT forwarded in plain mode.' | ||
fi | ||
|
||
limactl delete -f $INSTANCE | ||
echo "All tests passed for plain mode - only static ports work!" | ||
# EOF |
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,64 @@ | ||
images: | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" | ||
arch: "x86_64" | ||
|
||
provision: | ||
- mode: system | ||
script: | | ||
apt-get update | ||
apt-get install -y nginx python3 | ||
systemctl enable nginx | ||
systemctl start nginx | ||
|
||
cat > /etc/systemd/system/test-server-9080.service << 'EOF' | ||
[Unit] | ||
Description=Test Server on Port 9080 | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
User=root | ||
ExecStart=/usr/bin/python3 -m http.server 9080 --bind 127.0.0.1 | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
cat > /etc/systemd/system/test-server-9070.service << 'EOF' | ||
[Unit] | ||
Description=Test Server on Port 9070 | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
User=root | ||
ExecStart=/usr/bin/python3 -m http.server 9070 --bind 127.0.0.1 | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
mkdir -p /var/www/html-9080 | ||
mkdir -p /var/www/html-9070 | ||
|
||
echo '<html><body><h1>Dynamic port 9080</h1></body></html>' > /var/www/html-9080/index.html | ||
echo '<html><body><h1>Dynamic port 9070</h1></body></html>' > /var/www/html-9070/index.html | ||
|
||
systemctl daemon-reload | ||
systemctl enable test-server-9080 | ||
systemctl enable test-server-9070 | ||
systemctl start test-server-9080 | ||
systemctl start test-server-9070 | ||
|
||
portForwards: | ||
- guestPort: 80 | ||
hostPort: 9090 | ||
static: true | ||
- guestPort: 9080 | ||
hostPort: 9080 | ||
static: false | ||
- guestPort: 9070 | ||
hostPort: 9070 | ||
static: false |
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.