Skip to content

Commit

Permalink
setup circle ci
Browse files Browse the repository at this point in the history
  • Loading branch information
aylei committed Dec 21, 2018
1 parent f9231f4 commit a7cb57d
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 10 deletions.
70 changes: 70 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.10

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

#### TEMPLATE_NOTE: go expects specific checkout path representing url
#### expecting it in the form of
#### /go/src/github.com/circleci/go-tool
#### /go/src/bitbucket.org/circleci/go-tool
working_directory: /go/src/github.com/aylei/kubectl-debug
environment:
- GOCACHE: "/tmp/go/cache"
- DEP_VERSION: 0.4.1
steps:
- checkout

- setup_remote_docker:
docker_layer_caching: true

# try to restore cache
- restore_cache:
key: gopkg-{{ .Branch }}-{{ checksum "Gopkg.lock" }}
paths:
- /go/src/github.com/aylei/kubectl-debug/vendor

# install dep and do dep ensure
- run:
name: dep-ensure
command: |
if [ ! -d /go/src/github.com/aylei/kubectl-debug/vendor ]; then
curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o /go/bin/dep
chmod +x /go/bin/dep
/go/bin/dep ensure
fi
- save_cache:
key: gopkg-{{ .Branch }}-{{ checksum "Gopkg.lock" }}
paths:
- /go/src/github.com/aylei/kubectl-debug/vendor

# cache for build
- restore_cache:
keys:
- build-cache-{{ .Branch }}-{{ .Environment.CIRCLE_PREVIOUS_BUILD_NUM }}
paths:
- /tmp/go/cache

- run: GOOS=linux GARCH=amd64 go build -o debug-agent ./cmd/agent

- deploy:
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
docker build . -t aylei/debug-agent
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} https://index.docker.io/v1/
docker push aylei/debug-agent
- save_cache:
key: build-cache-{{ .Branch }}-{{ .Environment.CIRCLE_BUILD_NUM }}
paths:
- /tmp/go/cache
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!debug-agent
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
.cache
*.output
.swp
vendor/
vendor/
debug-agent
kubectl-debug
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.4
RUN apk add --update --no-cache ca-certificates && rm /var/cache/apk/*

COPY ./debug-agent /bin/debug-agent
EXPOSE 10027

ENTRYPOINT ["/bin/debug-agent"]
2 changes: 1 addition & 1 deletion cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {

var configFile string
flag.StringVar(&configFile, "config.file", "debug-agent.yaml", "Config file location.")
flag.StringVar(&configFile, "config.file", "", "Config file location.")
flag.Parse()

config, err := agent.LoadFile(configFile)
Expand Down
3 changes: 3 additions & 0 deletions pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func Load(s string) (*Config, error) {
}

func LoadFile(filename string) (*Config, error) {
if len(filename) < 1 {
return &DefaultConfig, nil
}
c, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
Expand Down
16 changes: 9 additions & 7 deletions pkg/agent/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m *RuntimeManager) GetAttacher(image string, command []string) kubeletremo
// DebugContainer executes the main debug flow
func (m *RuntimeManager) DebugContainer(container, image string, command []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {

log.Printf("Accept new debug reqeust:\n\t target container: %s \n\t image: %s \n\t command: %s \n", container, image, command)
log.Printf("Accept new debug reqeust:\n\t target container: %s \n\t image: %s \n\t command: %v \n", container, image, command)

// step 1: pull image
stdout.Write([]byte(fmt.Sprintf("pulling image %s ...\n\r", image)))
Expand Down Expand Up @@ -145,19 +145,21 @@ func (m *RuntimeManager) CleanContainer(id string) {
defer cancel()
// wait the container gracefully exit
statusCh, errCh := m.client.ContainerWait(ctx, id, container.WaitConditionNotRunning)
var rmErr error
select {
case err := <-errCh:
if err != nil {
log.Println("error waiting container exit, kill with --force")
// timeout or error occurs, try force remove anywawy
if err := m.RmContainer(id, true); err != nil {
log.Printf("error remove container: %s\n", id)
}
rmErr = m.RmContainer(id, true)
}
case <-statusCh:
if err := m.RmContainer(id, false); err != nil {
log.Printf("error remove container: %s\n", id)
}
rmErr = m.RmContainer(id, false)
}
if rmErr != nil {
log.Printf("error remove container: %s \n", id)
} else {
log.Printf("Debug session end, debug container %s removed")
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (o *DebugOptions) Run() error {
}

if err := t.Safe(fn); err != nil {
fmt.Printf("error execute remote", err)
fmt.Printf("error execute remote, %v\n", err)
return err
}

Expand Down

0 comments on commit a7cb57d

Please sign in to comment.