tunasync.yml 7.1 KB

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