Skip to content

Commit 61ca12e

Browse files
authored
Merge pull request #74 from estesp/gha
Migrate to GitHub Actions CI
2 parents 16b287b + 744121c commit 61ca12e

File tree

9 files changed

+149
-21
lines changed

9 files changed

+149
-21
lines changed

.github/workflows/ci.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
11+
checks:
12+
name: Project Checks
13+
runs-on: ubuntu-18.04
14+
timeout-minutes: 5
15+
16+
steps:
17+
- uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.16.x
20+
21+
- name: Set env
22+
shell: bash
23+
run: |
24+
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
25+
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
26+
27+
- uses: actions/checkout@v2
28+
with:
29+
path: src/github.com/containerd/go-runc
30+
fetch-depth: 25
31+
32+
- uses: containerd/project-checks@v1
33+
with:
34+
working-directory: src/github.com/containerd/go-runc
35+
36+
linters:
37+
name: Linters
38+
runs-on: ${{ matrix.os }}
39+
timeout-minutes: 10
40+
41+
strategy:
42+
matrix:
43+
go-version: [1.16.x]
44+
os: [ubuntu-18.04]
45+
46+
steps:
47+
- uses: actions/checkout@v2
48+
with:
49+
path: src/github.com/containerd/go-runc
50+
51+
- name: Set env
52+
shell: bash
53+
run: |
54+
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
55+
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
56+
57+
- uses: golangci/golangci-lint-action@v2
58+
with:
59+
version: v1.29
60+
working-directory: src/github.com/containerd/go-runc
61+
62+
tests:
63+
name: Tests
64+
runs-on: ubuntu-18.04
65+
timeout-minutes: 5
66+
67+
steps:
68+
- uses: actions/checkout@v2
69+
with:
70+
path: src/github.com/containerd/go-runc
71+
72+
- uses: actions/setup-go@v2
73+
with:
74+
go-version: 1.16.x
75+
76+
- name: Set env
77+
shell: bash
78+
run: |
79+
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
80+
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
81+
82+
- run: |
83+
go test -v -race -covermode=atomic -coverprofile=coverage.txt ./...
84+
bash <(curl -s https://codecov.io/bash)
85+
working-directory: src/github.com/containerd/go-runc

.golangci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
linters:
2+
enable:
3+
- structcheck
4+
- varcheck
5+
- staticcheck
6+
- unconvert
7+
- gofmt
8+
- goimports
9+
- golint
10+
- ineffassign
11+
- vet
12+
- unused
13+
- misspell
14+
disable:
15+
- errcheck
16+
17+
issues:
18+
include:
19+
- EXC0002
20+
21+
run:
22+
timeout: 2m

console_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestTempConsole(t *testing.T) {
3333

3434
func TestTempConsoleWithXdgRuntimeDir(t *testing.T) {
3535
tmpDir := "/tmp/foo"
36-
// prevent interferring with other tests
36+
// prevent interfering with other tests
3737
defer os.Setenv("XDG_RUNTIME_DIR", os.Getenv("XDG_RUNTIME_DIR"))
3838
if err := os.Setenv("XDG_RUNTIME_DIR", tmpDir); err != nil {
3939
t.Fatal(err)

events.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package runc
1818

19+
// Event is a struct to pass runc event information
1920
type Event struct {
2021
// Type are the event type generated by runc
2122
// If the type is "error" then check the Err field on the event for
@@ -27,27 +28,31 @@ type Event struct {
2728
Err error `json:"-"`
2829
}
2930

31+
// Stats is statistical information from the runc process
3032
type Stats struct {
31-
Cpu Cpu `json:"cpu"`
33+
Cpu Cpu `json:"cpu"` //nolint:golint
3234
Memory Memory `json:"memory"`
3335
Pids Pids `json:"pids"`
3436
Blkio Blkio `json:"blkio"`
3537
Hugetlb map[string]Hugetlb `json:"hugetlb"`
3638
}
3739

40+
// Hugetlb represents the detailed hugetlb component of the statistics data
3841
type Hugetlb struct {
3942
Usage uint64 `json:"usage,omitempty"`
4043
Max uint64 `json:"max,omitempty"`
4144
Failcnt uint64 `json:"failcnt"`
4245
}
4346

47+
// BlkioEntry represents a block IO entry in the IO stats
4448
type BlkioEntry struct {
4549
Major uint64 `json:"major,omitempty"`
4650
Minor uint64 `json:"minor,omitempty"`
4751
Op string `json:"op,omitempty"`
4852
Value uint64 `json:"value,omitempty"`
4953
}
5054

55+
// Blkio represents the statistical information from block IO devices
5156
type Blkio struct {
5257
IoServiceBytesRecursive []BlkioEntry `json:"ioServiceBytesRecursive,omitempty"`
5358
IoServicedRecursive []BlkioEntry `json:"ioServicedRecursive,omitempty"`
@@ -59,37 +64,43 @@ type Blkio struct {
5964
SectorsRecursive []BlkioEntry `json:"sectorsRecursive,omitempty"`
6065
}
6166

67+
// Pids represents the process ID information
6268
type Pids struct {
6369
Current uint64 `json:"current,omitempty"`
6470
Limit uint64 `json:"limit,omitempty"`
6571
}
6672

73+
// Throttling represents the throttling statistics
6774
type Throttling struct {
6875
Periods uint64 `json:"periods,omitempty"`
6976
ThrottledPeriods uint64 `json:"throttledPeriods,omitempty"`
7077
ThrottledTime uint64 `json:"throttledTime,omitempty"`
7178
}
7279

73-
type CpuUsage struct {
80+
// CpuUsage represents the CPU usage statistics
81+
type CpuUsage struct { //nolint:golint
7482
// Units: nanoseconds.
7583
Total uint64 `json:"total,omitempty"`
7684
Percpu []uint64 `json:"percpu,omitempty"`
7785
Kernel uint64 `json:"kernel"`
7886
User uint64 `json:"user"`
7987
}
8088

81-
type Cpu struct {
89+
// Cpu represents the CPU usage and throttling statistics
90+
type Cpu struct { //nolint:golint
8291
Usage CpuUsage `json:"usage,omitempty"`
8392
Throttling Throttling `json:"throttling,omitempty"`
8493
}
8594

95+
// MemoryEntry represents an item in the memory use/statistics
8696
type MemoryEntry struct {
8797
Limit uint64 `json:"limit"`
8898
Usage uint64 `json:"usage,omitempty"`
8999
Max uint64 `json:"max,omitempty"`
90100
Failcnt uint64 `json:"failcnt"`
91101
}
92102

103+
// Memory represents the collection of memory statistics from the process
93104
type Memory struct {
94105
Cache uint64 `json:"cache,omitempty"`
95106
Usage MemoryEntry `json:"usage,omitempty"`

io.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os/exec"
2323
)
2424

25+
// IO is the terminal IO interface
2526
type IO interface {
2627
io.Closer
2728
Stdin() io.WriteCloser
@@ -30,6 +31,7 @@ type IO interface {
3031
Set(*exec.Cmd)
3132
}
3233

34+
// StartCloser is an interface to handle IO closure after start
3335
type StartCloser interface {
3436
CloseAfterStart() error
3537
}
@@ -144,6 +146,7 @@ func (i *pipeIO) Set(cmd *exec.Cmd) {
144146
}
145147
}
146148

149+
// NewSTDIO returns I/O setup for standard OS in/out/err usage
147150
func NewSTDIO() (IO, error) {
148151
return &stdio{}, nil
149152
}

io_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
package runc
2020

2121
import (
22+
"runtime"
23+
2224
"github.com/pkg/errors"
2325
"github.com/sirupsen/logrus"
2426
"golang.org/x/sys/unix"
25-
"runtime"
2627
)
2728

2829
// NewPipeIO creates pipe pairs to be used with runc

monitor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import (
2222
"time"
2323
)
2424

25+
// Monitor is the default ProcessMonitor for handling runc process exit
2526
var Monitor ProcessMonitor = &defaultMonitor{}
2627

28+
// Exit holds the exit information from a process
2729
type Exit struct {
2830
Timestamp time.Time
2931
Pid int

runc.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ import (
3434
specs "github.com/opencontainers/runtime-spec/specs-go"
3535
)
3636

37-
// Format is the type of log formatting options avaliable
37+
// Format is the type of log formatting options available
3838
type Format string
3939

40-
// TopBody represents the structured data of the full ps output
40+
// TopResults represents the structured data of the full ps output
4141
type TopResults struct {
4242
// Processes running in the container, where each is process is an array of values corresponding to the headers
4343
Processes [][]string `json:"Processes"`
@@ -48,7 +48,9 @@ type TopResults struct {
4848

4949
const (
5050
none Format = ""
51+
// JSON represents the JSON format
5152
JSON Format = "json"
53+
// Text represents plain text format
5254
Text Format = "text"
5355
// DefaultCommand is the default command for Runc
5456
DefaultCommand = "runc"
@@ -82,10 +84,12 @@ func (r *Runc) State(context context.Context, id string) (*Container, error) {
8284
return &c, nil
8385
}
8486

87+
// ConsoleSocket handles the path of the socket for console access
8588
type ConsoleSocket interface {
8689
Path() string
8790
}
8891

92+
// CreateOpts holds all the options information for calling runc with supported options
8993
type CreateOpts struct {
9094
IO
9195
// PidFile is a path to where a pid file should be created
@@ -171,6 +175,7 @@ func (r *Runc) Start(context context.Context, id string) error {
171175
return r.runOrError(r.command(context, "start", id))
172176
}
173177

178+
// ExecOpts holds optional settings when starting an exec process with runc
174179
type ExecOpts struct {
175180
IO
176181
PidFile string
@@ -285,6 +290,7 @@ func (r *Runc) Run(context context.Context, id, bundle string, opts *CreateOpts)
285290
return status, err
286291
}
287292

293+
// DeleteOpts holds the deletion options for calling `runc delete`
288294
type DeleteOpts struct {
289295
Force bool
290296
}
@@ -428,6 +434,7 @@ func (r *Runc) Top(context context.Context, id string, psOptions string) (*TopRe
428434
return topResults, nil
429435
}
430436

437+
// CheckpointOpts holds the options for performing a criu checkpoint using runc
431438
type CheckpointOpts struct {
432439
// ImagePath is the path for saving the criu image file
433440
ImagePath string
@@ -456,11 +463,15 @@ type CheckpointOpts struct {
456463
StatusFile *os.File
457464
}
458465

466+
// CgroupMode defines the cgroup mode used for checkpointing
459467
type CgroupMode string
460468

461469
const (
462-
Soft CgroupMode = "soft"
463-
Full CgroupMode = "full"
470+
// Soft is the "soft" cgroup mode
471+
Soft CgroupMode = "soft"
472+
// Full is the "full" cgroup mode
473+
Full CgroupMode = "full"
474+
// Strict is the "strict" cgroup mode
464475
Strict CgroupMode = "strict"
465476
)
466477

@@ -501,6 +512,7 @@ func (o *CheckpointOpts) args() (out []string) {
501512
return out
502513
}
503514

515+
// CheckpointAction represents specific actions executed during checkpoint/restore
504516
type CheckpointAction func([]string) []string
505517

506518
// LeaveRunning keeps the container running after the checkpoint has been completed
@@ -535,6 +547,7 @@ func (r *Runc) Checkpoint(context context.Context, id string, opts *CheckpointOp
535547
return r.runOrError(cmd)
536548
}
537549

550+
// RestoreOpts holds the options for performing a criu restore using runc
538551
type RestoreOpts struct {
539552
CheckpointOpts
540553
IO
@@ -617,8 +630,10 @@ func (r *Runc) Update(context context.Context, id string, resources *specs.Linux
617630
return r.runOrError(cmd)
618631
}
619632

633+
// ErrParseRuncVersion is used when the runc version can't be parsed
620634
var ErrParseRuncVersion = errors.New("unable to parse runc version")
621635

636+
// Version represents the runc version information
622637
type Version struct {
623638
Runc string
624639
Commit string
@@ -732,6 +747,7 @@ func cmdOutput(cmd *exec.Cmd, combined bool, started chan<- int) (*bytes.Buffer,
732747
return b, err
733748
}
734749

750+
// ExitError holds the status return code when a process exits with an error code
735751
type ExitError struct {
736752
Status int
737753
}

utils.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"strconv"
2323
"strings"
2424
"sync"
25-
"syscall"
2625
)
2726

2827
// ReadPidFile reads the pid file at the provided path and returns
@@ -35,17 +34,6 @@ func ReadPidFile(path string) (int, error) {
3534
return strconv.Atoi(string(data))
3635
}
3736

38-
const exitSignalOffset = 128
39-
40-
// exitStatus returns the correct exit status for a process based on if it
41-
// was signaled or exited cleanly
42-
func exitStatus(status syscall.WaitStatus) int {
43-
if status.Signaled() {
44-
return exitSignalOffset + int(status.Signal())
45-
}
46-
return status.ExitStatus()
47-
}
48-
4937
var bytesBufferPool = sync.Pool{
5038
New: func() interface{} {
5139
return bytes.NewBuffer(nil)

0 commit comments

Comments
 (0)