Skip to content

Commit

Permalink
Merge pull request leodotcloud#6 from leodotcloud/drone
Browse files Browse the repository at this point in the history
enable drone
  • Loading branch information
leodotcloud authored Apr 3, 2020
2 parents c93aa20 + 10e3932 commit 51761e7
Show file tree
Hide file tree
Showing 111 changed files with 9,416 additions and 5,924 deletions.
66 changes: 66 additions & 0 deletions .drone.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
# This file is used for running on CI server
# Need to keep this in sync with .drone.yml
#

kind: pipeline
type: docker
name: default-amd64

platform:
os: linux
arch: amd64

trigger:
branch:
- master

workspace:
base: /go
path: src/github.com/leodotcloud/swiss-army-knife

steps:
- name: version
image: golang:1.13.9-buster
commands:
- ./scripts/version

- name: lint
image: golangci/golangci-lint:v1.24.0
commands:
- ./scripts/lint

- name: test
image: golang:1.13.9-buster
environment:
CGO_ENABLED: 0
GOFLAGS: -mod=vendor
commands:
- . ./version.env
- ./scripts/test

- name: build
image: golang:1.13.9-buster
environment:
CGO_ENABLED: 0
GOFLAGS: -mod=vendor
commands:
- . ./version.env
- ./scripts/build

- name: publish
image: plugins/docker
settings:
username:
from_secret: DOCKERHUB_USERNAME
password:
from_secret: DOCKERHUB_PASSWORD
repo: leodotcloud/swiss-army-knife
dockerfile: package/Dockerfile
auto_tag: true
when:
branch:
- master
event:
- tag

78 changes: 63 additions & 15 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
---
#
# This file is used for local development/builds
# Need to keep this in sync with .drone.ci.yml
#

kind: pipeline
type: exec
name: default-amd64

platform:
os: linux
arch: amd64

steps:
- name: build
pull: default
image: rancher/dapper:v0.4.1
commands:
- dapper ci
privileged: true
volumes:
workspace:
base: /go
path: src/github.com/leodotcloud/swiss-army-knife

volumes:
- name: docker
path: /var/run/docker.sock
when:
event:
- push
- pull_request
- tag
host:
path: /var/lib/docker
- name: docker_socket
host:
path: /var/run/docker.sock

steps:
- name: version
image: golang:1.13.9-buster
commands:
- ./scripts/version

- name: lint
image: golangci/golangci-lint:v1.24.0
commands:
- ./scripts/lint

- name: test
image: golang:1.13.9-buster
environment:
CGO_ENABLED: 0
GOFLAGS: -mod=vendor
commands:
- . ./version.env
- ./scripts/test

- name: build
image: golang:1.13.9-buster
environment:
CGO_ENABLED: 0
GOFLAGS: -mod=vendor
commands:
- . ./version.env
- ./scripts/build

- name: publish
image: plugins/docker
volumes:
- name: docker
path: /var/lib/docker
- name: docker_socket
path: /var/run/docker.sock
settings:
username:
from_secret: DOCKERHUB_USERNAME
password:
from_secret: DOCKERHUB_PASSWORD
repo: leodotcloud/swiss-army-knife
tags:
- dev
dockerfile: package/Dockerfile
dry_run: true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
/.trash-cache
swiss-army-knife
/.idea

# This file is generated by the scripts
version.env
# These files can be modified to run custom local builds
custom.env
secrets.env
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
run:
skip-dirs:
- vendor

linters:
enable:
- goimports

linters-settings:
govet:
check-shadowing: false
32 changes: 0 additions & 32 deletions Dockerfile.dapper

This file was deleted.

23 changes: 0 additions & 23 deletions Makefile

This file was deleted.

26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ tcpdump -i eth0 -vvv -nn -s0 -SS -XX

## Building

`make`
This repo can be built locally using `drone` cli using `exec` pipeline type. Since, local builds use the host docker, it's necessary to mark the repo as "trusted" for the "publish" step.

If you would like to build using a custom repo and tag:
Build all steps:
```bash
drone exec --trusted
```

Build specific steps:
```bash
drone exec --include=lint
drone exec --include=test
drone exec --include=version,build
drone exec --trusted --include=publish
```

To override and specify custom configuration, edit `custom.env` file and use:
```bash
drone exec --trusted --env-file=custom.env
```

For using secrets locally:
```bash
drone exec --secrets-file=secrets.env
```

`REPO=your_docker_repo TAG=dev_or_sth_else make release`
16 changes: 16 additions & 0 deletions custom.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Below variables can be used to override values from .drone.yml
# for local builds
#
# drone exec --env-file=custom.env

