Skip to content

Commit

Permalink
Merge pull request #74 from estesp/gha
Browse files Browse the repository at this point in the history
Migrate to GitHub Actions CI
  • Loading branch information
fuweid authored Apr 27, 2021
2 parents 16b287b + 744121c commit 61ca12e
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 21 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

checks:
name: Project Checks
runs-on: ubuntu-18.04
timeout-minutes: 5

steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16.x

- name: Set env
shell: bash
run: |
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
- uses: actions/checkout@v2
with:
path: src/github.com/containerd/go-runc
fetch-depth: 25

- uses: containerd/project-checks@v1
with:
working-directory: src/github.com/containerd/go-runc

linters:
name: Linters
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-18.04]

steps:
- uses: actions/checkout@v2
with:
path: src/github.com/containerd/go-runc

- name: Set env
shell: bash
run: |
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
- uses: golangci/golangci-lint-action@v2
with:
version: v1.29
working-directory: src/github.com/containerd/go-runc

tests:
name: Tests
runs-on: ubuntu-18.04
timeout-minutes: 5

steps:
- uses: actions/checkout@v2
with:
path: src/github.com/containerd/go-runc

- uses: actions/setup-go@v2
with:
go-version: 1.16.x

- name: Set env
shell: bash
run: |
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
- run: |
go test -v -race -covermode=atomic -coverprofile=coverage.txt ./...
bash <(curl -s https://codecov.io/bash)
working-directory: src/github.com/containerd/go-runc
22 changes: 22 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
linters:
enable:
- structcheck
- varcheck
- staticcheck
- unconvert
- gofmt
- goimports
- golint
- ineffassign
- vet
- unused
- misspell
disable:
- errcheck

issues:
include:
- EXC0002

run:
timeout: 2m
2 changes: 1 addition & 1 deletion console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestTempConsole(t *testing.T) {

func TestTempConsoleWithXdgRuntimeDir(t *testing.T) {
tmpDir := "/tmp/foo"
// prevent interferring with other tests
// prevent interfering with other tests
defer os.Setenv("XDG_RUNTIME_DIR", os.Getenv("XDG_RUNTIME_DIR"))
if err := os.Setenv("XDG_RUNTIME_DIR", tmpDir); err != nil {
t.Fatal(err)
Expand Down
17 changes: 14 additions & 3 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package runc

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

// Stats is statistical information from the runc process
type Stats struct {
Cpu Cpu `json:"cpu"`
Cpu Cpu `json:"cpu"` //nolint:golint
Memory Memory `json:"memory"`
Pids Pids `json:"pids"`
Blkio Blkio `json:"blkio"`
Hugetlb map[string]Hugetlb `json:"hugetlb"`
}

// Hugetlb represents the detailed hugetlb component of the statistics data
type Hugetlb struct {
Usage uint64 `json:"usage,omitempty"`
Max uint64 `json:"max,omitempty"`
Failcnt uint64 `json:"failcnt"`
}

// BlkioEntry represents a block IO entry in the IO stats
type BlkioEntry struct {
Major uint64 `json:"major,omitempty"`
Minor uint64 `json:"minor,omitempty"`
Op string `json:"op,omitempty"`
Value uint64 `json:"value,omitempty"`
}

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

// Pids represents the process ID information
type Pids struct {
Current uint64 `json:"current,omitempty"`
Limit uint64 `json:"limit,omitempty"`
}

// Throttling represents the throttling statistics
type Throttling struct {
Periods uint64 `json:"periods,omitempty"`
ThrottledPeriods uint64 `json:"throttledPeriods,omitempty"`
ThrottledTime uint64 `json:"throttledTime,omitempty"`
}

type CpuUsage struct {
// CpuUsage represents the CPU usage statistics
type CpuUsage struct { //nolint:golint
// Units: nanoseconds.
Total uint64 `json:"total,omitempty"`
Percpu []uint64 `json:"percpu,omitempty"`
Kernel uint64 `json:"kernel"`
User uint64 `json:"user"`
}

type Cpu struct {
// Cpu represents the CPU usage and throttling statistics
type Cpu struct { //nolint:golint
Usage CpuUsage `json:"usage,omitempty"`
Throttling Throttling `json:"throttling,omitempty"`
}

// MemoryEntry represents an item in the memory use/statistics
type MemoryEntry struct {
Limit uint64 `json:"limit"`
Usage uint64 `json:"usage,omitempty"`
Max uint64 `json:"max,omitempty"`
Failcnt uint64 `json:"failcnt"`
}

// Memory represents the collection of memory statistics from the process
type Memory struct {
Cache uint64 `json:"cache,omitempty"`
Usage MemoryEntry `json:"usage,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions io.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os/exec"
)

// IO is the terminal IO interface
type IO interface {
io.Closer
Stdin() io.WriteCloser
Expand All @@ -30,6 +31,7 @@ type IO interface {
Set(*exec.Cmd)
}

// StartCloser is an interface to handle IO closure after start
type StartCloser interface {
CloseAfterStart() error
}
Expand Down Expand Up @@ -144,6 +146,7 @@ func (i *pipeIO) Set(cmd *exec.Cmd) {
}
}

// NewSTDIO returns I/O setup for standard OS in/out/err usage
func NewSTDIO() (IO, error) {
return &stdio{}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion io_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
package runc

import (
"runtime"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"runtime"
)

// NewPipeIO creates pipe pairs to be used with runc
Expand Down
2 changes: 2 additions & 0 deletions monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"time"
)

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

// Exit holds the exit information from a process
type Exit struct {
Timestamp time.Time
Pid int
Expand Down
24 changes: 20 additions & 4 deletions runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
)

// Format is the type of log formatting options avaliable
// Format is the type of log formatting options available
type Format string

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

const (
none Format = ""
// JSON represents the JSON format
JSON Format = "json"
// Text represents plain text format
Text Format = "text"
// DefaultCommand is the default command for Runc
DefaultCommand = "runc"
Expand Down Expand Up @@ -82,10 +84,12 @@ func (r *Runc) State(context context.Context, id string) (*Container, error) {
return &c, nil
}

// ConsoleSocket handles the path of the socket for console access
type ConsoleSocket interface {
Path() string
}

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

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

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

// CheckpointOpts holds the options for performing a criu checkpoint using runc
type CheckpointOpts struct {
// ImagePath is the path for saving the criu image file
ImagePath string
Expand Down Expand Up @@ -456,11 +463,15 @@ type CheckpointOpts struct {
StatusFile *os.File
}

// CgroupMode defines the cgroup mode used for checkpointing
type CgroupMode string

const (
Soft CgroupMode = "soft"
Full CgroupMode = "full"
// Soft is the "soft" cgroup mode
Soft CgroupMode = "soft"
// Full is the "full" cgroup mode
Full CgroupMode = "full"
// Strict is the "strict" cgroup mode
Strict CgroupMode = "strict"
)

Expand Down Expand Up @@ -501,6 +512,7 @@ func (o *CheckpointOpts) args() (out []string) {
return out
}

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

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

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

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

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

// ExitError holds the status return code when a process exits with an error code
type ExitError struct {
Status int
}
Expand Down
12 changes: 0 additions & 12 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strconv"
"strings"
"sync"
"syscall"
)

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

const exitSignalOffset = 128

// exitStatus returns the correct exit status for a process based on if it
// was signaled or exited cleanly
func exitStatus(status syscall.WaitStatus) int {
if status.Signaled() {
return exitSignalOffset + int(status.Signal())
}
return status.ExitStatus()
}

var bytesBufferPool = sync.Pool{
New: func() interface{} {
return bytes.NewBuffer(nil)
Expand Down

0 comments on commit 61ca12e

Please sign in to comment.