5 Commits

Author SHA1 Message Date
Don
dcc073cef3 Fix 2020-10-15 10:21:06 -07:00
Don
ece57563b4 Fix build 2020-10-15 10:16:50 -07:00
Don
e33755c959 Fix 2020-10-15 10:12:54 -07:00
Don
188d9c8543 Fix staticcheck lints 2020-10-15 10:05:52 -07:00
Don
af1bb6bcf2 Add starlark build 2020-10-15 08:47:27 -07:00
5 changed files with 658 additions and 1342 deletions

272
.drone.star Normal file
View File

@@ -0,0 +1,272 @@
golang_image = "golang:1.15"
def main(ctx):
before = testing(ctx)
stages = [
linux(ctx, "amd64"),
linux(ctx, "arm64"),
linux(ctx, "arm"),
]
after = manifest(ctx) + gitter(ctx)
for b in before:
for s in stages:
s["depends_on"].append(b["name"])
for s in stages:
for a in after:
a["depends_on"].append(s["name"])
return before + stages + after
def testing(ctx):
step_volumes = [
{
"name": "gopath",
"path": "/go",
},
]
return [
{
"kind": "pipeline",
"type": "docker",
"name": "testing",
"platform": {
"os": "linux",
"arch": "amd64",
},
"steps": [
{
"name": "staticcheck",
"image": golang_image,
"pull": "always",
"commands": [
"go run honnef.co/go/tools/cmd/staticcheck ./...",
],
"volumes": step_volumes,
},
{
"name": "lint",
"image": golang_image,
"pull": "always",
"commands": [
"go run golang.org/x/lint/golint -set_exit_status ./...",
],
"volumes": step_volumes,
},
{
"name": "vet",
"image": golang_image,
"commands": [
"go vet ./...",
],
"volumes": step_volumes,
},
{
"name": "test",
"image": golang_image,
"commands": [
"go test -cover ./...",
],
"volumes": step_volumes,
},
],
"volumes": [
{
"name": "gopath",
"temp": {},
},
],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
"refs/pull/**",
],
},
},
]
def linux(ctx, arch):
steps = [
{
"name": "environment",
"image": golang_image,
"pull": "always",
"environment": {
"CGO_ENABLED": "0",
},
"commands": [
"go version",
"go env",
],
},
]
steps.extend(linux_build(ctx, arch, "docker"))
steps.extend(linux_build(ctx, arch, "acr"))
steps.extend(linux_build(ctx, arch, "ecr"))
steps.extend(linux_build(ctx, arch, "gcr"))
steps.extend(linux_build(ctx, arch, "heroku"))
return {
"kind": "pipeline",
"type": "docker",
"name": "linux-%s" % (arch),
"platform": {
"os": "linux",
"arch": arch,
},
"steps": steps,
"depends_on": [],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
"refs/pull/**",
],
},
}
def linux_build(ctx, arch, name):
docker = {
"dockerfile": "docker/%s/Dockerfile.linux.%s" % (name, arch),
"repo": "plugins/%s" % (name),
"username": {
"from_secret": "docker_username",
},
"password": {
"from_secret": "docker_password",
},
}
if ctx.build.event == "pull_request":
docker.update({
"dry_run": True,
"tags": "linux-%s" % (arch),
})
else:
docker.update({
"auto_tag": True,
"auto_tag_suffix": "linux-%s" % (arch),
})
if ctx.build.event == "tag":
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-%s ./cmd/drone-%s' % (ctx.build.ref.replace("refs/tags/v", ""), arch, name, name),
]
else:
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-%s ./cmd/drone-%s' % (ctx.build.commit[0:8], arch, name, name),
]
return [
{
"name": "build-%s" % (name),
"image": golang_image,
"environment": {
"CGO_ENABLED": "0",
},
"commands": build,
},
{
"name": "docker-%s" % (name),
"image": "plugins/docker",
"pull": "always",
"settings": docker,
},
]
def manifest(ctx):
steps = []
steps.extend(manifest_build(ctx, "docker"))
steps.extend(manifest_build(ctx, "acr"))
steps.extend(manifest_build(ctx, "ecr"))
steps.extend(manifest_build(ctx, "gcr"))
steps.extend(manifest_build(ctx, "heroku"))
return [
{
"kind": "pipeline",
"type": "docker",
"name": "manifest",
"steps": steps,
"depends_on": [],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
],
},
},
]
def manifest_build(ctx, name):
return [
{
"name": "manifest-%s" % (name),
"image": "plugins/manifest",
"pull": "always",
"settings": {
"auto_tag": "true",
"username": {
"from_secret": "docker_username",
},
"password": {
"from_secret": "docker_password",
},
"spec": "docker/%s/manifest.tmpl" % (name),
"ignore_missing": "true",
},
},
{
"name": "microbadger-%s" % (name),
"image": "plugins/webhook",
"pull": "always",
"settings": {
"urls": {
"from_secret": "microbadger_url",
},
},
},
]
def gitter(ctx):
return [
{
"kind": "pipeline",
"type": "docker",
"name": "gitter",
"clone": {
"disable": True,
},
"steps": [
{
"name": "gitter",
"image": "plugins/gitter",
"pull": "always",
"settings": {
"webhook": {
"from_secret": "gitter_webhook",
},
},
},
],
"depends_on": [
"manifest",
],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
],
"status": [
"failure",
],
},
},
]

1645
.drone.yml

File diff suppressed because it is too large Load Diff

View File

@@ -5,6 +5,7 @@ package docker
import (
"io/ioutil"
"os"
"os/exec"
)
const dockerExe = "/usr/local/bin/docker"
@@ -25,3 +26,40 @@ func (p Plugin) startDaemon() {
cmd.Run()
}()
}
// helper function to create the docker daemon command.
func commandDaemon(daemon Daemon) *exec.Cmd {
args := []string{
"--data-root", daemon.StoragePath,
"--host=unix:///var/run/docker.sock",
}
if daemon.StorageDriver != "" {
args = append(args, "-s", daemon.StorageDriver)
}
if daemon.Insecure && daemon.Registry != "" {
args = append(args, "--insecure-registry", daemon.Registry)
}
if daemon.IPv6 {
args = append(args, "--ipv6")
}
if len(daemon.Mirror) != 0 {
args = append(args, "--registry-mirror", daemon.Mirror)
}
if len(daemon.Bip) != 0 {
args = append(args, "--bip", daemon.Bip)
}
for _, dns := range daemon.DNS {
args = append(args, "--dns", dns)
}
for _, dnsSearch := range daemon.DNSSearch {
args = append(args, "--dns-search", dnsSearch)
}
if len(daemon.MTU) != 0 {
args = append(args, "--mtu", daemon.MTU)
}
if daemon.Experimental {
args = append(args, "--experimental")
}
return exec.Command(dockerdExe, args...)
}

View File

@@ -3,7 +3,6 @@
package docker
const dockerExe = "C:\\bin\\docker.exe"
const dockerdExe = ""
const dockerHome = "C:\\ProgramData\\docker\\"
func (p Plugin) startDaemon() {

View File

@@ -94,7 +94,7 @@ func (p Plugin) Exec() error {
path := filepath.Join(dockerHome, "config.json")
err := ioutil.WriteFile(path, []byte(p.Login.Config), 0600)
if err != nil {
return fmt.Errorf("Error writeing config.json: %s", err)
return fmt.Errorf("error writing config.json: %w", err)
}
}
@@ -103,7 +103,7 @@ func (p Plugin) Exec() error {
cmd := commandLogin(p.Login)
err := cmd.Run()
if err != nil {
return fmt.Errorf("Error authenticating: %s", err)
return fmt.Errorf("error authenticating: %w", err)
}
}
@@ -138,7 +138,7 @@ func (p Plugin) Exec() error {
for _, tag := range p.Build.Tags {
cmds = append(cmds, commandTag(p.Build, tag)) // docker tag
if p.Dryrun == false {
if !p.Dryrun {
cmds = append(cmds, commandPush(p.Build, tag)) // docker push
}
}
@@ -336,44 +336,6 @@ func commandPush(build Build, tag string) *exec.Cmd {
return exec.Command(dockerExe, "push", target)
}
// helper function to create the docker daemon command.
func commandDaemon(daemon Daemon) *exec.Cmd {
args := []string{
"--data-root", daemon.StoragePath,
"--host=unix:///var/run/docker.sock",
}
if daemon.StorageDriver != "" {
args = append(args, "-s", daemon.StorageDriver)
}
if daemon.Insecure && daemon.Registry != "" {
args = append(args, "--insecure-registry", daemon.Registry)
}
if daemon.IPv6 {
args = append(args, "--ipv6")
}
if len(daemon.Mirror) != 0 {
args = append(args, "--registry-mirror", daemon.Mirror)
}
if len(daemon.Bip) != 0 {
args = append(args, "--bip", daemon.Bip)
}
for _, dns := range daemon.DNS {
args = append(args, "--dns", dns)
}
for _, dnsSearch := range daemon.DNSSearch {
args = append(args, "--dns-search", dnsSearch)
}
if len(daemon.MTU) != 0 {
args = append(args, "--mtu", daemon.MTU)
}
if daemon.Experimental {
args = append(args, "--experimental")
}
return exec.Command(dockerdExe, args...)
}
// helper to check if args match "docker prune"
func isCommandPrune(args []string) bool {
return len(args) > 3 && args[2] == "prune"