Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Neilpang committed Nov 21, 2023
1 parent a1bf6ab commit 2deb392
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 34 deletions.
12 changes: 6 additions & 6 deletions .github/tpl/README.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
MYTOKEN : ${{ secrets.MYTOKEN }}
MYTOKEN2: "value2"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test in {{VM_NAME}}
id: test
uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}}
Expand Down Expand Up @@ -72,7 +72,7 @@ The code is shared from the host to the VM via `rsync`, you can choose to use to
...
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test
id: test
uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}}
Expand All @@ -99,7 +99,7 @@ When using `rsync`, you can define `copyback: false` to not copy files back fro
...
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test
id: test
uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}}
Expand All @@ -125,7 +125,7 @@ You can add NAT port between the host and the VM.
```
...
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test
id: test
uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}}
Expand All @@ -145,7 +145,7 @@ The default memory of the VM is 6144MB, you can use `mem` option to set the memo
```
...
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test
id: test
uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}}
Expand All @@ -163,7 +163,7 @@ It uses [the latest {{VM_NAME}} {{DEFAULT_RELEASE}}](conf/default.release.conf)
```
...
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test
id: test
uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
VM_RELEASE: ${{ secrets.VM_RELEASE }}
SEC_VBOX : ${{ secrets.SEC_VBOX }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: vmactions/cf-tunnel@v0
id: tunnel
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get latest release
id: get-latest-release
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
MYTOKEN2: "value2"
SEC_VBOX : ${{ secrets.SEC_VBOX }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test in Solaris
id: test
uses: vmactions/solaris-vm@main
uses: vmactions/solaris-vm@a1bf6ab4cd8352772b1debbb01ee9e132b0d6d9c
with:
envs: 'MYTOKEN MYTOKEN2'
prepare: |
Expand All @@ -49,6 +49,7 @@ jobs:
copyback: false
release: ${{ matrix.release }}
nat: |
"10022": "22"
"8080": "80"
"8443": "443"
udp:"8081": "80"
Expand All @@ -57,6 +58,9 @@ jobs:
run: |
tree .
tree $HOME/work/
- name: Test NAT
run:
ssh -p 10022 -i $HOME/.ssh/host.id_rsa root@localhost "uname -a;whoami;pwd"

test:
strategy:
Expand All @@ -70,10 +74,10 @@ jobs:
MYTOKEN2: "value2"
SEC_VBOX : ${{ secrets.SEC_VBOX }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Test in Solaris
id: test
uses: vmactions/solaris-vm@main
uses: vmactions/solaris-vm@a1bf6ab4cd8352772b1debbb01ee9e132b0d6d9c
with:
envs: 'MYTOKEN MYTOKEN2'
prepare: |
Expand All @@ -82,6 +86,7 @@ jobs:
copyback: false
release: ${{ matrix.release }}
nat: |
"10022": "22"
"8080": "80"
"8443": "443"
udp:"8081": "80"
Expand All @@ -100,6 +105,9 @@ jobs:
psrinfo -vp
cat /etc/release
echo "OK"
- name: Test NAT
run:
ssh -p 10022 -i $HOME/.ssh/host.id_rsa root@localhost "uname -a;whoami;pwd"



Expand Down
44 changes: 24 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,7 @@ async function setup(nat, mem) {
core.endGroup();

core.startGroup("Set VM");
if (nat) {
let nats = nat.split("\n").filter(x => x !== "");
for (let element of nats) {
core.info("Add nat: " + element);
let segs = element.split(":");
if (segs.length === 3) {
//udp:"8081": "80"
let proto = segs[0].trim().trim('"');
let hostPort = segs[1].trim().trim('"');
let vmPort = segs[2].trim().trim('"');

await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort);

} else if (segs.length === 2) {
let proto = "tcp"
let hostPort = segs[0].trim().trim('"');
let vmPort = segs[1].trim().trim('"');
await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort);
}
};
}

if (mem) {
await shell("bash run.sh setMemory " + mem);
Expand All @@ -82,6 +62,30 @@ async function setup(nat, mem) {
core.endGroup();

core.startGroup("Run onStarted in VM");

if (nat) {
let nats = nat.split("\n").filter(x => x !== "");
for (let element of nats) {
core.info("Add nat: " + element);
let segs = element.split(":");
if (segs.length === 3) {
//udp:"8081": "80"
let proto = segs[0].trim().trim('"');
let hostPort = segs[1].trim().trim('"');
let vmPort = segs[2].trim().trim('"');

await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort);

} else if (segs.length === 2) {
let proto = "tcp"
let hostPort = segs[0].trim().trim('"');
let vmPort = segs[1].trim().trim('"');
await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort);
}
};
}


await shell("bash run.sh onStarted" );
core.endGroup();

Expand Down
22 changes: 20 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,25 @@ execSSHSH() {


addNAT() {
bash $vmsh addNAT "$osname" "$@"
_prot="$1"
_hostport="$2"
_vmport="$3"
_vmip=$(bash $vmsh getVMIP "$osname")

if ! command -v socat; then
if bash $vmsh isLinux; then
sudo apt-get install -y socat
else
brew install socat
fi
fi

if [ "$_prot" == "udp" ]; then
sudo socat UDP4-RECVFROM:$_hostport,fork UDP4-SENDTO:$_vmip:$_vmport &
else
sudo socat TCP-LISTEN:$_hostport,fork TCP:$_vmip:$_vmport &
fi

}

setMemory() {
Expand Down Expand Up @@ -244,7 +262,7 @@ waitForBooting() {

showDebugInfo() {
echo "==================Debug Info===================="
pwd && ls -lah
pwd && ls -lah && sudo ps aux
bash -c 'pwd && ls -lah ~/.ssh/ && [ -e "~/.ssh/config" ] && cat ~/.ssh/config'
cat $_conf_filename

Expand Down

0 comments on commit 2deb392

Please sign in to comment.