# PLUGIN_REPO lets to change the default repo
#PLUGIN_REPO=your_repo/swiss-army-knife

# For local builds, the publish step builds the docker image, but
# does not push to the registry.
# PLUGIN_DRY_RUN allows the push action if set to false
#PLUGIN_DRY_RUN=false

# PLUGIN_TAGS can be used to override the default "dev" tag for
# the image built locally
#PLUGIN_TAGS=tag1,tag2
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/leodotcloud/swiss-army-knife

go 1.13

require (
github.com/Sirupsen/logrus v1.0.4 // indirect
github.com/leodotcloud/log v0.1.0
github.com/rancher/go-rancher-metadata v0.0.0-20170929155856-d2103caca587
github.com/urfave/cli v1.22.3
golang.org/x/crypto v0.0.0-20180119165957-a66000089151 // indirect
golang.org/x/sys v0.0.0-20180117170059-2c42eef0765b // indirect
)
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Sirupsen/logrus v1.0.4 h1:yilvuj073Hm7wwwz12E96GjrdivMNuTMJk9ddjde+D8=
github.com/Sirupsen/logrus v1.0.4/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/leodotcloud/log v0.1.0 h1:sx3MwuD7q9Van4nbonbNbYREQCTJKehWfhm8I6ovYm0=
github.com/leodotcloud/log v0.1.0/go.mod h1:nUeGmzAy2eQifbL7coShqTc1EmaDKOJBQNzDCD9YWLw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rancher/go-rancher-metadata v0.0.0-20170929155856-d2103caca587 h1:T97rmLRz0aLeqPwj1isJ+IF34XI0yfoXXfoU0nNhwdM=
github.com/rancher/go-rancher-metadata v0.0.0-20170929155856-d2103caca587/go.mod h1:2GCT10S59Rl3M/hwW7BG6MMCqvuedd7VWJ1TneSeWsQ=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20180119165957-a66000089151 h1:du7dTgoJooIwkyksVuOCfUbQDgZE9oIUdVk/v/tqou4=
golang.org/x/crypto v0.0.0-20180119165957-a66000089151/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20180117170059-2c42eef0765b h1:mxo/dXmtEd5rXc/ZzMKg0qDhMT+51+LvV65S9dP6nh4=
golang.org/x/sys v0.0.0-20180117170059-2c42eef0765b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/leodotcloud/log"
Expand Down Expand Up @@ -53,15 +54,23 @@ func main() {
}

app.Action = run
app.Run(os.Args)
if err := app.Run(os.Args); err != nil {
os.Exit(1)
}
}

func run(c *cli.Context) error {
logserver.StartServerWithDefaults()
if c.Bool("debug") {
log.SetLevelString("debug")
if err := log.SetLevelString("debug"); err != nil {
return err
}
}

if c.Bool("version") {
fmt.Println(c.App.Version)
return nil
}
s, err := server.NewServer(
c.String(portArg),
c.String(metadataAddressArg),
Expand Down
3 changes: 2 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ RUN apt-get update && \
ln -s /usr/local/bin/kubectl-1.14 /usr/local/bin/kubectl && \
mkdir /root/.kube

ADD loglevel.tar.gz /usr/bin
ENV LOGLEVEL_TAG v0.1
RUN curl -sfSL https://github.com/rancher/loglevel/releases/download/${LOGLEVEL_TAG}/loglevel-amd64-${LOGLEVEL_TAG}.tar.gz | tar xvzf - -C /usr/bin
COPY swiss-army-knife /usr/bin/
WORKDIR /root
CMD ["swiss-army-knife"]
20 changes: 11 additions & 9 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/bash
set -ex
#!/bin/sh

source $(dirname $0)/version
set -e

# This logic is to make sure, we can build directly from CLI
if [ -z ${VERSION_SET+x} ];then
source $(dirname $0)/version
fi

cd $(dirname $0)/..

mkdir -p bin
[ "$(uname)" != "Darwin" ] && [ "${OS}" != "windows" ] && LINKFLAGS="-linkmode external -extldflags -static -s"
[ "$(uname)" != "Darwin" ] && [ "${OS}" != "windows" ] && LINKFLAGS=""

OUTPUT=bin/swiss-army-knife
if [ "${OS}" == "windows" ]; then
OUTPUT=bin/swiss-army-knife.exe
OUTPUT=swiss-army-knife
if [ "${OS}" = "windows" ]; then
OUTPUT=swiss-army-knife.exe
fi

GOOS=${OS} GOARCH=${ARCH} go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o ${OUTPUT}
Loading

0 comments on commit 51761e7

Please sign in to comment.