Compare commits
No commits in common. "master" and "docs" have entirely different histories.
366 changed files with 7648 additions and 9171 deletions
105
.drone.star
105
.drone.star
|
|
@ -1,105 +0,0 @@
|
|||
# go version
|
||||
go = "golang:1.13"
|
||||
|
||||
# docker repository
|
||||
repo = "drone/drone-runner-docker"
|
||||
|
||||
def main(ctx):
|
||||
return [
|
||||
pipeline_linux(),
|
||||
pipeline_windows("1903"),
|
||||
pipeline_windows("1809"),
|
||||
pipeline_manifest(),
|
||||
# manifest
|
||||
]
|
||||
|
||||
|
||||
def pipeline_linux():
|
||||
return {
|
||||
"kind": "pipeline",
|
||||
"type": "docker",
|
||||
"name": "linux",
|
||||
"steps": [
|
||||
test,
|
||||
build,
|
||||
publish("arm"),
|
||||
publish("arm64"),
|
||||
publish("amd64"),
|
||||
]
|
||||
}
|
||||
|
||||
def pipeline_windows(version):
|
||||
return {
|
||||
"kind": "pipeline",
|
||||
"type": "ssh",
|
||||
"name": "windows_%s" % version,
|
||||
"server": {
|
||||
|
||||
},
|
||||
"platform": {
|
||||
"os": "windows",
|
||||
},
|
||||
"steps": [
|
||||
"sh scripts/ci_%s.ps1" % version,
|
||||
],
|
||||
}
|
||||
|
||||
def pipeline_manifest():
|
||||
return [
|
||||
"kind": "pipeline",
|
||||
"type": "docker",
|
||||
"name": "linux",
|
||||
"steps": [
|
||||
{
|
||||
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
# publish creates a docker publish step.
|
||||
def publish(arch):
|
||||
return {
|
||||
"name": "publish_%s" % arch,
|
||||
"image": "plugins/docker",
|
||||
"pull": "if-not-exists",
|
||||
"settings": {
|
||||
"auto_tag": "true",
|
||||
"auto_tag_suffix": "linux-%s" % arch,
|
||||
"dockerfile": "docker/Dockerfile.linux.%s" % arch,
|
||||
"repo": repo,
|
||||
},
|
||||
"when": {
|
||||
"event": [ "push", "tag" ]
|
||||
}
|
||||
}
|
||||
|
||||
# test defines a test step that downloads
|
||||
# dependencies and tests the packages.
|
||||
test = {
|
||||
"name": "test",
|
||||
"image": go,
|
||||
"volumes": mounts,
|
||||
"commands": [
|
||||
"go test -v ./...",
|
||||
],
|
||||
}
|
||||
|
||||
# build defines a build step that compiles
|
||||
# the binaries.
|
||||
build = {
|
||||
"name": "build",
|
||||
"image": go,
|
||||
"volumes": mounts,
|
||||
"commands": [
|
||||
"sh scripts/build.sh",
|
||||
],
|
||||
"when": {
|
||||
"event": [ "push", "tag" ]
|
||||
}
|
||||
}
|
||||
|
||||
# mount points shared by all steps.
|
||||
mounts = [{
|
||||
"name": "go",
|
||||
"path": "/go",
|
||||
}]
|
||||
213
.drone.yml
213
.drone.yml
|
|
@ -1,208 +1,29 @@
|
|||
kind: pipeline
|
||||
type: docker
|
||||
name: linux
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
name: documentation
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: golang:1.12
|
||||
- name: download
|
||||
image: alpine/git
|
||||
pull: if-not-exists
|
||||
commands:
|
||||
- go test -cover ./...
|
||||
volumes:
|
||||
- name: go
|
||||
path: /go
|
||||
- git clone https://github.com/drone/drone-hugo-theme.git themes/drone-hugo-theme
|
||||
|
||||
- name: build
|
||||
image: golang:1.12
|
||||
commands:
|
||||
- sh scripts/build.sh
|
||||
volumes:
|
||||
- name: go
|
||||
path: /go
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- tag
|
||||
|
||||
- name: publish_amd64
|
||||
image: plugins/docker
|
||||
pull: if-not-exists
|
||||
image: plugins/hugo
|
||||
settings:
|
||||
repo: drone/drone-runner-docker
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-amd64
|
||||
dockerfile: docker/Dockerfile.linux.amd64
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
when:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/*
|
||||
hugo_version: 0.55.6
|
||||
config: config.yaml
|
||||
|
||||
- name: publish_arm
|
||||
image: plugins/docker
|
||||
pull: if-not-exists
|
||||
- name: publish
|
||||
image: lucap/drone-netlify
|
||||
settings:
|
||||
repo: drone/drone-runner-docker
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm
|
||||
dockerfile: docker/Dockerfile.linux.arm
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
when:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/*
|
||||
|
||||
- name: publish_arm64
|
||||
image: plugins/docker
|
||||
pull: if-not-exists
|
||||
settings:
|
||||
repo: drone/drone-runner-docker
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm64
|
||||
dockerfile: docker/Dockerfile.linux.arm64
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
when:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/*
|
||||
|
||||
volumes:
|
||||
- name: go
|
||||
temp: {}
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: ssh
|
||||
name: windows-1903
|
||||
|
||||
platform:
|
||||
os: windows
|
||||
|
||||
server:
|
||||
host:
|
||||
from_secret: windows_server_1903
|
||||
password:
|
||||
from_secret: windows_password
|
||||
user:
|
||||
from_secret: windows_username
|
||||
|
||||
steps:
|
||||
- name: build_latest
|
||||
environment:
|
||||
VERSION: 1903
|
||||
USERNAME:
|
||||
from_secret: docker_username
|
||||
PASSWORD:
|
||||
from_secret: docker_password
|
||||
commands:
|
||||
- powershell.exe scripts/windows/latest.ps1
|
||||
when:
|
||||
event: [ push ]
|
||||
|
||||
- name: build_tag
|
||||
environment:
|
||||
VERSION: 1903
|
||||
USERNAME:
|
||||
from_secret: docker_username
|
||||
PASSWORD:
|
||||
from_secret: docker_password
|
||||
commands:
|
||||
- powershell.exe scripts/windows/tag.ps1
|
||||
when:
|
||||
event: [ tag ]
|
||||
|
||||
depends_on:
|
||||
- linux
|
||||
path: ./public
|
||||
site_id:
|
||||
from_secret: netlify_site_id
|
||||
token:
|
||||
from_secret: netlify_token
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/*
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: ssh
|
||||
name: windows-1809
|
||||
|
||||
platform:
|
||||
os: windows
|
||||
|
||||
server:
|
||||
host:
|
||||
from_secret: windows_server_1809
|
||||
password:
|
||||
from_secret: windows_password
|
||||
user:
|
||||
from_secret: windows_username
|
||||
|
||||
steps:
|
||||
- name: build_latest
|
||||
environment:
|
||||
VERSION: 1809
|
||||
USERNAME:
|
||||
from_secret: docker_username
|
||||
PASSWORD:
|
||||
from_secret: docker_password
|
||||
commands:
|
||||
- powershell.exe scripts/windows/latest.ps1
|
||||
when:
|
||||
event: [ push ]
|
||||
|
||||
- name: build_tag
|
||||
environment:
|
||||
VERSION: 1809
|
||||
USERNAME:
|
||||
from_secret: docker_username
|
||||
PASSWORD:
|
||||
from_secret: docker_password
|
||||
commands:
|
||||
- powershell.exe scripts/windows/tag.ps1
|
||||
when:
|
||||
event: [ tag ]
|
||||
|
||||
depends_on:
|
||||
- linux
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/*
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: manifest
|
||||
|
||||
steps:
|
||||
- name: manifest
|
||||
image: plugins/manifest
|
||||
settings:
|
||||
spec: docker/manifest.tmpl
|
||||
auto_tag: true
|
||||
ignore_missing: true
|
||||
password:
|
||||
from_secret: docker_password
|
||||
username:
|
||||
from_secret: docker_username
|
||||
|
||||
depends_on:
|
||||
- windows-1903
|
||||
- windows-1809
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/*
|
||||
|
||||
event:
|
||||
- push
|
||||
|
|
|
|||
0
.github/issue_template.md
vendored
0
.github/issue_template.md
vendored
0
.github/pull_request_template.md
vendored
0
.github/pull_request_template.md
vendored
36
.github/security.md
vendored
36
.github/security.md
vendored
|
|
@ -1,36 +0,0 @@
|
|||
# Security Policies and Procedures
|
||||
|
||||
This document outlines security procedures and general policies for this project.
|
||||
|
||||
* [Reporting a Bug](#reporting-a-bug)
|
||||
* [Disclosure Policy](#disclosure-policy)
|
||||
* [Comments on this Policy](#comments-on-this-policy)
|
||||
|
||||
## Reporting a Bug
|
||||
|
||||
Report security bugs by emailing the lead maintainer at security@drone.io.
|
||||
|
||||
The lead maintainer will acknowledge your email within 48 hours, and will send a
|
||||
more detailed response within 48 hours indicating the next steps in handling
|
||||
your report. After the initial reply to your report, the security team will
|
||||
endeavor to keep you informed of the progress towards a fix and full
|
||||
announcement, and may ask for additional information or guidance.
|
||||
|
||||
Report security bugs in third-party packages to the person or team maintaining
|
||||
the module.
|
||||
|
||||
## Disclosure Policy
|
||||
|
||||
When the security team receives a security bug report, they will assign it to a
|
||||
primary handler. This person will coordinate the fix and release process,
|
||||
involving the following steps:
|
||||
|
||||
* Confirm the problem and determine the affected versions.
|
||||
* Audit code to find any potential similar problems.
|
||||
* Prepare fixes for all releases still under maintenance. These fixes will be
|
||||
released as fast as possible.
|
||||
|
||||
## Comments on this Policy
|
||||
|
||||
If you have suggestions on how this process could be improved please submit a
|
||||
pull request.
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -1,6 +1,5 @@
|
|||
drone-runner-docker
|
||||
drone-runner-docker.exe
|
||||
release/*
|
||||
.docker
|
||||
.env
|
||||
release/*
|
||||
public/*
|
||||
themes/*
|
||||
NOTES*
|
||||
|
|
|
|||
14
BUILDING.md
14
BUILDING.md
|
|
@ -1,14 +0,0 @@
|
|||
1. Install go 1.13 or higher
|
||||
2. Test
|
||||
|
||||
go test ./...
|
||||
|
||||
3. Build binaries
|
||||
|
||||
sh scripts/build_all.sh
|
||||
|
||||
4. Build images
|
||||
|
||||
docker build -t drone/drone-runner-docker:latest-linux-amd64 -f docker/Dockerfile.linux.amd64 .
|
||||
docker build -t drone/drone-runner-docker:latest-linux-arm64 -f docker/Dockerfile.linux.arm64 .
|
||||
docker build -t drone/drone-runner-docker:latest-linux-arm -f docker/Dockerfile.linux.arm .
|
||||
24
CHANGELOG.md
24
CHANGELOG.md
|
|
@ -1,24 +0,0 @@
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
### Changed
|
||||
|
||||
- use trace level logging for context errors
|
||||
- prefix named docker resources with drone-
|
||||
|
||||
### Added
|
||||
- support for global environment variable extension
|
||||
|
||||
## 1.0.1
|
||||
### Fixed
|
||||
|
||||
- handle pipelines with missing names
|
||||
- prevent mounting /run/drone directory
|
||||
|
||||
## 1.0.0
|
||||
### Added
|
||||
|
||||
- ported docker pipelines to runner-go framework
|
||||
- support for pipeline environment variables
|
||||
- support for shm_size
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
[Polyform-Small-Business-1.0.0](https://polyformproject.org/licenses/small-business/1.0.0) OR
|
||||
[Polyform-Free-Trial-1.0.0](https://polyformproject.org/licenses/free-trial/1.0.0)
|
||||
12
README.md
12
README.md
|
|
@ -1,12 +0,0 @@
|
|||
# drone-runner-docker
|
||||
|
||||
The `docker` runner executes pipelines inside Docker containers. This runner is intended for linux workloads that are suitable for execution inside containers. This requires Drone server `1.6.0` or higher.
|
||||
|
||||
Documentation:<br/>
|
||||
https://docker-runner.docs.drone.io
|
||||
|
||||
Technical Support:<br/>
|
||||
https://discourse.drone.io
|
||||
|
||||
Issue Tracker and Roadmap:<br/>
|
||||
https://trello.com/b/ttae5E5o/drone
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/drone-runners/drone-runner-docker/command/daemon"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
// program version
|
||||
var version = "0.0.0"
|
||||
|
||||
// empty context
|
||||
var nocontext = context.Background()
|
||||
|
||||
// Command parses the command line arguments and then executes a
|
||||
// subcommand program.
|
||||
func Command() {
|
||||
app := kingpin.New("drone", "drone exec runner")
|
||||
registerCompile(app)
|
||||
registerExec(app)
|
||||
daemon.Register(app)
|
||||
|
||||
kingpin.Version(version)
|
||||
kingpin.MustParse(app.Parse(os.Args[1:]))
|
||||
}
|
||||
|
|
@ -1,197 +0,0 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/drone-runners/drone-runner-docker/command/internal"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/compiler"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/linter"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/resource"
|
||||
"github.com/drone/envsubst"
|
||||
"github.com/drone/runner-go/environ"
|
||||
"github.com/drone/runner-go/environ/provider"
|
||||
"github.com/drone/runner-go/manifest"
|
||||
"github.com/drone/runner-go/registry"
|
||||
"github.com/drone/runner-go/secret"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type compileCommand struct {
|
||||
*internal.Flags
|
||||
|
||||
Source *os.File
|
||||
Privileged []string
|
||||
Networks []string
|
||||
Volumes map[string]string
|
||||
Environ map[string]string
|
||||
Labels map[string]string
|
||||
Secrets map[string]string
|
||||
Resources compiler.Resources
|
||||
Clone bool
|
||||
Config string
|
||||
}
|
||||
|
||||
func (c *compileCommand) run(*kingpin.ParseContext) error {
|
||||
rawsource, err := ioutil.ReadAll(c.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
envs := environ.Combine(
|
||||
c.Environ,
|
||||
environ.System(c.System),
|
||||
environ.Repo(c.Repo),
|
||||
environ.Build(c.Build),
|
||||
environ.Stage(c.Stage),
|
||||
environ.Link(c.Repo, c.Build, c.System),
|
||||
c.Build.Params,
|
||||
)
|
||||
|
||||
// string substitution function ensures that string
|
||||
// replacement variables are escaped and quoted if they
|
||||
// contain newlines.
|
||||
subf := func(k string) string {
|
||||
v := envs[k]
|
||||
if strings.Contains(v, "\n") {
|
||||
v = fmt.Sprintf("%q", v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// evaluates string replacement expressions and returns an
|
||||
// update configuration.
|
||||
config, err := envsubst.Eval(string(rawsource), subf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// parse and lint the configuration
|
||||
manifest, err := manifest.ParseString(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// a configuration can contain multiple pipelines.
|
||||
// get a specific pipeline resource for execution.
|
||||
resource, err := resource.Lookup(c.Stage.Name, manifest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// lint the pipeline and return an error if any
|
||||
// linting rules are broken
|
||||
lint := linter.New()
|
||||
opts := linter.Opts{Trusted: c.Repo.Trusted}
|
||||
err = lint.Lint(resource, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// compile the pipeline to an intermediate representation.
|
||||
comp := &compiler.Compiler{
|
||||
Environ: provider.Static(c.Environ),
|
||||
Labels: c.Labels,
|
||||
Resources: c.Resources,
|
||||
Privileged: append(c.Privileged, compiler.Privileged...),
|
||||
Networks: c.Networks,
|
||||
Volumes: c.Volumes,
|
||||
Secret: secret.StaticVars(c.Secrets),
|
||||
Registry: registry.Combine(
|
||||
registry.File(c.Config),
|
||||
),
|
||||
}
|
||||
|
||||
// when running a build locally cloning is always
|
||||
// disabled in favor of mounting the source code
|
||||
// from the current working directory.
|
||||
if c.Clone == false {
|
||||
comp.Mount, _ = os.Getwd()
|
||||
}
|
||||
|
||||
args := compiler.Args{
|
||||
Pipeline: resource,
|
||||
Manifest: manifest,
|
||||
Build: c.Build,
|
||||
Netrc: c.Netrc,
|
||||
Repo: c.Repo,
|
||||
Stage: c.Stage,
|
||||
System: c.System,
|
||||
}
|
||||
spec := comp.Compile(nocontext, args)
|
||||
|
||||
// encode the pipeline in json format and print to the
|
||||
// console for inspection.
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(spec)
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerCompile(app *kingpin.Application) {
|
||||
c := new(compileCommand)
|
||||
c.Environ = map[string]string{}
|
||||
c.Secrets = map[string]string{}
|
||||
c.Labels = map[string]string{}
|
||||
c.Volumes = map[string]string{}
|
||||
|
||||
cmd := app.Command("compile", "compile the yaml file").
|
||||
Action(c.run)
|
||||
|
||||
cmd.Flag("source", "source file location").
|
||||
Default(".drone.yml").
|
||||
FileVar(&c.Source)
|
||||
|
||||
cmd.Flag("clone", "enable cloning").
|
||||
BoolVar(&c.Clone)
|
||||
|
||||
cmd.Flag("secrets", "secret parameters").
|
||||
StringMapVar(&c.Secrets)
|
||||
|
||||
cmd.Flag("environ", "environment variables").
|
||||
StringMapVar(&c.Environ)
|
||||
|
||||
cmd.Flag("labels", "container labels").
|
||||
StringMapVar(&c.Labels)
|
||||
|
||||
cmd.Flag("networks", "container networks").
|
||||
StringsVar(&c.Networks)
|
||||
|
||||
cmd.Flag("volumes", "container volumes").
|
||||
StringMapVar(&c.Volumes)
|
||||
|
||||
cmd.Flag("privileged", "privileged docker images").
|
||||
StringsVar(&c.Privileged)
|
||||
|
||||
cmd.Flag("cpu-period", "container cpu period").
|
||||
Int64Var(&c.Resources.CPUPeriod)
|
||||
|
||||
cmd.Flag("cpu-quota", "container cpu quota").
|
||||
Int64Var(&c.Resources.CPUQuota)
|
||||
|
||||
cmd.Flag("cpu-set", "container cpu set").
|
||||
StringsVar(&c.Resources.CPUSet)
|
||||
|
||||
cmd.Flag("cpu-shares", "container cpu shares").
|
||||
Int64Var(&c.Resources.CPUShares)
|
||||
|
||||
cmd.Flag("memory", "container memory limit").
|
||||
Int64Var(&c.Resources.Memory)
|
||||
|
||||
cmd.Flag("memory-swap", "container memory swap limit").
|
||||
Int64Var(&c.Resources.MemorySwap)
|
||||
|
||||
cmd.Flag("docker-config", "path to the docker config file").
|
||||
StringVar(&c.Config)
|
||||
|
||||
// shared pipeline flags
|
||||
c.Flags = internal.ParseFlags(cmd)
|
||||
}
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
// Config stores the system configuration.
|
||||
type Config struct {
|
||||
Debug bool `envconfig:"DRONE_DEBUG"`
|
||||
Trace bool `envconfig:"DRONE_TRACE"`
|
||||
|
||||
Client struct {
|
||||
Address string `ignored:"true"`
|
||||
Proto string `envconfig:"DRONE_RPC_PROTO" default:"http"`
|
||||
Host string `envconfig:"DRONE_RPC_HOST" required:"true"`
|
||||
Secret string `envconfig:"DRONE_RPC_SECRET" required:"true"`
|
||||
SkipVerify bool `envconfig:"DRONE_RPC_SKIP_VERIFY"`
|
||||
Dump bool `envconfig:"DRONE_RPC_DUMP_HTTP"`
|
||||
DumpBody bool `envconfig:"DRONE_RPC_DUMP_HTTP_BODY"`
|
||||
}
|
||||
|
||||
Dashboard struct {
|
||||
Disabled bool `envconfig:"DRONE_UI_DISABLE"`
|
||||
Username string `envconfig:"DRONE_UI_USERNAME"`
|
||||
Password string `envconfig:"DRONE_UI_PASSWORD"`
|
||||
Realm string `envconfig:"DRONE_UI_REALM" default:"MyRealm"`
|
||||
}
|
||||
|
||||
Server struct {
|
||||
Port string `envconfig:"DRONE_HTTP_BIND" default:":3000"`
|
||||
Proto string `envconfig:"DRONE_HTTP_PROTO"`
|
||||
Host string `envconfig:"DRONE_HTTP_HOST"`
|
||||
Acme bool `envconfig:"DRONE_HTTP_ACME"`
|
||||
}
|
||||
|
||||
Runner struct {
|
||||
Name string `envconfig:"DRONE_RUNNER_NAME"`
|
||||
Capacity int `envconfig:"DRONE_RUNNER_CAPACITY" default:"2"`
|
||||
Procs int64 `envconfig:"DRONE_RUNNER_MAX_PROCS"`
|
||||
Environ map[string]string `envconfig:"DRONE_RUNNER_ENVIRON"`
|
||||
EnvFile string `envconfig:"DRONE_RUNNER_ENV_FILE"`
|
||||
Secrets map[string]string `envconfig:"DRONE_RUNNER_SECRETS"`
|
||||
Labels map[string]string `envconfig:"DRONE_RUNNER_LABELS"`
|
||||
Volumes map[string]string `envconfig:"DRONE_RUNNER_VOLUMES"`
|
||||
Devices []string `envconfig:"DRONE_RUNNER_DEVICES"`
|
||||
Networks []string `envconfig:"DRONE_RUNNER_NETWORKS"`
|
||||
Privileged []string `envconfig:"DRONE_RUNNER_PRIVILEGED_IMAGES"`
|
||||
Clone string `envconfig:"DRONE_RUNNER_CLONE_IMAGE"`
|
||||
}
|
||||
|
||||
Platform struct {
|
||||
OS string `envconfig:"DRONE_PLATFORM_OS" default:"linux"`
|
||||
Arch string `envconfig:"DRONE_PLATFORM_ARCH" default:"amd64"`
|
||||
Kernel string `envconfig:"DRONE_PLATFORM_KERNEL"`
|
||||
Variant string `envconfig:"DRONE_PLATFORM_VARIANT"`
|
||||
}
|
||||
|
||||
Limit struct {
|
||||
Repos []string `envconfig:"DRONE_LIMIT_REPOS"`
|
||||
Events []string `envconfig:"DRONE_LIMIT_EVENTS"`
|
||||
Trusted bool `envconfig:"DRONE_LIMIT_TRUSTED"`
|
||||
}
|
||||
|
||||
Resources struct {
|
||||
Memory int64 `envconfig:"DRONE_MEMORY_LIMIT"`
|
||||
MemorySwap int64 `envconfig:"DRONE_MEMORY_SWAP_LIMIT"`
|
||||
CPUQuota int64 `envconfig:"DRONE_CPU_QUOTA"`
|
||||
CPUPeriod int64 `envconfig:"DRONE_CPU_PERIOD"`
|
||||
CPUShares int64 `envconfig:"DRONE_CPU_SHARES"`
|
||||
CPUSet []string `envconfig:"DRONE_CPU_SET"`
|
||||
}
|
||||
|
||||
Environ struct {
|
||||
Endpoint string `envconfig:"DRONE_ENV_PLUGIN_ENDPOINT"`
|
||||
Token string `envconfig:"DRONE_ENV_PLUGIN_TOKEN"`
|
||||
SkipVerify bool `envconfig:"DRONE_ENV_PLUGIN_SKIP_VERIFY"`
|
||||
}
|
||||
|
||||
Secret struct {
|
||||
Endpoint string `envconfig:"DRONE_SECRET_PLUGIN_ENDPOINT"`
|
||||
Token string `envconfig:"DRONE_SECRET_PLUGIN_TOKEN"`
|
||||
SkipVerify bool `envconfig:"DRONE_SECRET_PLUGIN_SKIP_VERIFY"`
|
||||
}
|
||||
|
||||
Registry struct {
|
||||
Endpoint string `envconfig:"DRONE_REGISTRY_PLUGIN_ENDPOINT"`
|
||||
Token string `envconfig:"DRONE_REGISTRY_PLUGIN_SECRET"`
|
||||
SkipVerify bool `envconfig:"DRONE_REGISTRY_PLUGIN_SKIP_VERIFY"`
|
||||
}
|
||||
|
||||
Docker struct {
|
||||
Config string `envconfig:"DRONE_DOCKER_CONFIG"`
|
||||
Stream bool `envconfig:"DRONE_DOCKER_STREAM_PULL" default:"true"`
|
||||
}
|
||||
}
|
||||
|
||||
// legacy environment variables. the key is the legacy
|
||||
// variable name, and the value is the new variable name.
|
||||
var legacy = map[string]string{
|
||||
"DRONE_MACHINE": "DRONE_RUNNER_NAME",
|
||||
"DRONE_RUNNER_OS": "DRONE_PLATFORM_OS",
|
||||
"DRONE_RUNNER_ARCH": "DRONE_PLATFORM_ARCH",
|
||||
"DRONE_RUNNER_KERNEL": "DRONE_PLATFORM_KERNEL",
|
||||
"DRONE_RUNNER_VARIANT": "DRONE_PLATFORM_VARIANT",
|
||||
"DRONE_REGISTRY_ENDPOINT": "DRONE_REGISTRY_PLUGIN_ENDPOINT",
|
||||
"DRONE_REGISTRY_SECRET": "DRONE_REGISTRY_PLUGIN_SECRET",
|
||||
"DRONE_REGISTRY_SKIP_VERIFY": "DRONE_REGISTRY_PLUGIN_SKIP_VERIFY",
|
||||
"DRONE_SECRET_ENDPOINT": "DRONE_SECRET_PLUGIN_ENDPOINT",
|
||||
"DRONE_SECRET_SECRET": "DRONE_SECRET_PLUGIN_TOKEN",
|
||||
"DRONE_SECRET_SKIP_VERIFY": "DRONE_SECRET_PLUGIN_SKIP_VERIFY",
|
||||
"DRONE_LIMIT_MEM_SWAP": "DRONE_MEMORY_SWAP_LIMIT",
|
||||
"DRONE_LIMIT_MEM": "DRONE_MEMORY_LIMIT",
|
||||
"DRONE_LIMIT_CPU_QUOTA": "DRONE_CPU_QUOTA",
|
||||
"DRONE_LIMIT_CPU_SHARES": "DRONE_CPU_SHARES",
|
||||
"DRONE_LIMIT_CPU_SET": "DRONE_CPU_SET",
|
||||
"DRONE_LOGS_DEBUG": "DRONE_DEBUG",
|
||||
"DRONE_LOGS_TRACE": "DRONE_TRACE",
|
||||
"DRONE_SERVER_PROTO": "DRONE_HTTP_PROTO",
|
||||
"DRONE_SERVER_HOST": "DRONE_HTTP_HOST",
|
||||
"DRONE_SERVER_PORT": "DRONE_HTTP_BIND",
|
||||
"DRONE_SERVER_ACME": "DRONE_HTTP_ACME",
|
||||
}
|
||||
|
||||
func fromEnviron() (Config, error) {
|
||||
// loop through legacy environment variable and, if set
|
||||
// rewrite to the new variable name.
|
||||
for k, v := range legacy {
|
||||
if s, ok := os.LookupEnv(k); ok {
|
||||
os.Setenv(v, s)
|
||||
}
|
||||
}
|
||||
|
||||
var config Config
|
||||
err := envconfig.Process("", &config)
|
||||
if err != nil {
|
||||
return config, err
|
||||
}
|
||||
if config.Runner.Name == "" {
|
||||
config.Runner.Name, _ = os.Hostname()
|
||||
}
|
||||
if config.Dashboard.Password == "" {
|
||||
config.Dashboard.Disabled = true
|
||||
}
|
||||
config.Client.Address = fmt.Sprintf(
|
||||
"%s://%s",
|
||||
config.Client.Proto,
|
||||
config.Client.Host,
|
||||
)
|
||||
|
||||
// environment variables can be sourced from a separate
|
||||
// file. These variables are loaded and appended to the
|
||||
// environment list.
|
||||
if file := config.Runner.EnvFile; file != "" {
|
||||
envs, err := godotenv.Read(file)
|
||||
if err != nil {
|
||||
return config, err
|
||||
}
|
||||
for k, v := range envs {
|
||||
config.Runner.Environ[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
|
@ -1,269 +0,0 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/drone-runners/drone-runner-docker/engine"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/compiler"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/linter"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/resource"
|
||||
"github.com/drone-runners/drone-runner-docker/internal/match"
|
||||
"github.com/drone-runners/drone-runner-docker/runtime"
|
||||
|
||||
"github.com/drone/runner-go/client"
|
||||
"github.com/drone/runner-go/environ/provider"
|
||||
"github.com/drone/runner-go/handler/router"
|
||||
"github.com/drone/runner-go/logger"
|
||||
loghistory "github.com/drone/runner-go/logger/history"
|
||||
"github.com/drone/runner-go/pipeline/history"
|
||||
"github.com/drone/runner-go/pipeline/remote"
|
||||
"github.com/drone/runner-go/registry"
|
||||
"github.com/drone/runner-go/secret"
|
||||
"github.com/drone/runner-go/server"
|
||||
"github.com/drone/signal"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
// empty context.
|
||||
var nocontext = context.Background()
|
||||
|
||||
type daemonCommand struct {
|
||||
envfile string
|
||||
}
|
||||
|
||||
func (c *daemonCommand) run(*kingpin.ParseContext) error {
|
||||
// load environment variables from file.
|
||||
godotenv.Load(c.envfile)
|
||||
|
||||
// load the configuration from the environment
|
||||
config, err := fromEnviron()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// setup the global logrus logger.
|
||||
setupLogger(config)
|
||||
|
||||
ctx, cancel := context.WithCancel(nocontext)
|
||||
defer cancel()
|
||||
|
||||
// listen for termination signals to gracefully shutdown
|
||||
// the runner daemon.
|
||||
ctx = signal.WithContextFunc(ctx, func() {
|
||||
println("received signal, terminating process")
|
||||
cancel()
|
||||
})
|
||||
|
||||
cli := client.New(
|
||||
config.Client.Address,
|
||||
config.Client.Secret,
|
||||
config.Client.SkipVerify,
|
||||
)
|
||||
if config.Client.Dump {
|
||||
cli.Dumper = logger.StandardDumper(
|
||||
config.Client.DumpBody,
|
||||
)
|
||||
}
|
||||
cli.Logger = logger.Logrus(
|
||||
logrus.NewEntry(
|
||||
logrus.StandardLogger(),
|
||||
),
|
||||
)
|
||||
|
||||
opts := engine.Opts{
|
||||
HidePull: !config.Docker.Stream,
|
||||
}
|
||||
engine, err := engine.NewEnv(opts)
|
||||
if err != nil {
|
||||
logrus.WithError(err).
|
||||
Fatalln("cannot load the docker engine")
|
||||
}
|
||||
for {
|
||||
err := engine.Ping(ctx)
|
||||
if err == context.Canceled {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
logrus.WithError(err).
|
||||
Errorln("cannot ping the docker daemon")
|
||||
time.Sleep(time.Second)
|
||||
} else {
|
||||
logrus.Debugln("successfully pinged the docker daemon")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
remote := remote.New(cli)
|
||||
tracer := history.New(remote)
|
||||
hook := loghistory.New()
|
||||
logrus.AddHook(hook)
|
||||
|
||||
poller := &runtime.Poller{
|
||||
Client: cli,
|
||||
Runner: &runtime.Runner{
|
||||
Client: cli,
|
||||
Machine: config.Runner.Name,
|
||||
Reporter: tracer,
|
||||
Linter: linter.New(),
|
||||
Match: match.Func(
|
||||
config.Limit.Repos,
|
||||
config.Limit.Events,
|
||||
config.Limit.Trusted,
|
||||
),
|
||||
Compiler: &compiler.Compiler{
|
||||
Clone: config.Runner.Clone,
|
||||
Privileged: append(config.Runner.Privileged, compiler.Privileged...),
|
||||
Networks: config.Runner.Networks,
|
||||
Volumes: config.Runner.Volumes,
|
||||
Resources: compiler.Resources{
|
||||
Memory: config.Resources.Memory,
|
||||
MemorySwap: config.Resources.MemorySwap,
|
||||
CPUQuota: config.Resources.CPUQuota,
|
||||
CPUPeriod: config.Resources.CPUPeriod,
|
||||
CPUShares: config.Resources.CPUShares,
|
||||
CPUSet: config.Resources.CPUSet,
|
||||
},
|
||||
Environ: provider.Combine(
|
||||
provider.Static(config.Runner.Environ),
|
||||
provider.External(
|
||||
config.Environ.Endpoint,
|
||||
config.Environ.Token,
|
||||
config.Environ.SkipVerify,
|
||||
),
|
||||
),
|
||||
Registry: registry.Combine(
|
||||
registry.File(
|
||||
config.Docker.Config,
|
||||
),
|
||||
registry.External(
|
||||
config.Registry.Endpoint,
|
||||
config.Registry.Token,
|
||||
config.Registry.SkipVerify,
|
||||
),
|
||||
),
|
||||
Secret: secret.Combine(
|
||||
secret.StaticVars(
|
||||
config.Runner.Secrets,
|
||||
),
|
||||
secret.External(
|
||||
config.Secret.Endpoint,
|
||||
config.Secret.Token,
|
||||
config.Secret.SkipVerify,
|
||||
),
|
||||
),
|
||||
},
|
||||
Execer: runtime.NewExecer(
|
||||
tracer,
|
||||
remote,
|
||||
engine,
|
||||
config.Runner.Procs,
|
||||
),
|
||||
},
|
||||
Filter: &client.Filter{
|
||||
Kind: resource.Kind,
|
||||
Type: resource.Type,
|
||||
OS: config.Platform.OS,
|
||||
Arch: config.Platform.Arch,
|
||||
Variant: config.Platform.Variant,
|
||||
Kernel: config.Platform.Kernel,
|
||||
Labels: config.Runner.Labels,
|
||||
},
|
||||
}
|
||||
|
||||
var g errgroup.Group
|
||||
server := server.Server{
|
||||
Addr: config.Server.Port,
|
||||
Handler: router.New(tracer, hook, router.Config{
|
||||
Username: config.Dashboard.Username,
|
||||
Password: config.Dashboard.Password,
|
||||
Realm: config.Dashboard.Realm,
|
||||
}),
|
||||
}
|
||||
|
||||
logrus.WithField("addr", config.Server.Port).
|
||||
Infoln("starting the server")
|
||||
|
||||
g.Go(func() error {
|
||||
return server.ListenAndServe(ctx)
|
||||
})
|
||||
|
||||
// Ping the server and block until a successful connection
|
||||
// to the server has been established.
|
||||
for {
|
||||
err := cli.Ping(ctx, config.Runner.Name)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
logrus.WithError(err).
|
||||
Errorln("cannot ping the remote server")
|
||||
time.Sleep(time.Second)
|
||||
} else {
|
||||
logrus.Infoln("successfully pinged the remote server")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
g.Go(func() error {
|
||||
logrus.WithField("capacity", config.Runner.Capacity).
|
||||
WithField("endpoint", config.Client.Address).
|
||||
WithField("kind", resource.Kind).
|
||||
WithField("type", resource.Type).
|
||||
WithField("os", config.Platform.OS).
|
||||
WithField("arch", config.Platform.Arch).
|
||||
Infoln("polling the remote server")
|
||||
|
||||
poller.Poll(ctx, config.Runner.Capacity)
|
||||
return nil
|
||||
})
|
||||
|
||||
err = g.Wait()
|
||||
if err != nil {
|
||||
logrus.WithError(err).
|
||||
Errorln("shutting down the server")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// helper function configures the global logger from
|
||||
// the loaded configuration.
|
||||
func setupLogger(config Config) {
|
||||
logger.Default = logger.Logrus(
|
||||
logrus.NewEntry(
|
||||
logrus.StandardLogger(),
|
||||
),
|
||||
)
|
||||
if config.Debug {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
if config.Trace {
|
||||
logrus.SetLevel(logrus.TraceLevel)
|
||||
}
|
||||
}
|
||||
|
||||
// Register the daemon command.
|
||||
func Register(app *kingpin.Application) {
|
||||
c := new(daemonCommand)
|
||||
|
||||
cmd := app.Command("daemon", "starts the runner daemon").
|
||||
Default().
|
||||
Action(c.run)
|
||||
|
||||
cmd.Arg("envfile", "load the environment variable file").
|
||||
Default("").
|
||||
StringVar(&c.envfile)
|
||||
}
|
||||
351
command/exec.go
351
command/exec.go
|
|
@ -1,351 +0,0 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/drone-runners/drone-runner-docker/command/internal"
|
||||
"github.com/drone-runners/drone-runner-docker/engine"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/compiler"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/linter"
|
||||
"github.com/drone-runners/drone-runner-docker/engine/resource"
|
||||
"github.com/drone-runners/drone-runner-docker/runtime"
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/envsubst"
|
||||
"github.com/drone/runner-go/environ"
|
||||
"github.com/drone/runner-go/environ/provider"
|
||||
"github.com/drone/runner-go/logger"
|
||||
"github.com/drone/runner-go/manifest"
|
||||
"github.com/drone/runner-go/pipeline"
|
||||
"github.com/drone/runner-go/pipeline/console"
|
||||
"github.com/drone/runner-go/registry"
|
||||
"github.com/drone/runner-go/secret"
|
||||
"github.com/drone/signal"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type execCommand struct {
|
||||
*internal.Flags
|
||||
|
||||
Source *os.File
|
||||
Include []string
|
||||
Exclude []string
|
||||
Privileged []string
|
||||
Networks []string
|
||||
Volumes map[string]string
|
||||
Environ map[string]string
|
||||
Labels map[string]string
|
||||
Secrets map[string]string
|
||||
Resources compiler.Resources
|
||||
Clone bool
|
||||
Config string
|
||||
Pretty bool
|
||||
Procs int64
|
||||
Debug bool
|
||||
Trace bool
|
||||
Dump bool
|
||||
PublicKey string
|
||||
PrivateKey string
|
||||
}
|
||||
|
||||
func (c *execCommand) run(*kingpin.ParseContext) error {
|
||||
rawsource, err := ioutil.ReadAll(c.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
envs := environ.Combine(
|
||||
c.Environ,
|
||||
environ.System(c.System),
|
||||
environ.Repo(c.Repo),
|
||||
environ.Build(c.Build),
|
||||
environ.Stage(c.Stage),
|
||||
environ.Link(c.Repo, c.Build, c.System),
|
||||
c.Build.Params,
|
||||
)
|
||||
|
||||
// string substitution function ensures that string
|
||||
// replacement variables are escaped and quoted if they
|
||||
// contain newlines.
|
||||
subf := func(k string) string {
|
||||
v := envs[k]
|
||||
if strings.Contains(v, "\n") {
|
||||
v = fmt.Sprintf("%q", v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// evaluates string replacement expressions and returns an
|
||||
// update configuration.
|
||||
config, err := envsubst.Eval(string(rawsource), subf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// parse and lint the configuration.
|
||||
manifest, err := manifest.ParseString(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// a configuration can contain multiple pipelines.
|
||||
// get a specific pipeline resource for execution.
|
||||
resource, err := resource.Lookup(c.Stage.Name, manifest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// lint the pipeline and return an error if any
|
||||
// linting rules are broken
|
||||
lint := linter.New()
|
||||
opts := linter.Opts{Trusted: c.Repo.Trusted}
|
||||
err = lint.Lint(resource, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// compile the pipeline to an intermediate representation.
|
||||
comp := &compiler.Compiler{
|
||||
Environ: provider.Static(c.Environ),
|
||||
Labels: c.Labels,
|
||||
Resources: c.Resources,
|
||||
Privileged: append(c.Privileged, compiler.Privileged...),
|
||||
Networks: c.Networks,
|
||||
Volumes: c.Volumes,
|
||||
Secret: secret.StaticVars(c.Secrets),
|
||||
Registry: registry.Combine(
|
||||
registry.File(c.Config),
|
||||
),
|
||||
}
|
||||
|
||||
// when running a build locally cloning is always
|
||||
// disabled in favor of mounting the source code
|
||||
// from the current working directory.
|
||||
if c.Clone == false {
|
||||
comp.Mount, _ = os.Getwd()
|
||||
}
|
||||
|
||||
args := compiler.Args{
|
||||
Pipeline: resource,
|
||||
Manifest: manifest,
|
||||
Build: c.Build,
|
||||
Netrc: c.Netrc,
|
||||
Repo: c.Repo,
|
||||
Stage: c.Stage,
|
||||
System: c.System,
|
||||
}
|
||||
spec := comp.Compile(nocontext, args)
|
||||
|
||||
// include only steps that are in the include list,
|
||||
// if the list in non-empty.
|
||||
if len(c.Include) > 0 {
|
||||
I:
|
||||
for _, step := range spec.Steps {
|
||||
if step.Name == "clone" {
|
||||
continue
|
||||
}
|
||||
for _, name := range c.Include {
|
||||
if step.Name == name {
|
||||
continue I
|
||||
}
|
||||
}
|
||||
step.RunPolicy = engine.RunNever
|
||||
}
|
||||
}
|
||||
|
||||
// exclude steps that are in the exclude list,
|
||||
// if the list in non-empty.
|
||||
if len(c.Exclude) > 0 {
|
||||
E:
|
||||
for _, step := range spec.Steps {
|
||||
if step.Name == "clone" {
|
||||
continue
|
||||
}
|
||||
for _, name := range c.Exclude {
|
||||
if step.Name == name {
|
||||
step.RunPolicy = engine.RunNever
|
||||
continue E
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create a step object for each pipeline step.
|
||||
for _, step := range spec.Steps {
|
||||
if step.RunPolicy == engine.RunNever {
|
||||
continue
|
||||
}
|
||||
c.Stage.Steps = append(c.Stage.Steps, &drone.Step{
|
||||
StageID: c.Stage.ID,
|
||||
Number: len(c.Stage.Steps) + 1,
|
||||
Name: step.Name,
|
||||
Status: drone.StatusPending,
|
||||
ErrIgnore: step.IgnoreErr,
|
||||
})
|
||||
}
|
||||
|
||||
// configures the pipeline timeout.
|
||||
timeout := time.Duration(c.Repo.Timeout) * time.Minute
|
||||
ctx, cancel := context.WithTimeout(nocontext, timeout)
|
||||
defer cancel()
|
||||
|
||||
// listen for operating system signals and cancel execution
|
||||
// when received.
|
||||
ctx = signal.WithContextFunc(ctx, func() {
|
||||
println("received signal, terminating process")
|
||||
cancel()
|
||||
})
|
||||
|
||||
state := &pipeline.State{
|
||||
Build: c.Build,
|
||||
Stage: c.Stage,
|
||||
Repo: c.Repo,
|
||||
System: c.System,
|
||||
}
|
||||
|
||||
// enable debug logging
|
||||
logrus.SetLevel(logrus.WarnLevel)
|
||||
if c.Debug {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
if c.Trace {
|
||||
logrus.SetLevel(logrus.TraceLevel)
|
||||
}
|
||||
logger.Default = logger.Logrus(
|
||||
logrus.NewEntry(
|
||||
logrus.StandardLogger(),
|
||||
),
|
||||
)
|
||||
|
||||
engine, err := engine.NewEnv(engine.Opts{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = runtime.NewExecer(
|
||||
pipeline.NopReporter(),
|
||||
console.New(c.Pretty),
|
||||
engine,
|
||||
c.Procs,
|
||||
).Exec(ctx, spec, state)
|
||||
|
||||
if c.Dump {
|
||||
dump(state)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch state.Stage.Status {
|
||||
case drone.StatusError, drone.StatusFailing, drone.StatusKilled:
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func dump(v interface{}) {
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(v)
|
||||
}
|
||||
|
||||
func registerExec(app *kingpin.Application) {
|
||||
c := new(execCommand)
|
||||
c.Environ = map[string]string{}
|
||||
c.Secrets = map[string]string{}
|
||||
c.Labels = map[string]string{}
|
||||
c.Volumes = map[string]string{}
|
||||
|
||||
cmd := app.Command("exec", "executes a pipeline").
|
||||
Action(c.run)
|
||||
|
||||
cmd.Arg("source", "source file location").
|
||||
Default(".drone.yml").
|
||||
FileVar(&c.Source)
|
||||
|
||||
cmd.Flag("clone", "enable cloning").
|
||||
BoolVar(&c.Clone)
|
||||
|
||||
cmd.Flag("secrets", "secret parameters").
|
||||
StringMapVar(&c.Secrets)
|
||||
|
||||
cmd.Flag("include", "include pipeline steps").
|
||||
StringsVar(&c.Include)
|
||||
|
||||
cmd.Flag("exclude", "exclude pipeline steps").
|
||||
StringsVar(&c.Exclude)
|
||||
|
||||
cmd.Flag("environ", "environment variables").
|
||||
StringMapVar(&c.Environ)
|
||||
|
||||
cmd.Flag("labels", "container labels").
|
||||
StringMapVar(&c.Labels)
|
||||
|
||||
cmd.Flag("networks", "container networks").
|
||||
StringsVar(&c.Networks)
|
||||
|
||||
cmd.Flag("volumes", "container volumes").
|
||||
StringMapVar(&c.Volumes)
|
||||
|
||||
cmd.Flag("privileged", "privileged docker images").
|
||||
StringsVar(&c.Privileged)
|
||||
|
||||
cmd.Flag("cpu-period", "container cpu period").
|
||||
Int64Var(&c.Resources.CPUPeriod)
|
||||
|
||||
cmd.Flag("cpu-quota", "container cpu quota").
|
||||
Int64Var(&c.Resources.CPUQuota)
|
||||
|
||||
cmd.Flag("cpu-set", "container cpu set").
|
||||
StringsVar(&c.Resources.CPUSet)
|
||||
|
||||
cmd.Flag("cpu-shares", "container cpu shares").
|
||||
Int64Var(&c.Resources.CPUShares)
|
||||
|
||||
cmd.Flag("memory", "container memory limit").
|
||||
Int64Var(&c.Resources.Memory)
|
||||
|
||||
cmd.Flag("memory-swap", "container memory swap limit").
|
||||
Int64Var(&c.Resources.MemorySwap)
|
||||
|
||||
cmd.Flag("public-key", "public key file path").
|
||||
ExistingFileVar(&c.PublicKey)
|
||||
|
||||
cmd.Flag("private-key", "private key file path").
|
||||
ExistingFileVar(&c.PrivateKey)
|
||||
|
||||
cmd.Flag("docker-config", "path to the docker config file").
|
||||
StringVar(&c.Config)
|
||||
|
||||
cmd.Flag("debug", "enable debug logging").
|
||||
BoolVar(&c.Debug)
|
||||
|
||||
cmd.Flag("trace", "enable trace logging").
|
||||
BoolVar(&c.Trace)
|
||||
|
||||
cmd.Flag("dump", "dump the pipeline state to stdout").
|
||||
BoolVar(&c.Dump)
|
||||
|
||||
cmd.Flag("pretty", "pretty print the output").
|
||||
Default(
|
||||
fmt.Sprint(
|
||||
isatty.IsTerminal(
|
||||
os.Stdout.Fd(),
|
||||
),
|
||||
),
|
||||
).BoolVar(&c.Pretty)
|
||||
|
||||
// shared pipeline flags
|
||||
c.Flags = internal.ParseFlags(cmd)
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
// Flags maps
|
||||
type Flags struct {
|
||||
Build *drone.Build
|
||||
Netrc *drone.Netrc
|
||||
Repo *drone.Repo
|
||||
Stage *drone.Stage
|
||||
System *drone.System
|
||||
}
|
||||
|
||||
// ParseFlags parses the flags from the command args.
|
||||
func ParseFlags(cmd *kingpin.CmdClause) *Flags {
|
||||
f := &Flags{
|
||||
Build: &drone.Build{},
|
||||
Netrc: &drone.Netrc{},
|
||||
Repo: &drone.Repo{},
|
||||
Stage: &drone.Stage{},
|
||||
System: &drone.System{},
|
||||
}
|
||||
|
||||
now := fmt.Sprint(
|
||||
time.Now().Unix(),
|
||||
)
|
||||
|
||||
cmd.Flag("repo-id", "repo id").Default("1").Int64Var(&f.Repo.ID)
|
||||
cmd.Flag("repo-namespace", "repo namespace").Default("").StringVar(&f.Repo.Namespace)
|
||||
cmd.Flag("repo-name", "repo name").Default("").StringVar(&f.Repo.Name)
|
||||
cmd.Flag("repo-slug", "repo slug").Default("").StringVar(&f.Repo.Slug)
|
||||
cmd.Flag("repo-http", "repo http clone url").Default("").StringVar(&f.Repo.HTTPURL)
|
||||
cmd.Flag("repo-ssh", "repo ssh clone url").Default("").StringVar(&f.Repo.SSHURL)
|
||||
cmd.Flag("repo-link", "repo link").Default("").StringVar(&f.Repo.Link)
|
||||
cmd.Flag("repo-branch", "repo branch").Default("").StringVar(&f.Repo.Branch)
|
||||
cmd.Flag("repo-private", "repo private").Default("false").BoolVar(&f.Repo.Private)
|
||||
cmd.Flag("repo-visibility", "repo visibility").Default("").StringVar(&f.Repo.Visibility)
|
||||
cmd.Flag("repo-trusted", "repo trusted").Default("false").BoolVar(&f.Repo.Trusted)
|
||||
cmd.Flag("repo-protected", "repo protected").Default("false").BoolVar(&f.Repo.Protected)
|
||||
cmd.Flag("repo-timeout", "repo timeout in minutes").Default("60").Int64Var(&f.Repo.Timeout)
|
||||
cmd.Flag("repo-created", "repo created").Default(now).Int64Var(&f.Repo.Created)
|
||||
cmd.Flag("repo-updated", "repo updated").Default(now).Int64Var(&f.Repo.Updated)
|
||||
|
||||
cmd.Flag("build-id", "build id").Default("1").Int64Var(&f.Build.ID)
|
||||
cmd.Flag("build-number", "build number").Default("1").Int64Var(&f.Build.Number)
|
||||
cmd.Flag("build-parent", "build parent").Default("0").Int64Var(&f.Build.Parent)
|
||||
cmd.Flag("build-event", "build event").Default("push").StringVar(&f.Build.Event)
|
||||
cmd.Flag("build-action", "build action").Default("").StringVar(&f.Build.Action)
|
||||
cmd.Flag("build-cron", "build cron trigger").Default("").StringVar(&f.Build.Cron)
|
||||
cmd.Flag("build-target", "build deploy target").Default("").StringVar(&f.Build.Deploy)
|
||||
cmd.Flag("build-created", "build created").Default(now).Int64Var(&f.Build.Created)
|
||||
cmd.Flag("build-updated", "build updated").Default(now).Int64Var(&f.Build.Updated)
|
||||
|
||||
cmd.Flag("commit-sender", "commit sender").Default("").StringVar(&f.Build.Sender)
|
||||
cmd.Flag("commit-link", "commit link").Default("").StringVar(&f.Build.Link)
|
||||
cmd.Flag("commit-title", "commit title").Default("").StringVar(&f.Build.Title)
|
||||
cmd.Flag("commit-message", "commit message").Default("").StringVar(&f.Build.Message)
|
||||
cmd.Flag("commit-before", "commit before").Default("").StringVar(&f.Build.Before)
|
||||
cmd.Flag("commit-after", "commit after").Default("").StringVar(&f.Build.After)
|
||||
cmd.Flag("commit-ref", "commit ref").Default("").StringVar(&f.Build.Ref)
|
||||
cmd.Flag("commit-fork", "commit fork").Default("").StringVar(&f.Build.Fork)
|
||||
cmd.Flag("commit-source", "commit source branch").Default("").StringVar(&f.Build.Source)
|
||||
cmd.Flag("commit-target", "commit target branch").Default("").StringVar(&f.Build.Target)
|
||||
|
||||
cmd.Flag("author-login", "commit author login").Default("").StringVar(&f.Build.Author)
|
||||
cmd.Flag("author-name", "commit author name").Default("").StringVar(&f.Build.AuthorName)
|
||||
cmd.Flag("author-email", "commit author email").Default("").StringVar(&f.Build.AuthorEmail)
|
||||
cmd.Flag("author-avatar", "commit author avatar").Default("").StringVar(&f.Build.AuthorAvatar)
|
||||
|
||||
cmd.Flag("stage-id", "stage id").Default("1").Int64Var(&f.Stage.ID)
|
||||
cmd.Flag("stage-number", "stage number").Default("1").IntVar(&f.Stage.Number)
|
||||
cmd.Flag("stage-kind", "stage kind").Default("").StringVar(&f.Stage.Kind)
|
||||
cmd.Flag("stage-type", "stage type").Default("").StringVar(&f.Stage.Type)
|
||||
cmd.Flag("stage-name", "stage name").Default("default").StringVar(&f.Stage.Name)
|
||||
cmd.Flag("stage-os", "stage os").Default("").StringVar(&f.Stage.OS)
|
||||
cmd.Flag("stage-arch", "stage arch").Default("").StringVar(&f.Stage.Arch)
|
||||
cmd.Flag("stage-variant", "stage variant").Default("").StringVar(&f.Stage.Variant)
|
||||
cmd.Flag("stage-kernel", "stage kernel").Default("").StringVar(&f.Stage.Kernel)
|
||||
cmd.Flag("stage-created", "stage created").Default(now).Int64Var(&f.Stage.Created)
|
||||
cmd.Flag("stage-updated", "stage updated").Default(now).Int64Var(&f.Stage.Updated)
|
||||
|
||||
cmd.Flag("netrc-username", "netrc username").Default("").StringVar(&f.Netrc.Login)
|
||||
cmd.Flag("netrc-password", "netrc password").Default("").StringVar(&f.Netrc.Password)
|
||||
cmd.Flag("netrc-machine", "netrc machine").Default("").StringVar(&f.Netrc.Machine)
|
||||
|
||||
cmd.Flag("system-host", "server host").Default("").StringVar(&f.System.Host)
|
||||
cmd.Flag("system-proto", "server proto").Default("").StringVar(&f.System.Proto)
|
||||
cmd.Flag("system-link", "server link").Default("").StringVar(&f.System.Link)
|
||||
cmd.Flag("system-version", "server version").Default("").StringVar(&f.System.Version)
|
||||
|
||||
return f
|
||||
}
|
||||
10
config.yaml
Normal file
10
config.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
baseURL: https://docker-runner.docs.drone.io
|
||||
languageCode: en-us
|
||||
title: Drone Docker Runner
|
||||
theme: drone-hugo-theme
|
||||
|
||||
pygmentsUseClasses: true
|
||||
pygmentsCodefences: true
|
||||
|
||||
outputs:
|
||||
home: ["HTML", "JSON"]
|
||||
23
content/_index.md
Normal file
23
content/_index.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Docker runner
|
||||
author: bradrydzewski
|
||||
weight: 1
|
||||
expand: configuration/_index.md
|
||||
---
|
||||
|
||||
The Docker runner is a daemon that executes build pipelines inside Docker containers. This documentation provides details for installing, configuring and using the Docker runner.
|
||||
|
||||
If you want to install this runner:
|
||||
|
||||
{{< link "/installation" >}}
|
||||
|
||||
If you want to configure this runner for your project:
|
||||
|
||||
{{< link "/configuration" >}}
|
||||
|
||||
{{< link "/examples" >}}
|
||||
|
||||
If you have questions or require assistance:
|
||||
|
||||
{{< link "/support" >}}
|
||||
9
content/configuration/_index.md
Normal file
9
content/configuration/_index.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Configuration
|
||||
author: bradrydzewski
|
||||
weight: 2
|
||||
toc: false
|
||||
---
|
||||
|
||||
Here are the articles in this section:
|
||||
102
content/configuration/cloning.md
Normal file
102
content/configuration/cloning.md
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Cloning
|
||||
author: bradrydzewski
|
||||
weight: 3
|
||||
toc: true
|
||||
description: |
|
||||
Configure the pipeline to use custom clone logic.
|
||||
---
|
||||
|
||||
Drone automatically clones your repository before executing your pipeline steps. No special configuration is required. In some cases, however, you may need to customize, override or disable the default clone behavior.
|
||||
|
||||
# The `--depth` flag
|
||||
|
||||
The default clone configuration does use the `--depth` flag. You can enforce a clone depth by declaring a `clone` block and adding the `depth` attribute:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=5-6" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
clone:
|
||||
depth: 50
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
|
||||
# The `--tags` flag
|
||||
|
||||
The default clone configuration does not use the `--tags` flag. If you would like to fetch tags you should handle this as a step in your pipeline. For example:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=6-9" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: fetch
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git fetch --tags
|
||||
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
|
||||
|
||||
# The `--recursive` flag
|
||||
|
||||
The default clone behavior does not use the `--recursive` flag and does not fetch submodules. If you would like to fetch submodules you should handle this as a step in your pipeline. For example:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=6-9" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: submodules
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git submodule update --recursive --remote
|
||||
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
|
||||
# Custom Logic
|
||||
|
||||
The default clone behavior can be disabled and custom clone logic implemented, when necessary. In the following example we implement custom clone commands as a pipeline step:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=9-13 5-6" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
clone:
|
||||
disable: true
|
||||
|
||||
steps:
|
||||
- name: clone
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git clone https://github.com/octocat/hello-world.git .
|
||||
- git checkout $DRONE_COMMIT
|
||||
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
333
content/configuration/conditions.md
Normal file
333
content/configuration/conditions.md
Normal file
|
|
@ -0,0 +1,333 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Conditions
|
||||
author: bradrydzewski
|
||||
weight: 7
|
||||
toc: true
|
||||
description: |
|
||||
Configure pipeline steps to execute conditionally.
|
||||
---
|
||||
|
||||
Conditions can be used to limit pipeline step execution at runtime. For example, you may want to limit step execution by branch:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=11-14" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
- feature/*
|
||||
{{< / highlight >}}
|
||||
|
||||
You can use wildcard matching in your conditions. _Note that conditions use [glob](https://golang.org/pkg/path/#Match) pattern matching, not regular expressions._
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/heads/**
|
||||
- refs/pull/*/head
|
||||
{{< / highlight >}}
|
||||
|
||||
You can also combine multiple conditions. _Note that all conditions must evaluate to true when combining multiple conditions._
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
- push
|
||||
{{< / highlight >}}
|
||||
|
||||
# By Branch
|
||||
|
||||
The branch condition limits step execution based on the git branch. Please note that the target branch is evaluated for pull requests; and branch names are not available for tag events.
|
||||
|
||||
{{< alert "warn" >}}
|
||||
Note that you cannot use branch conditions with tags. A tag is not associated with the source branch from which it was created.
|
||||
{{< / alert >}}
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
- feature/*
|
||||
{{< / highlight >}}
|
||||
|
||||
Example include syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
branch:
|
||||
include:
|
||||
- master
|
||||
- feature/*
|
||||
{{< / highlight >}}
|
||||
|
||||
Example exclude syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- master
|
||||
- feature/*
|
||||
{{< / highlight >}}
|
||||
|
||||
# By Event
|
||||
|
||||
The event condition limits step execution based on the drone event type. This can be helpful when you want to limit steps based on push, pull request, tag and more.
|
||||
|
||||
{{< alert "warn" >}}
|
||||
Note that you cannot use branch conditions with tag events. A tag is not associated with the source branch from which it was created.
|
||||
{{< / alert >}}
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- pull_request
|
||||
- tag
|
||||
- promote
|
||||
- rollback
|
||||
{{< / highlight >}}
|
||||
|
||||
Example include syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
event:
|
||||
include:
|
||||
- push
|
||||
- pull_request
|
||||
{{< / highlight >}}
|
||||
|
||||
Example exclude syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
{{< / highlight >}}
|
||||
|
||||
# By Reference
|
||||
|
||||
The reference condition limits step execution based on the git reference name. This can be helpful when you want to glob match branch or tag names.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
ref:
|
||||
- refs/heads/feature-*
|
||||
- refs/tags/*
|
||||
{{< / highlight >}}
|
||||
|
||||
Example include syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
ref:
|
||||
include:
|
||||
- refs/heads/feature-*
|
||||
- refs/pull/**
|
||||
- refs/tags/**
|
||||
{{< / highlight >}}
|
||||
|
||||
Example exclude syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
ref:
|
||||
exclude:
|
||||
- refs/heads/feature-*
|
||||
- refs/pull/**
|
||||
- refs/tags/**
|
||||
{{< / highlight >}}
|
||||
|
||||
# By Repository
|
||||
|
||||
The repository condition limits step execution based on repository name. This can be useful when Drone is enabled for a repository and its forks, and you want to limit execution accordingly.
|
||||
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
repo:
|
||||
- octocat/hello-world
|
||||
{{< / highlight >}}
|
||||
|
||||
Example include syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
repo:
|
||||
include:
|
||||
- octocat/hello-world
|
||||
- spacebhost/hello-world
|
||||
{{< / highlight >}}
|
||||
|
||||
Example exclude syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
repo:
|
||||
exclude:
|
||||
- octocat/hello-world
|
||||
- spacebhost/hello-world
|
||||
{{< / highlight >}}
|
||||
|
||||
Example using wildcard matching:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
repo:
|
||||
include:
|
||||
- octocat/*
|
||||
{{< / highlight >}}
|
||||
|
||||
# By Instance
|
||||
|
||||
The instance condition limits step execution based on the Drone instance hostname. This can be useful if you have multiple Drone instances configured for a single repository, sharing the same yaml file, and want to limit steps by instance.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
instance:
|
||||
- drone.instance1.com
|
||||
- drone.instance2.com
|
||||
{{< / highlight >}}
|
||||
|
||||
Example include syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
instance:
|
||||
include:
|
||||
- drone.instance1.com
|
||||
- drone.instance2.com
|
||||
{{< / highlight >}}
|
||||
|
||||
Example exclude syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
instance:
|
||||
exclude:
|
||||
- drone.instance1.com
|
||||
- drone.instance2.com
|
||||
{{< / highlight >}}
|
||||
|
||||
Example using wildcard matching:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
instance:
|
||||
include:
|
||||
- *.company.com
|
||||
{{< / highlight >}}
|
||||
|
||||
# By Status
|
||||
|
||||
The status condition limits step execution based on the pipeline status. For example, you may want to configure Slack notification only on failure.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
status:
|
||||
- failure
|
||||
{{< / highlight >}}
|
||||
|
||||
Execute a step on failure:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
status:
|
||||
- failure
|
||||
{{< / highlight >}}
|
||||
|
||||
Execute a step on success or failure:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
status:
|
||||
- success
|
||||
- failure
|
||||
{{< / highlight >}}
|
||||
|
||||
The following configuration is redundant. The default behavior is for pipeline steps to only execute when the pipeline is in a passing state.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
status:
|
||||
- success
|
||||
{{< / highlight >}}
|
||||
|
||||
# By Target
|
||||
|
||||
The target condition limits step execution based on the target deployment environment. This only applies to promotion and rollback events.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
target:
|
||||
- production
|
||||
{{< / highlight >}}
|
||||
|
||||
Example include syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
target:
|
||||
include:
|
||||
- staging
|
||||
- production
|
||||
{{< / highlight >}}
|
||||
|
||||
Example exclude syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
target:
|
||||
exclude:
|
||||
- production
|
||||
{{< / highlight >}}
|
||||
|
||||
|
||||
# By Cron
|
||||
|
||||
The cron condition limits step execution based on the cron name that triggered the pipeline. This only applies to cron events.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
event:
|
||||
- cron
|
||||
cron:
|
||||
- nightly
|
||||
{{< / highlight >}}
|
||||
|
||||
Example include syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
event:
|
||||
- cron
|
||||
target:
|
||||
include:
|
||||
- weekly
|
||||
- nightly
|
||||
{{< / highlight >}}
|
||||
|
||||
Example exclude syntax:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=11" >}}
|
||||
when:
|
||||
event:
|
||||
- cron
|
||||
target:
|
||||
exclude:
|
||||
- nightly
|
||||
{{< / highlight >}}
|
||||
11
content/configuration/environment/_index.md
Normal file
11
content/configuration/environment/_index.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Environment
|
||||
author: bradrydzewski
|
||||
weight: 2
|
||||
toc: false
|
||||
description: |
|
||||
Configure pipeline environment variables.
|
||||
---
|
||||
|
||||
Here are the articles in this section:
|
||||
83
content/configuration/environment/overview.md
Normal file
83
content/configuration/environment/overview.md
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Environment
|
||||
author: bradrydzewski
|
||||
weight: 1
|
||||
toc: false
|
||||
description: |
|
||||
Configure pipeline environment variables.
|
||||
---
|
||||
|
||||
Drone provides the ability to define environment variables scoped to individual build steps. Example pipeline step with custom environment variables:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=16-18" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
server:
|
||||
host: 1.2.3.4
|
||||
user: root
|
||||
password:
|
||||
from_secret: password
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
environment:
|
||||
GOOS: linux
|
||||
GOARCH: amd64
|
||||
{{< / highlight >}}
|
||||
|
||||
Drone automatically injects environment variables containing repository and commit metadata into each pipeline step. See the environment variable index for a full list of variables.
|
||||
|
||||
{{< link "/configuration/environment/variables" >}}
|
||||
|
||||
# Secrets
|
||||
|
||||
{{< alert "security" >}}
|
||||
Pipelines execute directly on the host without isolation. Any process running on the host may be able to intercept your secrets. You should only expose secrets on a trusted server.
|
||||
{{< / alert >}}
|
||||
|
||||
Drone provides the ability to source environment variables from secrets. In the below example we provide the username and password as environment variables to the step.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=8-11" >}}
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- docker login -u $USERNAME -p $PASSWORD
|
||||
- docker build -t hello-world .
|
||||
- docker push hello-world
|
||||
environment:
|
||||
PASSWORD:
|
||||
from_secret: password
|
||||
USERNAME:
|
||||
from_secret: username
|
||||
{{< / highlight >}}
|
||||
|
||||
# Common Problems
|
||||
|
||||
Please note `${variable}` expressions are subject to pre-processing. If you do not want the pre-processor to evaluate your expression it must be escaped.
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=5,linenostart=5" >}}
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- echo $GOOS
|
||||
- echo $${GOARCH}
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
|
||||
Please also note the environment section cannot expand environment variables or evaluate shell expressions. If you need to construct variables it should be done in the commands section.
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=4,linenostart=5" >}}
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- export GOPATH=$HOME/golang
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
81
content/configuration/environment/substitution.md
Normal file
81
content/configuration/environment/substitution.md
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Substitution
|
||||
author: bradrydzewski
|
||||
weight: 2
|
||||
toc: false
|
||||
description: |
|
||||
Learn how Drone emulates bash string substitution.
|
||||
---
|
||||
|
||||
Drone provides the ability to substitute repository and build metadata to facilitate dynamic pipeline configurations.
|
||||
|
||||
Example commit substitution:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=9" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: publish
|
||||
image: plugins/docker
|
||||
settings:
|
||||
tags: ${DRONE_COMMIT}
|
||||
repo: octocat/hello-world
|
||||
{{< / highlight >}}
|
||||
|
||||
Example tag substitution:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=5,linenostart=5" >}}
|
||||
steps:
|
||||
- name: publish
|
||||
image: plugins/docker
|
||||
settings:
|
||||
tags: ${DRONE_TAG}
|
||||
repo: octocat/hello-world
|
||||
{{< / highlight >}}
|
||||
|
||||
# String Operations
|
||||
|
||||
Drone provides partial emulation for bash string operations. This can be used to manipulate string values prior to substitution.
|
||||
|
||||
Example variable substitution with substring:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=5,linenostart=5" >}}
|
||||
steps:
|
||||
- name: publish
|
||||
image: plugins/docker
|
||||
settings:
|
||||
tags: ${DRONE_COMMIT_SHA:0:8}
|
||||
repo: octocat/hello-world
|
||||
{{< / highlight >}}
|
||||
|
||||
Example variable substitution strips v prefix from v1.0.0:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=5,linenostart=5" >}}
|
||||
steps:
|
||||
- name: publish
|
||||
image: plugins/docker
|
||||
settings:
|
||||
tags: ${DRONE_TAG##v}
|
||||
repo: octocat/hello-world
|
||||
{{< / highlight >}}
|
||||
|
||||
# String Operations Reference
|
||||
|
||||
List of emulated string operations:
|
||||
|
||||
OPERATION | DESC
|
||||
--------------------|---
|
||||
`${param}` | parameter substitution
|
||||
`${param,}` | parameter substitution with lowercase first char
|
||||
`${param,,}` | parameter substitution with lowercase
|
||||
`${param^}` | parameter substitution with uppercase first char
|
||||
`${param^^}` | parameter substitution with uppercase
|
||||
`${param:pos}` | parameter substitution with substring
|
||||
`${param:pos:len}` | parameter substitution with substring and length
|
||||
`${param=default}` | parameter substitution with default
|
||||
`${param##prefix}` | parameter substitution with prefix removal
|
||||
`${param%%suffix}` | parameter substitution with suffix removal
|
||||
`${param/old/new}` | parameter substitution with find and replace
|
||||
99
content/configuration/environment/variables/_gen.go
Normal file
99
content/configuration/environment/variables/_gen.go
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for _, v := range variables {
|
||||
name := strings.ToLower(v + ".md")
|
||||
name = strings.ReplaceAll(name, "_", "-")
|
||||
data := fmt.Sprintf(markdownf, v, v)
|
||||
ioutil.WriteFile(name, []byte(data), 0644)
|
||||
}
|
||||
}
|
||||
|
||||
var markdownf = `---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: %s
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
`+"```"+`
|
||||
%s=
|
||||
`+"```"+`
|
||||
`
|
||||
|
||||
var variables = []string{
|
||||
"CI",
|
||||
"DRONE",
|
||||
"DRONE_SYSTEM_PROTO",
|
||||
"DRONE_SYSTEM_HOST",
|
||||
"DRONE_SYSTEM_HOSTNAME",
|
||||
"DRONE_SYSTEM_VERSION",
|
||||
"DRONE_REPO",
|
||||
"DRONE_REPO_SCM",
|
||||
"DRONE_REPO_OWNER",
|
||||
"DRONE_REPO_NAMESPACE",
|
||||
"DRONE_REPO_NAME",
|
||||
"DRONE_REPO_LINK",
|
||||
"DRONE_REPO_BRANCH",
|
||||
"DRONE_REMOTE_URL",
|
||||
"DRONE_GIT_HTTP_URL",
|
||||
"DRONE_GIT_SSH_URL",
|
||||
"DRONE_REPO_VISIBILITY",
|
||||
"DRONE_REPO_PRIVATE",
|
||||
"DRONE_STAGE_KIND",
|
||||
"DRONE_STAGE_TYPE",
|
||||
"DRONE_STAGE_NAME",
|
||||
"DRONE_STAGE_NUMBER",
|
||||
"DRONE_STAGE_MACHINE",
|
||||
"DRONE_STAGE_OS",
|
||||
"DRONE_STAGE_ARCH",
|
||||
"DRONE_STAGE_VARIANT",
|
||||
"DRONE_STAGE_STATUS",
|
||||
"DRONE_STAGE_STARTED",
|
||||
"DRONE_STAGE_FINISHED",
|
||||
"DRONE_STAGE_DEPENDS_ON",
|
||||
"DRONE_FAILED_STEPS",
|
||||
"DRONE_STEP_NAME",
|
||||
"DRONE_STEP_NUMBER",
|
||||
"DRONE_BRANCH",
|
||||
"DRONE_SOURCE_BRANCH",
|
||||
"DRONE_TARGET_BRANCH",
|
||||
"DRONE_COMMIT",
|
||||
"DRONE_COMMIT_SHA",
|
||||
"DRONE_COMMIT_BEFORE",
|
||||
"DRONE_COMMIT_AFTER",
|
||||
"DRONE_COMMIT_REF",
|
||||
"DRONE_COMMIT_BRANCH",
|
||||
"DRONE_COMMIT_LINK",
|
||||
"DRONE_COMMIT_MESSAGE",
|
||||
"DRONE_COMMIT_AUTHOR",
|
||||
"DRONE_COMMIT_AUTHOR_EMAIL",
|
||||
"DRONE_COMMIT_AUTHOR_AVATAR",
|
||||
"DRONE_COMMIT_AUTHOR_NAME",
|
||||
"DRONE_BUILD_NUMBER",
|
||||
"DRONE_BUILD_PARENT",
|
||||
"DRONE_BUILD_EVENT",
|
||||
"DRONE_BUILD_ACTION",
|
||||
"DRONE_BUILD_STATUS",
|
||||
"DRONE_BUILD_CREATED",
|
||||
"DRONE_BUILD_STARTED",
|
||||
"DRONE_BUILD_FINISHED",
|
||||
"DRONE_DEPLOY_TO",
|
||||
"DRONE_BUILD_STATUS",
|
||||
"DRONE_FAILED_STAGES",
|
||||
"DRONE_PULL_REQUEST",
|
||||
"DRONE_TAG",
|
||||
"DRONE_SEMVER",
|
||||
"DRONE_SEMVER_MAJOR",
|
||||
"DRONE_SEMVER_MINOR",
|
||||
"DRONE_SEMVER_PATCH",
|
||||
"DRONE_SEMVER_PRERELEASE",
|
||||
"DRONE_SEMVER_BUILD",
|
||||
"DRONE_SEMVER_SHORT",
|
||||
"DRONE_SEMVER_ERROR",
|
||||
}
|
||||
13
content/configuration/environment/variables/_index.md
Normal file
13
content/configuration/environment/variables/_index.md
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Environment Reference
|
||||
author: bradrydzewski
|
||||
weight: 18
|
||||
toc: false
|
||||
layout: list_li
|
||||
hide_children: true
|
||||
description: |
|
||||
Index of all environment variables available to the pipeline.
|
||||
---
|
||||
|
||||
Index of environment variables available to your pipeline:
|
||||
11
content/configuration/environment/variables/ci.md
Normal file
11
content/configuration/environment/variables/ci.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: CI
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Identifies the current environment as a Continuous Integration environment.
|
||||
|
||||
```
|
||||
CI=true
|
||||
```
|
||||
11
content/configuration/environment/variables/drone-branch.md
Normal file
11
content/configuration/environment/variables/drone-branch.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BRANCH
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the target branch for the push or pull request. This value may be empty for tag events.
|
||||
|
||||
```
|
||||
DRONE_BRANCH=master
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_ACTION
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the action that triggered the pipeline execution. Use this value to differentiate between the pull request being opened vs synchronized.
|
||||
|
||||
```
|
||||
DRONE_BUILD_ACTION=sync
|
||||
DRONE_BUILD_ACTION=open
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_CREATED
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the unix timestamp for when the build object was created by the system.
|
||||
|
||||
```
|
||||
DRONE_BUILD_CREATED=915148800
|
||||
```
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_EVENT
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the event that triggered the pipeline execution.
|
||||
|
||||
```
|
||||
DRONE_BUILD_EVENT=push
|
||||
DRONE_BUILD_EVENT=pull_request
|
||||
DRONE_BUILD_EVENT=promote
|
||||
DRONE_BUILD_EVENT=rollback
|
||||
DRONE_BUILD_EVENT=tag
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_FINISHED
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the unix timestamp for when the build is finished. A running build cannot have a finish timestamp, therefore, the system always sets this value to the current timestamp.
|
||||
|
||||
```
|
||||
DRONE_BUILD_FINISHED=915148800
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_NUMBER
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the build number for the current running build.
|
||||
|
||||
```
|
||||
DRONE_BUILD_NUMBER=42
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_PARENT
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the parent build number for the current running build. The parent build number is populated from an exiting build that is being promoted.
|
||||
|
||||
```
|
||||
DRONE_BUILD_PARENT=42
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_STARTED
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
|
||||
Provides the unix timestamp for when the build was started by the system.
|
||||
|
||||
```
|
||||
DRONE_BUILD_STARTED=915148800
|
||||
```
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_BUILD_STATUS
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the status for the current running build. If build pipelines and build steps are passing, the build status defaults to success.
|
||||
|
||||
```
|
||||
DRONE_BUILD_STATUS=success
|
||||
DRONE_BUILD_STATUS=failure
|
||||
```
|
||||
|
||||
_Please note this is point in time snapshot. This value may not accurately reflect the overall build status when multiple pipelines are running in parallel_.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_AFTER
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the git commit sha after the patch is applied. This may be used in conjunction with the before commit sha to create a diff.
|
||||
|
||||
```
|
||||
DRONE_COMMIT_AFTER=bcdd4bf0245c82c060407b3b24b9b87301d15ac1
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_AUTHOR_AVATAR
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the commit author avatar for the current running build. This is the avatar from source control management system (e.g. GitHub).
|
||||
|
||||
```
|
||||
DRONE_COMMIT_AUTHOR_AVATAR=https://githubusercontent.com/u/...
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_AUTHOR_EMAIL
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the commit email address for the current running build. _Note this is a user-defined value and may be empty or inaccurate._
|
||||
|
||||
```
|
||||
DRONE_COMMIT_AUTHOR_EMAIL=octocat@github.com
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_AUTHOR_NAME
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the commit author name for the current running build. _Note this is a user-defined value and may be empty or inaccurate._
|
||||
|
||||
```
|
||||
DRONE_COMMIT_AUTHOR_NAME=The Octocat
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_AUTHOR
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the commit author username for the current running build. This is the username from source control management system (e.g. GitHub username).
|
||||
|
||||
```
|
||||
DRONE_COMMIT_AUTHOR=octocat
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_BEFORE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the git commit sha before the patch is applied. This may be used in conjunction with the after commit sha to create a diff.
|
||||
|
||||
```
|
||||
DRONE_COMMIT_BEFORE=bcdd4bf0245c82c060407b3b24b9b87301d15ac1
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_BRANCH
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the target branch for the push or pull request. This value may be empty for tag events.
|
||||
|
||||
```
|
||||
DRONE_COMMIT_BRANCH=master
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_LINK
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides a link the git commit or object in the source control management system.
|
||||
|
||||
```
|
||||
DRONE_COMMIT_LINK=https://github.com/octocat/hello-world/pull/42
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_MESSAGE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the commit message for the current running build.
|
||||
|
||||
```
|
||||
DRONE_COMMIT_MESSAGE=Updated README.md
|
||||
```
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_REF
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the git reference for the current running build.
|
||||
|
||||
```
|
||||
DRONE_COMMIT_REF=refs/heads/master
|
||||
```
|
||||
|
||||
Example tag reference:
|
||||
|
||||
```
|
||||
DRONE_COMMIT_REF=refs/tags/v1.0.0
|
||||
```
|
||||
|
||||
Example pull request reference (GitHub):
|
||||
```
|
||||
DRONE_COMMIT_REF=refs/pull/42/head
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT_SHA
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the git commit sha for the current running build.
|
||||
|
||||
```
|
||||
DRONE_COMMIT_SHA=bcdd4bf0245c82c060407b3b24b9b87301d15ac1
|
||||
```
|
||||
11
content/configuration/environment/variables/drone-commit.md
Normal file
11
content/configuration/environment/variables/drone-commit.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_COMMIT
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the git commit sha for the current running build.
|
||||
|
||||
```
|
||||
DRONE_COMMIT=bcdd4bf0245c82c060407b3b24b9b87301d15ac1
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_DEPLOY_TO
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the target deployment environment for the running build. This value is only available to promotion and rollback pipelines.
|
||||
|
||||
```
|
||||
DRONE_DEPLOY_TO=production
|
||||
```
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_FAILED_STAGES
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides a comma-separate list of failed pipeline stages for the current running build.
|
||||
|
||||
```
|
||||
DRONE_FAILED_STAGES=build,test
|
||||
```
|
||||
|
||||
_Please note this is point in time snapshot. This value may not accurately reflect the latest results when multiple pipelines are running in parallel_.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_FAILED_STEPS
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides a comma-separate list of failed pipeline steps.
|
||||
|
||||
```
|
||||
DRONE_FAILED_STEPS=backend,frontend
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_GIT_HTTP_URL
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the `git+http` url that should be used to clone the repository.
|
||||
|
||||
```
|
||||
DRONE_GIT_HTTP_URL=https://github.com/octocat/hello-world.git
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_GIT_SSH_URL
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the `git+ssh` url that should be used to clone the repository.
|
||||
|
||||
```
|
||||
DRONE_GIT_SSH_URL=git@github.com:octocat/hello-world.git
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_PULL_REQUEST
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the pull request number for the current running build. If the build is not a pull request the variable is empty.
|
||||
|
||||
```
|
||||
DRONE_PULL_REQUEST=42
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REMOTE_URL
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the `git+https` url that should be used to clone the repository. _This is a legacy value included for backward compatibility only._
|
||||
|
||||
```
|
||||
DRONE_REMOTE_URL=https://github.com/octocat/hello-world.git
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_BRANCH
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the default repository branch for the current running build.
|
||||
|
||||
```
|
||||
DRONE_REPO_BRANCH=master
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_LINK
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the repository link for the current running build.
|
||||
|
||||
```
|
||||
DRONE_REPO_LINK=https://github.com/octocat/hello-world
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_NAME
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the repository name for the current running build.
|
||||
|
||||
```
|
||||
DRONE_REPO_NAME=hello-world
|
||||
DRONE_REPO=octocat/hello-world
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_NAMESPACE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the repository namespace for the current running build. The namespace is an alias for the source control management account that owns the repository.
|
||||
|
||||
```
|
||||
DRONE_REPO_NAMESPACE=octocat
|
||||
DRONE_REPO=octocat/hello-world
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_OWNER
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the repository namespace for the current running build. The namespace is an alias for the source control management account that owns the repository.
|
||||
|
||||
```
|
||||
DRONE_REPO_OWNER=octocat
|
||||
DRONE_REPO=octocat/hello-world
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_PRIVATE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides a boolean flag that indicates whether or not the repository is private or public.
|
||||
|
||||
```
|
||||
DRONE_REPO_PRIVATE=false
|
||||
```
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_SCM
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the repository type for the current running build.
|
||||
|
||||
```
|
||||
DRONE_REPO_SCM=git
|
||||
```
|
||||
|
||||
List of all possible values:
|
||||
|
||||
```
|
||||
DRONE_REPO_SCM=git
|
||||
DRONE_REPO_SCM=hg
|
||||
DRONE_REPO_SCM=svn
|
||||
```
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO_VISIBILITY
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the repository visibility level for the current running build.
|
||||
|
||||
```
|
||||
DRONE_REPO_VISIBILITY=public
|
||||
```
|
||||
|
||||
List of all possible values:
|
||||
|
||||
```
|
||||
DRONE_REPO_VISIBILITY=public
|
||||
DRONE_REPO_VISIBILITY=private
|
||||
DRONE_REPO_VISIBILITY=internal
|
||||
```
|
||||
11
content/configuration/environment/variables/drone-repo.md
Normal file
11
content/configuration/environment/variables/drone-repo.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_REPO
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the full repository name for the current running build.
|
||||
|
||||
```
|
||||
DRONE_REPO=octocat/hello-world
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER_BUILD
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is a valid semver string, this variable provides the build from the semver string.
|
||||
|
||||
```
|
||||
DRONE_SEMVER_BUILD=001
|
||||
DRONE_SEMVER=1.2.3+001
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER_ERROR
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is _not_ a valid semver string, this variable provides the semver parsing error.
|
||||
|
||||
```
|
||||
DRONE_SEMVER_ERROR=
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER_MAJOR
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is a valid semver string, this variable provides the major version number from the semver string.
|
||||
|
||||
```
|
||||
DRONE_SEMVER_MAJOR=1
|
||||
DRONE_SEMVER=1.2.3
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER_MINOR
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is a valid semver string, this variable provides the minor version number from the semver string.
|
||||
|
||||
```
|
||||
DRONE_SEMVER_MINOR=2
|
||||
DRONE_SEMVER=1.2.3
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER_PATCH
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is a valid semver string, this variable provides the patch from the semver string.
|
||||
|
||||
```
|
||||
DRONE_SEMVER_PATCH=3
|
||||
DRONE_SEMVER=1.2.3
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER_PRERELEASE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is a valid semver string, this variable provides the prelease from the semver string.
|
||||
|
||||
```
|
||||
DRONE_SEMVER_PRERELEASE=alpha.1
|
||||
DRONE_SEMVER=1.2.3-alpha.1
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER_SHORT
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is a valid semver string, this variable provides the short version of the semver string where labels and metadata are truncated.
|
||||
|
||||
```
|
||||
DRONE_SEMVER_SHORT=1.2.3
|
||||
```
|
||||
21
content/configuration/environment/variables/drone-semver.md
Normal file
21
content/configuration/environment/variables/drone-semver.md
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SEMVER
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
If the git tag is a valid semver string, provides the tag as a semver string.
|
||||
|
||||
```
|
||||
DRONE_SEMVER=1.2.3-alpha.1
|
||||
```
|
||||
|
||||
The semver string is also available in the following formats:
|
||||
|
||||
```
|
||||
DRONE_SEMVER_SHORT=1.2.3
|
||||
DRONE_SEMVER_PATCH=3
|
||||
DRONE_SEMVER_MINOR=2
|
||||
DRONE_SEMVER_MAJOR=1
|
||||
DRONE_SEMVER_PRERELEASE=alpha.1
|
||||
```
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SOURCE_BRANCH
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the source branch for the pull request. This value may be empty for certain source control management providers.
|
||||
|
||||
```
|
||||
DRONE_SOURCE_BRANCH=feature/develop
|
||||
```
|
||||
|
||||
This environment variable can be used in conjunction with the target branch variable to get the pull request base and head branch.
|
||||
|
||||
```
|
||||
DRONE_SOURCE_BRANCH=feature/develop
|
||||
DRONE_TARGET_BRANCH=master
|
||||
```
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_ARCH
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the platform architecture for the current build stage.
|
||||
|
||||
```
|
||||
DRONE_STAGE_ARCH=amd64
|
||||
```
|
||||
|
||||
List of all possible values:
|
||||
|
||||
```
|
||||
DRONE_STAGE_ARCH=386
|
||||
DRONE_STAGE_ARCH=amd64
|
||||
DRONE_STAGE_ARCH=arm64
|
||||
DRONE_STAGE_ARCH=arm
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_DEPENDS_ON
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides a comma-separated list of dependencies for the current pipeline stage.
|
||||
|
||||
```
|
||||
DRONE_STAGE_DEPENDS_ON=backend,frontend
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_FINISHED
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the unix timestamp for when the pipeline is finished. A running pipeline cannot have a finish timestamp, therefore, the system always sets this value to the current timestamp.
|
||||
|
||||
```
|
||||
DRONE_STAGE_FINISHED=915148800
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_KIND
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the kind of resource being executed. This value is sourced from the `kind` attribute in the yaml configuration file.
|
||||
|
||||
```
|
||||
DRONE_STAGE_KIND=pipeline
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_MACHINE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the name of the host machine on which the pipeline is currently running.
|
||||
|
||||
```
|
||||
DRONE_STAGE_MACHINE=ec2-203-0-113-25.compute-1.amazonaws.com
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_NAME
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the stage name for the current running pipeline stage.
|
||||
|
||||
```
|
||||
DRONE_STAGE_NAME=build
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_NUMBER
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the stage number for the current running pipeline stage.
|
||||
|
||||
```
|
||||
DRONE_STAGE_NUMBER=1
|
||||
```
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_OS
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the target operating system for the current build stage.
|
||||
|
||||
```
|
||||
DRONE_STAGE_OS=linux
|
||||
```
|
||||
|
||||
List of all possible values:
|
||||
|
||||
```
|
||||
DRONE_STAGE_OS=darwin
|
||||
DRONE_STAGE_OS=dragonfly
|
||||
DRONE_STAGE_OS=freebsd
|
||||
DRONE_STAGE_OS=linux
|
||||
DRONE_STAGE_OS=netbsd
|
||||
DRONE_STAGE_OS=openbsd
|
||||
DRONE_STAGE_OS=solaris
|
||||
DRONE_STAGE_OS=windows
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_STARTED
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the unix timestamp for when the pipeline was started by the runner.
|
||||
|
||||
```
|
||||
DRONE_STAGE_STARTED=915148800
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_STATUS
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the status for the current running pipeline. If all pipeline steps are passing, the pipeline status defaults to success.
|
||||
|
||||
```
|
||||
DRONE_STAGE_STATUS=success
|
||||
DRONE_STAGE_STATUS=failure
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_TYPE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the type of resource being executed. This value is sourced from the `type` attribute in the yaml configuration file.
|
||||
|
||||
```
|
||||
DRONE_STAGE_TYPE=docker
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STAGE_VARIANT
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the target operating architecture variable for the current build stage. This variable is optional and is only available for arm architectures.
|
||||
|
||||
```
|
||||
DRONE_STAGE_VARIANT=v7
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STEP_NAME
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the step name for the current running pipeline step.
|
||||
|
||||
```
|
||||
DRONE_STEP_NAME=build
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_STEP_NUMBER
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the step number for the current running pipeline step.
|
||||
|
||||
```
|
||||
DRONE_STEP_NUMBER=1
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SYSTEM_HOST
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the hostname used by the Drone server. This can be combined with the protocol to construct to the server url.
|
||||
|
||||
```
|
||||
DRONE_SYSTEM_HOST=cloud.drone.io
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SYSTEM_HOSTNAME
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the hostname used by the Drone server. This can be combined with the protocol to construct to the server url.
|
||||
|
||||
```
|
||||
DRONE_SYSTEM_HOSTNAME=cloud.drone.io
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SYSTEM_PROTO
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the protocol used by the Drone server. This can be combined with the hostname to construct to the server url.
|
||||
|
||||
```
|
||||
DRONE_SYSTEM_PROTO=https
|
||||
```
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_SYSTEM_VERSION
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the version of the Drone server.
|
||||
|
||||
```
|
||||
DRONE_SYSTEM_VERSION=1.2.3
|
||||
```
|
||||
11
content/configuration/environment/variables/drone-tag.md
Normal file
11
content/configuration/environment/variables/drone-tag.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_TAG
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the tag for the current running build. This value is only populated for tag events and promotion events that are derived from tags.
|
||||
|
||||
```
|
||||
DRONE_TAG=v1.0.0
|
||||
```
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE_TARGET_BRANCH
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Provides the target branch for the push or pull request. This value may be empty for tag events.
|
||||
|
||||
```
|
||||
DRONE_TARGET_BRANCH=master
|
||||
```
|
||||
|
||||
This environment variable can be used in conjunction with the source branch variable to get the pull request base and head branch.
|
||||
|
||||
```
|
||||
DRONE_SOURCE_BRANCH=feature/develop
|
||||
DRONE_TARGET_BRANCH=master
|
||||
```
|
||||
11
content/configuration/environment/variables/drone.md
Normal file
11
content/configuration/environment/variables/drone.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: DRONE
|
||||
author: bradrydzewski
|
||||
---
|
||||
|
||||
Identifies the current environment as the Drone Continuous Integration environment.
|
||||
|
||||
```
|
||||
DRONE=true
|
||||
```
|
||||
100
content/configuration/images.md
Normal file
100
content/configuration/images.md
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Images
|
||||
author: bradrydzewski
|
||||
weight: 6
|
||||
toc: true
|
||||
description: |
|
||||
Configure pipeline images.
|
||||
---
|
||||
|
||||
Pipeline steps are defined as a series of Docker containers. Each step must therefore define the Docker image used to create the container.
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=7" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang:1.12
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
|
||||
Drone supports any valid Docker image from any Docker registry:
|
||||
|
||||
```
|
||||
image: golang
|
||||
image: golang:1.7
|
||||
image: library/golang:1.7
|
||||
image: index.docker.io/library/golang
|
||||
image: index.docker.io/library/golang:1.7
|
||||
image: docker.company.com/golang
|
||||
```
|
||||
|
||||
# Pulling Images
|
||||
|
||||
If the image does not exist in the local cache, Drone instructs Docker to pull the image automatically. You will never need to manually download or install Docker images.
|
||||
|
||||
If the image is tagged with latest, Drone will always attempt to pull the latest version of the image. Configure the runner to only pull the image if not found in the local cache:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=3" >}}
|
||||
steps:
|
||||
- name: build
|
||||
pull: if-not-exists
|
||||
image: golang
|
||||
{{< / highlight >}}
|
||||
|
||||
To always pull the latest version of the image:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=3" >}}
|
||||
steps:
|
||||
- name: build
|
||||
pull: always
|
||||
image: golang:1.12
|
||||
{{< / highlight >}}
|
||||
|
||||
To never pull the image and always use the image in the local cache:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=3" >}}
|
||||
steps:
|
||||
- name: build
|
||||
pull: never
|
||||
image: golang:1.12
|
||||
{{< / highlight >}}
|
||||
|
||||
# Pulling Private Images
|
||||
|
||||
If the image is private you need to provide Drone with docker credentials, sourced from a secret. You can manage secrets in your repository settings screen in the web interface.
|
||||
|
||||
First create a secret that includes your Docker credentials in the format of a Docker config.json file. This file may provide credentials for multiple registries.
|
||||
|
||||
```
|
||||
{
|
||||
"auths": {
|
||||
"docker.io": {
|
||||
"auth": "4452D71687B6BC2C9389C3..."
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Next, define which secrets should be used to pull private images using the image_pull_secrets attribute:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=8-9" >}}
|
||||
steps:
|
||||
- name: build
|
||||
image: registry.internal.company.com/golang:1.12
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
|
||||
image_pull_secrets:
|
||||
- dockerconfig
|
||||
{{< / highlight >}}
|
||||
|
||||
{{< alert "info" >}}
|
||||
If you want to pull private images from Amazon Elastic Container Registry (ECR) you will need to install a registry credential plugin.
|
||||
{{< / alert >}}
|
||||
50
content/configuration/overview.md
Normal file
50
content/configuration/overview.md
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Overview
|
||||
author: bradrydzewski
|
||||
weight: -2
|
||||
toc: false
|
||||
description: |
|
||||
Overview of Docker pipelines.
|
||||
---
|
||||
|
||||
A `docker` pipeline is a pipeline that executes shell commands inside Docker containers. Docker containers provide isolation allowing safe execution of concurrent pipelines on the same machine.
|
||||
|
||||
A major benefit of container pipelines is the ability to bring your own build environment, in the form of a Docker image. Drone automatically downloads docker images at runtime.
|
||||
|
||||
Example pipeline configuration:
|
||||
|
||||
{{< highlight text "linenos=table" >}}
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: greeting
|
||||
image: golang:1.12
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
|
||||
...
|
||||
{{< / highlight >}}
|
||||
|
||||
The kind and type attributes define a Docker pipeline.
|
||||
|
||||
{{< highlight text "linenos=table" >}}
|
||||
---
|
||||
kind: pipline
|
||||
type: docker
|
||||
{{< / highlight >}}
|
||||
|
||||
The `steps` section defines a series of shell commands. These commands are executed inside the Docker container as the `Entrypoint`. If any command returns a non-zero exit code, the pipeline fails and exits.
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=6" >}}
|
||||
steps:
|
||||
- name: greeting
|
||||
image: golang:1.12
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
49
content/configuration/parallelism.md
Normal file
49
content/configuration/parallelism.md
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Parallelism
|
||||
author: bradrydzewski
|
||||
weight: 6
|
||||
toc: false
|
||||
description: |
|
||||
Configure pipeline steps to execute in parallel.
|
||||
---
|
||||
|
||||
Pipeline steps are executed sequentially by default. You can optionally describe your build steps as a [directed acyclic graph](https://en.wikipedia.org/wiki/Directed_acyclic_graph). In the below example we fan-out to execute the first two steps in parallel, and then once complete, we fan-in to execute the final step:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=23-25" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: backend
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
|
||||
- name: frontend
|
||||
image: node
|
||||
commands:
|
||||
- npm install
|
||||
- npm test
|
||||
|
||||
- name: notify
|
||||
image: plugins/slack
|
||||
settings:
|
||||
webhook:
|
||||
from_secret: webhook
|
||||
depends_on:
|
||||
- frontend
|
||||
- backend
|
||||
{{< / highlight >}}
|
||||
|
||||
The above example is quite simple, however, you can use this syntax to create very complex execution flows.
|
||||
|
||||
{{< alert "warn" >}}
|
||||
Note that when you define the dependency graph you must configure dependencies for all pipeline steps.
|
||||
{{< / alert >}}
|
||||
|
||||
{{< alert "info" >}}
|
||||
Note that you can use conditional steps in your dependency graph. The scheduler automatically corrects the dependency graph for skipped steps.
|
||||
{{< / alert >}}
|
||||
52
content/configuration/platform.md
Normal file
52
content/configuration/platform.md
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Platform
|
||||
author: bradrydzewski
|
||||
weight: 2
|
||||
toc: false
|
||||
description: |
|
||||
Configure the target operating system and architecture.
|
||||
---
|
||||
|
||||
Use the `platform` section to configure the target operating system and architecture and routes the pipeline to the appropriate runner.
|
||||
|
||||
Example linux arm64 pipeline:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=5-7" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
{{< / highlight >}}
|
||||
|
||||
If you are running Docker pipelines on windows you must specify the operating system version number.
|
||||
|
||||
Example windows 1809 pipeline:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=4" >}}
|
||||
platform:
|
||||
os: windows
|
||||
arch: amd64
|
||||
version: 1809
|
||||
{{< / highlight >}}
|
||||
|
||||
# Supported Platforms
|
||||
|
||||
os | arch | version
|
||||
------------|---------|---
|
||||
`linux` | `amd64` |
|
||||
`linux` | `arm` |
|
||||
`linux` | `arm64` |
|
||||
`windows` | `amd64` | `1809`
|
||||
`windows` | `amd64` | `1903`
|
||||
`windows` | `amd64` | `1909 (coming soon)`
|
||||
89
content/configuration/plugins.md
Normal file
89
content/configuration/plugins.md
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Plugins
|
||||
author: bradrydzewski
|
||||
weight: 5
|
||||
toc: true
|
||||
description: |
|
||||
Configure re-usable pipeline steps using plugins.
|
||||
---
|
||||
|
||||
Plugins are docker containers that encapsulate commands, and can be shared and re-used in your pipeline. Use plugins to build and publish artifacts, send notifications, and more.
|
||||
|
||||
Example Slack plugin:
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=12-15" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: node
|
||||
commands:
|
||||
- npm install
|
||||
- npm test
|
||||
|
||||
- name: notify
|
||||
image: plugins/slack
|
||||
settings:
|
||||
webhook: https://hooks.slack.com/services/...
|
||||
{{< / highlight >}}
|
||||
|
||||
As you can see plugins are just Docker containers. Anyone can encapsulate logic, bundle as a Docker image, and publish to a Docker registry to share with their organization, or with the broader community.
|
||||
|
||||
{{< alert "info" >}}
|
||||
The Drone community owns the plugins/ namespace in Dockerhub. Any plugin prefixed with plugins/ is actively maintained and vetted by community members.
|
||||
{{< / alert >}}
|
||||
|
||||
{{< alert "info" >}}
|
||||
The Drone community plugins in the plugins/ namespace are maintained by the community. Community plugins are not subject to our Enterprise support policy or service level agreements.
|
||||
{{< / alert >}}
|
||||
|
||||
# Secrets
|
||||
|
||||
Drone provides the ability to source any configuration parameter from a named secret using the `from_secret` syntax.
|
||||
|
||||
Example Slack plugin using secrets:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=11-12" >}}
|
||||
steps:
|
||||
- name: build
|
||||
image: node
|
||||
commands:
|
||||
- npm install
|
||||
- npm test
|
||||
|
||||
- name: notify
|
||||
image: plugins/slack
|
||||
settings:
|
||||
webhook:
|
||||
from_secret: webhook
|
||||
{{< / highlight >}}
|
||||
|
||||
Example NPM plugin using secrets:
|
||||
|
||||
{{< highlight text "linenos=table,linenostart=5,hl_lines=11-14" >}}
|
||||
steps:
|
||||
- name: build
|
||||
image: node
|
||||
commands:
|
||||
- npm install
|
||||
- npm test
|
||||
|
||||
- name: publish
|
||||
image: plugins/npm
|
||||
settings:
|
||||
username:
|
||||
from_secret: username
|
||||
password:
|
||||
from_secret: password
|
||||
{{< / highlight >}}
|
||||
|
||||
# Registry
|
||||
|
||||
The community maintains a public registry of Open Source plugins. You can browse the plugin registry at [plugins.drone.io](http://plugins.drone.io).
|
||||
|
||||
{{< link-to "http://plugins.drone.io" >}}
|
||||
Plugin Registry
|
||||
{{< / link-to >}}
|
||||
32
content/configuration/routing.md
Normal file
32
content/configuration/routing.md
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
date: 2000-01-01T00:00:00+00:00
|
||||
title: Routing
|
||||
author: bradrydzewski
|
||||
weight: 9
|
||||
toc: false
|
||||
description: |
|
||||
Route pipelines to specific servers.
|
||||
---
|
||||
|
||||
The `nodes` section can be used to route pipelines to specific runners, or groups of runners, that have matching labels. This can be useful when you need to route pipelines to runners with special configurations or hardware.
|
||||
|
||||
{{< alert "warn" >}}
|
||||
A pipeline is not routed to a runner unless it matches all runner labels. If the pipeline only defines and matches a subset of runner labels it will not be routed to the runner.
|
||||
{{< / alert >}}
|
||||
|
||||
{{< highlight text "linenos=table,hl_lines=11-14" >}}
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
|
||||
node:
|
||||
keyA: valueA
|
||||
keyB: valueB
|
||||
{{< / highlight >}}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue