diff --git a/.github/tpl/README.tpl.md b/.github/tpl/README.tpl.md index 9559761..6dfa10e 100644 --- a/.github/tpl/README.tpl.md +++ b/.github/tpl/README.tpl.md @@ -68,7 +68,7 @@ So, you will have the same directory and same default env variables when you `ru ## 2. Share code -The code is shared from the host to the VM via `rsync` by default, you can choose to use to `sshfs` share code instead. +The code is shared from the host to the VM via `rsync` by default, you can choose to use to `sshfs` or `nfs` share code instead. ``` @@ -83,7 +83,7 @@ The code is shared from the host to the VM via `rsync` by default, you can choos with: envs: 'MYTOKEN MYTOKEN2' usesh: true - sync: sshfs + sync: sshfs # or: nfs prepare: | {{VM_PREPARE}} diff --git a/.github/tpl/test.tpl.yml b/.github/tpl/test.tpl.yml index a9680d5..cdeda1b 100644 --- a/.github/tpl/test.tpl.yml +++ b/.github/tpl/test.tpl.yml @@ -83,6 +83,64 @@ jobs: pwd {{VM_RUN}} + testnfs: + strategy: + matrix: + release: [ {{TEST_RELEASES}}, ""] + runs: [ "ubuntu-22.04", "ubuntu-24.04", "ubuntu-latest"] + runs-on: ${{ matrix.runs }} + name: nfs {{VM_NAME}} + env: + MYTOKEN : ${{ secrets.MYTOKEN }} + MYTOKEN2: "value2" + SEC_VBOX : ${{ secrets.SEC_VBOX }} + DEBUG: 1 + steps: + - uses: actions/checkout@v4 + - name: Creating Web console + uses: vmactions/cf-tunnel@v0 + id: tunnel + with: + protocol: http + port: 8000 + - name: Test in {{VM_NAME}} + id: test + uses: {{GITHUB_REPOSITORY}}@{{GITHUB_SHA}} + with: + envs: 'DEBUG MYTOKEN MYTOKEN2' + prepare: | + {{VM_PREPARE}} + release: ${{ matrix.release }} + nat: | + "10022": "22" + "8080": "80" + "8443": "443" + udp:"8081": "80" + usesh: true + sync: nfs + run: | + ls -lah /root/work + tree $HOME/work/ + if [ -z "$(ls -A $HOME/work)" ]; then + echo "nfs error." + exit 1 + fi + echo "TEST_ENV=abc" >>${GITHUB_ENV} +{{VM_RUN}} + + - name: Test NAT + run: + echo "TEST_ENV=$TEST_ENV" + [ "$TEST_ENV" = "abc" ] + ssh -vvv -p 10022 -i $HOME/.ssh/host.id_rsa root@localhost "uname -a;whoami;pwd" + - name: Test custom shell + shell: {{VM_OS_NAME}} {0} + run: | + pwd + cd $GITHUB_WORKSPACE; + pwd +{{VM_RUN}} + test: strategy: diff --git a/index.js b/index.js index a3405ef..e167284 100644 --- a/index.js +++ b/index.js @@ -95,6 +95,9 @@ async function setup(nat, mem, cpu) { } else if (sync == "sshfs") { core.info("Setup sshfs"); await shell("bash run.sh runSSHFSInVM"); + } else if (sync == "nfs") { + core.info("Setup nfs"); + await shell("bash run.sh runNFSInVM"); } else { await shell("bash run.sh installRsyncInVM"); await shell("bash run.sh rsyncToVM"); @@ -193,7 +196,7 @@ async function main() { let sync = core.getInput("sync"); if(sync == "no") { core.info("don't get back by rsync"); - } else if (sync != "sshfs") { + } else if (sync != "sshfs" && sync != "nfs") { core.info("get back by rsync"); await exec.exec("bash " + workingDir + "/run.sh rsyncBackFromVM"); } diff --git a/run.sh b/run.sh index b81af10..a60b944 100644 --- a/run.sh +++ b/run.sh @@ -60,6 +60,7 @@ export VM_OS_NAME export VM_RELEASE export VM_INSTALL_CMD export VM_SSHFS_PKG +export VM_NFS_CMD export VM_LOGIN_TAG export VM_OCR export VM_DISK @@ -275,6 +276,29 @@ EOF } +runNFSInVM() { + echo "Installing NFS on host" + sudo apt-get install -y nfs-kernel-server + echo "$HOME/work *(rw,async,no_subtree_check,anonuid=$(id -u),anongid=$(id -g))" | sudo tee -a /etc/exports + sudo exportfs -a + + if [ -e "hooks/onRunNFS.sh" ] && ssh "$osname" env "RUNNER_HOME=$HOME" sh