Skip to content

Commit

Permalink
Merge pull request #2 from bjia56/nfs
Browse files Browse the repository at this point in the history
Add support for NFS sync
  • Loading branch information
Neilpang authored Dec 25, 2024
2 parents 22b9074 + 16fd3ca commit 5a7529f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/tpl/README.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


```
Expand All @@ -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}}
Expand Down
58 changes: 58 additions & 0 deletions .github/tpl/test.tpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
}
Expand Down
24 changes: 24 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <hooks/onRunNFS.sh; then
echo "OK";
elif [ "$VM_NFS_CMD" ]; then
echo "Configuring NFS in VM"
ssh "$osname" sh <<EOF
$VM_NFS_CMD
EOF
echo "Done with NFS"
else
echo "Configuring NFS in VM with default command"
ssh "$osname" sh <<EOF
mount 192.168.122.1:$HOME/work \$HOME/work
EOF
echo "Done with NFS"
fi
}


#run in the vm, just as soon as the vm is up
onStarted() {
Expand Down

0 comments on commit 5a7529f

Please sign in to comment.