tunasync.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. name: tunasync
  2. on: [push, pull_request, workflow_dispatch]
  3. jobs:
  4. build:
  5. name: Build
  6. runs-on: ubuntu-latest
  7. steps:
  8. - name: Check out code into the Go module directory
  9. uses: actions/checkout@v4
  10. - name: Set up Go
  11. uses: actions/setup-go@v5
  12. with:
  13. go-version: '^1.22'
  14. id: go
  15. - name: Get dependencies
  16. run: |
  17. go get -v -t -d ./cmd/tunasync
  18. go get -v -t -d ./cmd/tunasynctl
  19. - name: Build
  20. run: |
  21. make tunasync
  22. make tunasynctl
  23. - name: Keep artifacts
  24. uses: actions/upload-artifact@v4
  25. with:
  26. name: tunasync-bin
  27. path: build-linux-amd64/
  28. test:
  29. name: Test
  30. runs-on: ubuntu-latest
  31. services:
  32. registry:
  33. image: registry:2
  34. ports:
  35. - 5000:5000
  36. steps:
  37. - name: Setup test dependencies
  38. run: |
  39. sudo apt-get update
  40. sudo apt-get install -y cgroup-tools
  41. docker pull alpine:3.8
  42. - name: Check out code into the Go module directory
  43. uses: actions/checkout@v4
  44. - name: Set up Go
  45. uses: actions/setup-go@v5
  46. with:
  47. go-version: '^1.22'
  48. id: go
  49. - name: Run Additional Unit tests.
  50. run: |
  51. make build-test-worker
  52. readelf --dyn-syms -W worker.test
  53. sudo mkdir /sys/fs/cgroup/tunasync
  54. sudo ./worker.test -test.v=true -test.coverprofile profile2.cov -test.run TestCgroup
  55. sudo rmdir /sys/fs/cgroup/tunasync
  56. touch /tmp/dummy_exec
  57. chmod +x /tmp/dummy_exec
  58. run_test_reexec (){
  59. case="$1"
  60. shift
  61. argv0="$1"
  62. shift
  63. (TESTREEXEC="$case" TERM=xterm-256color exec -a "$argv0" ./worker.test -test.v=true -test.coverprofile "profile5_$case.cov" -test.run TestReexec -- "$@")
  64. }
  65. run_test_reexec 1 tunasync-exec __dummy__
  66. run_test_reexec 2 tunasync-exec /tmp/dummy_exec
  67. run_test_reexec 3 tunasync-exec /tmp/dummy_exec 3< <(echo -n "abrt")
  68. run_test_reexec 4 tunasync-exec /tmp/dummy_exec 3< <(echo -n "cont")
  69. run_test_reexec 5 tunasync-exec2
  70. - name: Set up Docker Buildx
  71. uses: docker/setup-buildx-action@v3
  72. with:
  73. driver-opts: network=host
  74. - name: Cache Docker layers
  75. uses: actions/cache@v4
  76. if: github.event_name == 'push'
  77. with:
  78. path: /tmp/.buildx-cache
  79. key: ${{ runner.os }}-buildx-${{ github.sha }}
  80. restore-keys: |
  81. ${{ runner.os }}-buildx-
  82. - name: Cache Docker layers
  83. uses: actions/cache@v4
  84. if: github.event_name == 'pull_request'
  85. with:
  86. path: /tmp/.buildx-cache
  87. key: ${{ runner.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ github.sha }}
  88. restore-keys: |
  89. ${{ runner.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-
  90. ${{ runner.os }}-buildx-
  91. - name: Cache Docker layers
  92. if: github.event_name != 'push' && github.event_name != 'pull_request'
  93. run: |
  94. echo "I do not know how to setup cache"
  95. exit -1
  96. - name: Prepare cache directory
  97. run: |
  98. mkdir -p /tmp/.buildx-cache
  99. - name: Build Docker image for uml rootfs
  100. uses: docker/build-push-action@v6
  101. with:
  102. context: .umlrootfs
  103. file: .umlrootfs/Dockerfile
  104. push: true
  105. tags: localhost:5000/umlrootfs
  106. cache-from: type=local,src=/tmp/.buildx-cache
  107. cache-to: type=local,dest=/tmp/.buildx-cache
  108. - name: Fetch and install uml package
  109. run: |
  110. sudo apt-get update
  111. sudo apt-get install -y debian-archive-keyring
  112. sudo ln -sf /usr/share/keyrings/debian-archive-keyring.gpg /etc/apt/trusted.gpg.d/
  113. echo "deb http://deb.debian.org/debian bullseye main" | sudo tee /etc/apt/sources.list.d/bullseye.list
  114. sudo apt-get update
  115. apt-get download user-mode-linux/bullseye
  116. sudo rm /etc/apt/sources.list.d/bullseye.list
  117. sudo apt-get update
  118. sudo mv user-mode-linux_*.deb /tmp/uml.deb
  119. sudo apt-get install --no-install-recommends -y /tmp/uml.deb
  120. sudo rm /tmp/uml.deb
  121. sudo apt-get install --no-install-recommends -y rsh-redone-client
  122. - name: Prepare uml environment
  123. run: |
  124. docker container create --name umlrootfs localhost:5000/umlrootfs
  125. sudo mkdir -p umlrootfs
  126. docker container export umlrootfs | sudo tar -xv -C umlrootfs
  127. docker container rm umlrootfs
  128. sudo cp -a --target-directory=umlrootfs/lib/ /usr/lib/uml/modules
  129. /bin/echo -e "127.0.0.1 localhost\n254.255.255.1 host" | sudo tee umlrootfs/etc/hosts
  130. sudo ip tuntap add dev umltap mode tap
  131. sudo ip addr add 254.255.255.1/24 dev umltap
  132. sudo ip link set umltap up
  133. - name: Start Uml
  134. run: |
  135. start_uml () {
  136. sudo bash -c 'linux root=/dev/root rootflags=/ rw rootfstype=hostfs mem=2G eth0=tuntap,umltap hostfs="$PWD/umlrootfs" con1=pts systemd.unified_cgroup_hierarchy=0 & pid=$!; echo "UMLINUX_PID=$pid" >> '"$GITHUB_ENV"
  137. }
  138. ( start_uml )
  139. started=0
  140. for i in $(seq 1 60); do
  141. if ping -c 1 -w 1 254.255.255.2; then
  142. started=1
  143. break
  144. fi
  145. done
  146. if [ "$started" != "1" ]; then
  147. echo "Failed to wait Umlinux online"
  148. exit 1
  149. fi
  150. - name: Prepare Uml Environment
  151. run: |
  152. CUSER="$(id --user --name)"
  153. CUID="$(id --user)"
  154. CGID="$(id --group)"
  155. sudo chroot umlrootfs bash --noprofile --norc -eo pipefail << EOF
  156. groupadd --gid "${CGID?}" "${CUSER?}"
  157. useradd --create-home --home-dir "/home/${CUSER}" --gid "${CGID?}" \
  158. --uid "${CUID?}" --shell "\$(which bash)" "${CUSER?}"
  159. EOF
  160. ln ./worker.test "umlrootfs/home/${CUSER}/worker.test"
  161. - name: Run Tests in Cgroupv1
  162. run: |
  163. CUSER="$(id --user --name)"
  164. sudo rsh 254.255.255.2 bash --noprofile --norc -eo pipefail << EOF
  165. exec 2>&1
  166. cd "/home/${CUSER}"
  167. lssubsys -am
  168. cgcreate -a "$CUSER" -t "$CUSER" -g cpu:tunasync
  169. cgcreate -a "$CUSER" -t "$CUSER" -g memory:tunasync
  170. ls -la /sys/fs/cgroup/cpuacct
  171. ls -la /sys/fs/cgroup/cpu,cpuacct
  172. ls -la /sys/fs/cgroup/memory
  173. TERM=xterm-256color ./worker.test -test.v=true -test.coverprofile \
  174. profile3.cov -test.run TestCgroup
  175. cgexec -g "*:/" bash -c "echo 0 > /sys/fs/cgroup/systemd/tasks; exec sudo -u $CUSER env USECURCGROUP=1 TERM=xterm-256color cgexec -g cpu,memory:tunasync ./worker.test -test.v=true -test.coverprofile profile4.cov -test.run TestCgroup"
  176. EOF
  177. - name: Stop Uml
  178. run: |
  179. sudo rsh 254.255.255.2 systemctl poweroff
  180. sleep 10
  181. if [ -e "/proc/$UMLINUX_PID" ]; then
  182. sleep 10
  183. if [ -e "/proc/$UMLINUX_PID" ]; then
  184. sudo kill -TERM "$UMLINUX_PID" || true
  185. sleep 1
  186. fi
  187. fi
  188. if [ -e "/proc/$UMLINUX_PID" ]; then
  189. sleep 10
  190. if [ -e "/proc/$UMLINUX_PID" ]; then
  191. sudo kill -KILL "$UMLINUX_PID" || true
  192. sleep 1
  193. fi
  194. fi
  195. - name: Combine coverage files
  196. run : |
  197. CUSER="$(id --user --name)"
  198. "${HOME}/go/bin/gocovmerge" profile.cov profile2.cov \
  199. "umlrootfs/home/${CUSER}/profile3.cov" \
  200. "umlrootfs/home/${CUSER}/profile4.cov" \
  201. profile5_*.cov > profile-all.cov
  202. - name: Convert coverage to lcov
  203. uses: jandelgado/gcov2lcov-action@v1
  204. with:
  205. infile: profile-all.cov
  206. outfile: coverage.lcov
  207. - name: Coveralls
  208. uses: coverallsapp/github-action@v2
  209. with:
  210. github-token: ${{ secrets.github_token }}
  211. path-to-lcov: coverage.lcov