2
0

tunasync.yml 7.8 KB

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