1name: CI
2on:
3  push:
4    branches:
5      - master
6      - 'release/**'
7  pull_request:
8    branches:
9      - master
10      - 'release/**'
11
12jobs:
13  #
14  # golangci-lint
15  #
16  linters:
17    name: Linters
18    runs-on: ${{ matrix.os }}
19    timeout-minutes: 10
20
21    strategy:
22      matrix:
23        go-version: [1.16.6]
24        os: [ubuntu-18.04, macos-10.15, windows-2019]
25
26    steps:
27      - uses: actions/checkout@v2
28        with:
29          path: src/github.com/containerd/containerd
30
31      - name: Set env
32        shell: bash
33        run: |
34          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
35          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
36
37      - uses: golangci/golangci-lint-action@v2
38        with:
39          version: v1.36.0
40          working-directory: src/github.com/containerd/containerd
41          args: --timeout=5m
42
43  #
44  # Project checks
45  #
46  project:
47    name: Project Checks
48    runs-on: ubuntu-18.04
49    timeout-minutes: 5
50
51    steps:
52      - uses: actions/setup-go@v2
53        with:
54          go-version: '1.16.6'
55
56      - shell: bash
57        run: |
58          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
59          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
60
61      - uses: actions/checkout@v2
62        with:
63          path: src/github.com/containerd/containerd
64          fetch-depth: 100
65
66      - uses: containerd/project-checks@v1
67        with:
68          working-directory: src/github.com/containerd/containerd
69
70  #
71  # Protobuf checks
72  #
73  protos:
74    name: Protobuf
75    runs-on: ubuntu-18.04
76    timeout-minutes: 5
77
78    defaults:
79      run:
80        working-directory: src/github.com/containerd/containerd
81
82    steps:
83      - uses: actions/setup-go@v2
84        with:
85          go-version: '1.16.6'
86
87      - uses: actions/checkout@v2
88        with:
89          path: src/github.com/containerd/containerd
90
91      - name: Set env
92        shell: bash
93        run: |
94          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
95          echo "GO111MODULE=off" >> $GITHUB_ENV
96          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
97
98      - name: Install protobuf
99        run: |
100          sudo -E PATH=$PATH script/setup/install-protobuf
101          sudo chmod +x /usr/local/bin/protoc
102          sudo chmod og+rx /usr/local/include/google /usr/local/include/google/protobuf /usr/local/include/google/protobuf/compiler
103          sudo chmod -R og+r /usr/local/include/google/protobuf/
104          protoc --version
105
106      - run: script/setup/install-dev-tools
107      - run: make proto-fmt
108      - run: make check-protos check-api-descriptors
109
110  man:
111    name: Manpages
112    runs-on: ubuntu-18.04
113    timeout-minutes: 5
114
115    steps:
116      - uses: actions/setup-go@v2
117        with:
118          go-version: '1.16.6'
119
120      - name: Set env
121        shell: bash
122        run: |
123          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
124          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
125
126      - uses: actions/checkout@v2
127        with:
128          path: src/github.com/containerd/containerd
129
130      - run: GO111MODULE=on go get github.com/cpuguy83/go-md2man/v2@v2.0.0
131
132      - run: make man
133        working-directory: src/github.com/containerd/containerd
134
135  # Make sure binaries compile with other platforms
136  crossbuild:
137    name: Crossbuild Binaries
138    needs: [project, linters, protos, man]
139    runs-on: ubuntu-18.04
140    timeout-minutes: 10
141    strategy:
142      fail-fast: false
143      matrix:
144        include:
145          - goos: linux
146            goarch: arm64
147          - goos: linux
148            goarch: arm
149            goarm: "7"
150          - goos: linux
151            goarch: arm
152            goarm: "5"
153          - goos: freebsd
154            goarch: amd64
155          - goos: freebsd
156            goarch: arm64
157          - goos: windows
158            goarch: arm
159            goarm: "7"
160
161    steps:
162      - uses: actions/setup-go@v2
163        with:
164          go-version: '1.16.6'
165      - name: Set env
166        shell: bash
167        run: |
168          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
169          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
170      - uses: actions/checkout@v2
171        with:
172          path: src/github.com/containerd/containerd
173      - run: |
174          set -e -x
175
176          packages=""
177          platform="${{matrix.goos}}/${{matrix.goarch}}"
178          if [ -n "${{matrix.goarm}}" ]; then
179            platform+="/v${{matrix.goarm}}"
180          fi
181
182          case "${platform}" in
183          linux/arm/v5)
184            packages+=" crossbuild-essential-armel"
185            echo "CGO_ENABLED=1" >> $GITHUB_ENV
186            echo "CC=arm-linux-gnueabi-gcc" >> $GITHUB_ENV
187            ;;
188          linux/arm/v7)
189            packages+=" crossbuild-essential-armhf"
190            echo "CGO_ENABLED=1" >> $GITHUB_ENV
191            echo "CC=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV
192            ;;
193          linux/arm64)
194            packages+=" crossbuild-essential-arm64"
195            echo "CGO_ENABLED=1" >> $GITHUB_ENV
196            echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
197            ;;
198          windows/arm/v7)
199            echo "CGO_ENABLED=0" >> $GITHUB_ENV
200            ;;
201          esac
202
203          if [ -n "${packages}" ]; then
204            sudo apt-get update && sudo apt-get install -y ${packages}
205          fi
206        name: install deps
207      - name: Build
208        working-directory: src/github.com/containerd/containerd
209        env:
210          GOOS: ${{matrix.goos}}
211          GOARCH: ${{matrix.goarch}}
212          GOARM: ${{matrix.goarm}}
213        run: |
214          make build
215          make binaries
216
217  #
218  # Build containerd binaries
219  #
220  binaries:
221    name: Binaries
222    runs-on: ${{ matrix.os }}
223    timeout-minutes: 10
224    needs: [project, linters, protos, man]
225
226    strategy:
227      matrix:
228        os: [ubuntu-18.04, macos-10.15, windows-2019]
229        go-version: ['1.16.6']
230        include:
231          # Go 1.13.x is still used by Docker/Moby
232          - go-version: '1.13.x'
233            os: ubuntu-18.04
234
235    steps:
236      - uses: actions/setup-go@v2
237        with:
238          go-version: ${{ matrix.go-version }}
239
240      - name: Set env
241        shell: bash
242        run: |
243          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
244          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
245
246      - uses: actions/checkout@v2
247        with:
248          path: src/github.com/containerd/containerd
249
250      - name: Make
251        run: |
252          make build
253          make binaries
254        working-directory: src/github.com/containerd/containerd
255
256  #
257  # Integration and CRI tests
258  #
259  integration-windows:
260    name: Windows Integration
261    runs-on: windows-2019
262    timeout-minutes: 30
263    needs: [project, linters, protos, man]
264    env:
265      GOTEST: gotestsum --
266
267    defaults:
268      run:
269        shell: bash
270        working-directory: src/github.com/containerd/containerd
271
272    steps:
273      - uses: actions/setup-go@v2
274        with:
275          go-version: '1.16.6'
276
277      - uses: actions/checkout@v2
278        with:
279          path: src/github.com/containerd/containerd
280
281      - uses: actions/checkout@v2
282        with:
283          repository: Microsoft/hcsshim
284          path: src/github.com/Microsoft/hcsshim
285
286      - name: Set env
287        run: |
288          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
289          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
290          echo "${{ github.workspace }}/src/github.com/containerd/containerd/bin" >> $GITHUB_PATH
291
292      - run: script/setup/install-dev-tools
293
294      - name: Binaries
295        env:
296          CGO_ENABLED: 1
297        run: |
298          set -o xtrace
299          mingw32-make.exe binaries
300          bindir="$(pwd)"
301          SHIM_COMMIT=$(grep 'Microsoft/hcsshim ' go.mod | awk '{print $2}')
302          cd ../../Microsoft/hcsshim
303          git fetch --tags origin "${SHIM_COMMIT}"
304          git checkout "${SHIM_COMMIT}"
305          GO111MODULE=on go build -mod=vendor -o "${bindir}/integration/client/containerd-shim-runhcs-v1.exe" ./cmd/containerd-shim-runhcs-v1
306
307      - run: script/setup/install-gotestsum
308      - name: Tests
309        env:
310          CGO_ENABLED: 1
311          GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-unit-root.xml
312        run: mingw32-make.exe test root-test
313
314      - name: Integration 1
315        env:
316          CGO_ENABLED: 1
317          GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-integration-serial-junit.xml
318        run: mingw32-make.exe integration
319
320      # Run the integration suite a second time. See discussion in github.com/containerd/containerd/pull/1759
321      - name: Integration 2
322        env:
323          TESTFLAGS_PARALLEL: 1
324          CGO_ENABLED: 1
325          GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-integration-parallel-junit.xml
326        run: mingw32-make.exe integration
327      - uses: actions/upload-artifact@v2
328        if: always()
329        with:
330          name: TestResults Windows
331          path: |
332            ${{github.workspace}}/*-junit.xml
333
334  integration-linux:
335    name: Linux Integration
336    runs-on: ubuntu-18.04
337    timeout-minutes: 30
338    needs: [project, linters, protos, man]
339
340    strategy:
341      fail-fast: false
342      matrix:
343        runtime: [io.containerd.runtime.v1.linux, io.containerd.runc.v1, io.containerd.runc.v2]
344        runc: [runc, crun]
345        exclude:
346          - runtime: io.containerd.runc.v1
347            runc: crun
348          - runtime: io.containerd.runtime.v1.linux
349            runc: crun
350
351    env:
352      GOTEST: gotestsum --
353    steps:
354      - uses: actions/setup-go@v2
355        with:
356          go-version: '1.16.6'
357
358      - uses: actions/checkout@v2
359        with:
360          path: src/github.com/containerd/containerd
361
362      - name: Set env
363        run: |
364          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
365          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
366
367      - name: Install containerd dependencies
368        env:
369          RUNC_FLAVOR: ${{ matrix.runc }}
370        run: |
371          sudo -E PATH=$PATH script/setup/install-seccomp
372          sudo -E PATH=$PATH script/setup/install-runc
373          sudo -E PATH=$PATH script/setup/install-cni
374          sudo -E PATH=$PATH script/setup/install-critools
375        working-directory: src/github.com/containerd/containerd
376
377      - name: Install criu
378        run: |
379          sudo apt-get install -y \
380            libprotobuf-dev \
381            libprotobuf-c-dev \
382            protobuf-c-compiler \
383            protobuf-compiler \
384            python-protobuf \
385            libnl-3-dev \
386            libnet-dev \
387            libcap-dev \
388            python-future
389          wget https://github.com/checkpoint-restore/criu/archive/v3.13.tar.gz -O criu.tar.gz
390          tar -zxf criu.tar.gz
391          cd criu-3.13
392          sudo make install-criu
393
394      - name: Install containerd
395        env:
396          CGO_ENABLED: 1
397        run: |
398          make binaries
399          sudo -E PATH=$PATH make install
400        working-directory: src/github.com/containerd/containerd
401
402      - run: sudo -E PATH=$PATH script/setup/install-gotestsum
403        working-directory: src/github.com/containerd/containerd
404      - name: Tests
405        env:
406          GOPROXY: direct
407          GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-unit-root-junit.xml
408        run: |
409          make test
410          sudo -E PATH=$PATH make root-test
411        working-directory: src/github.com/containerd/containerd
412
413      - name: Integration 1
414        env:
415          GOPROXY: direct
416          TEST_RUNTIME: ${{ matrix.runtime }}
417          RUNC_FLAVOR: ${{ matrix.runc }}
418          GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-integration-serial-junit.xml
419        run: |
420          sudo -E PATH=$PATH make integration EXTRA_TESTFLAGS=-no-criu TESTFLAGS_RACE=-race
421        working-directory: src/github.com/containerd/containerd
422
423      # Run the integration suite a second time. See discussion in github.com/containerd/containerd/pull/1759
424      - name: Integration 2
425        env:
426          GOPROXY: direct
427          TEST_RUNTIME: ${{ matrix.runtime }}
428          RUNC_FLAVOR: ${{ matrix.runc }}
429          GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-integration-parallel-junit.xml
430        run: |
431          sudo -E PATH=$PATH TESTFLAGS_PARALLEL=1 make integration EXTRA_TESTFLAGS=-no-criu
432        working-directory: src/github.com/containerd/containerd
433
434      # CRIU wouldn't work with overlay snapshotter yet.
435      # See https://github.com/containerd/containerd/pull/4708#issuecomment-724322294.
436      - name: CRIU Integration
437        env:
438          GOPROXY: direct
439          TEST_RUNTIME: ${{ matrix.runtime }}
440          RUNC_FLAVOR: ${{ matrix.runc }}
441          GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-integration-criu-junit.xml
442        # crun doesn't have "checkpoint" command.
443        if: ${{ matrix.runc == 'runc' }}
444        run: |
445          sudo -E PATH=$PATH \
446          TESTFLAGS_PARALLEL=1 \
447          TEST_SNAPSHOTTER=native \
448          make integration EXTRA_TESTFLAGS='-run TestCheckpoint'
449        working-directory: src/github.com/containerd/containerd
450
451      - name: CRI Integration Test
452        env:
453          TEST_RUNTIME: ${{ matrix.runtime }}
454        run: |
455          CONTAINERD_RUNTIME=$TEST_RUNTIME make cri-integration
456        working-directory: src/github.com/containerd/containerd
457
458      - name: cri-tools critest
459        env:
460          TEST_RUNTIME: ${{ matrix.runtime }}
461        run: |
462          BDIR="$(mktemp -d -p $PWD)"
463          mkdir -p ${BDIR}/{root,state}
464          cat > ${BDIR}/config.toml <<EOF
465            version = 2
466            [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
467            runtime_type = "${TEST_RUNTIME}"
468          EOF
469          sudo ls /etc/cni/net.d
470          sudo -E PATH=$PATH /usr/local/bin/containerd -a ${BDIR}/c.sock --config ${BDIR}/config.toml --root ${BDIR}/root --state ${BDIR}/state --log-level debug &> ${BDIR}/containerd-cri.log &
471          sudo -E PATH=$PATH /usr/local/bin/ctr -a ${BDIR}/c.sock version
472          sudo -E PATH=$PATH critest --report-dir "${{github.workspace}}/critestreport" --runtime-endpoint=unix:///${BDIR}/c.sock --parallel=8
473          TEST_RC=$?
474          test $TEST_RC -ne 0 && cat ${BDIR}/containerd-cri.log
475          sudo pkill containerd
476          sudo -E rm -rf ${BDIR}
477          test $TEST_RC -eq 0 || /bin/false
478
479      # Log the status of this VM to investigate issues like
480      # https://github.com/containerd/containerd/issues/4969
481      - name: Host Status
482        if: always()
483        run: |
484          set -x
485          mount
486          df
487          losetup -l
488      - uses: actions/upload-artifact@v2
489        if: always()
490        with:
491          name: TestResults ${{ matrix.runtime }} ${{matrix.runc}}
492          path: |
493            *-junit.xml
494            ${{github.workspace}}/critestreport/*.xml
495
496  tests-mac-os:
497    name: MacOS unit tests
498    runs-on: macos-10.15
499    timeout-minutes: 10
500    needs: [project, linters, protos, man]
501    env:
502      GOTEST: gotestsum --
503
504    steps:
505      - uses: actions/setup-go@v2
506        with:
507          go-version: '1.16.6'
508
509      - uses: actions/checkout@v2
510        with:
511          path: src/github.com/containerd/containerd
512
513      - name: Set env
514        run: |
515          echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
516          echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
517
518      - run: sudo -E PATH=$PATH script/setup/install-gotestsum
519        working-directory: src/github.com/containerd/containerd
520      - name: Tests
521        env:
522          GOPROXY: direct
523          GOTESTSUM_JUNITFILE: "${{ github.workspace }}/macos-test-junit.xml"
524        run: |
525          make test
526        working-directory: src/github.com/containerd/containerd
527      - uses: actions/upload-artifact@v2
528        if: always()
529        with:
530          name: TestResults MacOS
531          path: |
532            *-junit.xml
533
534  cgroup2:
535    name: CGroupsV2 and SELinux Integration
536    # nested virtualization is only available on macOS hosts
537    runs-on: macos-10.15
538    timeout-minutes: 45
539    needs: [project, linters, protos, man]
540    strategy:
541      matrix:
542        # Currently crun is disabled to decrease CI flakiness.
543        # We can enable crun again when we get a better CI infra.
544        runc: [runc]
545    env:
546      GOTEST: gotestsum --
547    steps:
548      - uses: actions/checkout@v2
549
550      - name: "Cache ~/.vagrant.d/boxes"
551        uses: actions/cache@v2
552        with:
553          path: ~/.vagrant.d/boxes
554          key: vagrant-${{ hashFiles('Vagrantfile*') }}
555
556      - name: Vagrant start
557        run: |
558          # Retry if it fails (download.fedoraproject.org returns 404 sometimes)
559          vagrant up || vagrant up
560
561      - name: Integration
562        env:
563          RUNC_FLAVOR: ${{ matrix.runc }}
564          SELINUX: Enforcing
565          GOTESTSUM_JUNITFILE: /tmp/test-integration-junit.xml
566        run: vagrant up --provision-with=selinux,install-runc,install-gotestsum,test-integration
567
568      - name: CRI test
569        env:
570          RUNC_FLAVOR: ${{ matrix.runc }}
571          SELINUX: Enforcing
572          REPORT_DIR: /tmp/critestreport
573        run: vagrant up --provision-with=selinux,install-runc,install-gotestsum,test-cri
574      - name: Get test reports
575        if: always()
576        run: |
577          set -e
578          vagrant plugin install vagrant-vbguest
579          vagrant plugin install vagrant-scp
580          vagrant scp :/tmp/test-integration-junit.xml "${{ github.workspace }}/"
581          vagrant scp :/tmp/critestreport "${{ github.workspace }}/critestreport"
582      - uses: actions/upload-artifact@v2
583        if: always()
584        with:
585          name:  TestResults cgroup2 ${{ matrix.runtime }} ${{matrix.runc}}
586          path: |
587            ${{github.workspace}}/*-junit.xml
588            ${{github.workspace}}/critestreport/*
589