Skip to content

Commit 43bbf6e

Browse files
committed
initial commit [ci skip]
1 parent 56c135e commit 43bbf6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+6579
-1
lines changed

.drone.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
kind: pipeline
2+
name: default
3+
4+
platform:
5+
os: linux
6+
arch: amd64
7+
8+
steps:
9+
- name: test
10+
image: golang:1.12
11+
commands:
12+
- go test -cover ./...
13+
volumes:
14+
- name: go
15+
path: /go
16+
17+
- name: build
18+
image: golang:1.12
19+
commands:
20+
- sh scripts/build.sh
21+
volumes:
22+
- name: go
23+
path: /go
24+
when:
25+
event:
26+
- push
27+
- tag
28+
29+
- name: publish
30+
image: plugins/docker
31+
pull: if-not-exists
32+
settings:
33+
repo: drone/drone-runner-docker
34+
auto_tag: true
35+
auto_tag_suffix: linux-amd64
36+
dockerfile: docker/Dockerfile.linux.amd64
37+
username:
38+
from_secret: docker_username
39+
password:
40+
from_secret: docker_password
41+
when:
42+
ref:
43+
- refs/heads/master
44+
- refs/tags/*
45+
46+
volumes:
47+
- name: go
48+
temp: {}

.github/code_of_conduct.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
education, socio-economic status, nationality, personal appearance, race,
10+
religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org

.github/issue_template.md

Whitespace-only changes.

.github/pull_request_template.md

Whitespace-only changes.

.github/security.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Security Policies and Procedures
2+
3+
This document outlines security procedures and general policies for this project.
4+
5+
* [Reporting a Bug](#reporting-a-bug)
6+
* [Disclosure Policy](#disclosure-policy)
7+
* [Comments on this Policy](#comments-on-this-policy)
8+
9+
## Reporting a Bug
10+
11+
Report security bugs by emailing the lead maintainer at [email protected].
12+
13+
The lead maintainer will acknowledge your email within 48 hours, and will send a
14+
more detailed response within 48 hours indicating the next steps in handling
15+
your report. After the initial reply to your report, the security team will
16+
endeavor to keep you informed of the progress towards a fix and full
17+
announcement, and may ask for additional information or guidance.
18+
19+
Report security bugs in third-party packages to the person or team maintaining
20+
the module.
21+
22+
## Disclosure Policy
23+
24+
When the security team receives a security bug report, they will assign it to a
25+
primary handler. This person will coordinate the fix and release process,
26+
involving the following steps:
27+
28+
* Confirm the problem and determine the affected versions.
29+
* Audit code to find any potential similar problems.
30+
* Prepare fixes for all releases still under maintenance. These fixes will be
31+
released as fast as possible.
32+
33+
## Comments on this Policy
34+
35+
If you have suggestions on how this process could be improved please submit a
36+
pull request.

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
drone-runner-docker
2+
drone-runner-docker.exe
3+
release/*
4+
.env
5+
NOTES*
6+
engine/compiler2

BUILDING.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1. Install go 1.13 or higher
2+
2. Test
3+
4+
go test ./...
5+
6+
3. Build binaries
7+
8+
sh scripts/build_all.sh
9+
10+
4. Build images
11+
12+
docker build -t drone/drone-runner-docker:latest-linux-amd64 -f docker/Dockerfile.linux.amd64 .
13+
docker build -t drone/drone-runner-docker:latest-linux-arm64 -f docker/Dockerfile.linux.arm64 .
14+
docker build -t drone/drone-runner-docker:latest-linux-arm -f docker/Dockerfile.linux.arm .

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
3+
4+
## [Unreleased]
5+
### Added

LICENSE.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Polyform-Small-Business-1.0.0](https://polyformproject.org/licenses/small-business/1.0.0) OR
2+
[Polyform-Free-Trial-1.0.0](https://polyformproject.org/licenses/free-trial/1.0.0)

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# drone-runner-docker
2-
Drone pipeline runner that executes builds inside Docker containers
2+
3+
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.
4+
5+
Documentation:<br/>
6+
https://docker-runner.docs.drone.io
7+
8+
Technical Support:<br/>
9+
https://discourse.drone.io
10+
11+
Issue Tracker and Roadmap:<br/>
12+
https://trello.com/b/ttae5E5o/drone

command/command.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2019 Drone.IO Inc. All rights reserved.
2+
// Use of this source code is governed by the Polyform License
3+
// that can be found in the LICENSE file.
4+
5+
package command
6+
7+
import (
8+
"context"
9+
"os"
10+
11+
"github.com/drone-runners/drone-runner-docker/command/daemon"
12+
13+
"gopkg.in/alecthomas/kingpin.v2"
14+
)
15+
16+
// program version
17+
var version = "0.0.0"
18+
19+
// empty context
20+
var nocontext = context.Background()
21+
22+
// Command parses the command line arguments and then executes a
23+
// subcommand program.
24+
func Command() {
25+
app := kingpin.New("drone", "drone exec runner")
26+
registerCompile(app)
27+
registerExec(app)
28+
daemon.Register(app)
29+
30+
kingpin.Version(version)
31+
kingpin.MustParse(app.Parse(os.Args[1:]))
32+
}

command/compile.go

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2019 Drone.IO Inc. All rights reserved.
2+
// Use of this source code is governed by the Polyform License
3+
// that can be found in the LICENSE file.
4+
5+
package command
6+
7+
import (
8+
"encoding/json"
9+
"fmt"
10+
"io/ioutil"
11+
"os"
12+
"strings"
13+
14+
"github.com/drone-runners/drone-runner-docker/command/internal"
15+
"github.com/drone-runners/drone-runner-docker/engine/compiler"
16+
"github.com/drone-runners/drone-runner-docker/engine/resource"
17+
"github.com/drone/envsubst"
18+
"github.com/drone/runner-go/environ"
19+
"github.com/drone/runner-go/manifest"
20+
"github.com/drone/runner-go/secret"
21+
22+
"gopkg.in/alecthomas/kingpin.v2"
23+
)
24+
25+
type compileCommand struct {
26+
*internal.Flags
27+
28+
Source *os.File
29+
Environ map[string]string
30+
Secrets map[string]string
31+
}
32+
33+
func (c *compileCommand) run(*kingpin.ParseContext) error {
34+
rawsource, err := ioutil.ReadAll(c.Source)
35+
if err != nil {
36+
return err
37+
}
38+
39+
envs := environ.Combine(
40+
c.Environ,
41+
environ.System(c.System),
42+
environ.Repo(c.Repo),
43+
environ.Build(c.Build),
44+
environ.Stage(c.Stage),
45+
environ.Link(c.Repo, c.Build, c.System),
46+
c.Build.Params,
47+
)
48+
49+
// string substitution function ensures that string
50+
// replacement variables are escaped and quoted if they
51+
// contain newlines.
52+
subf := func(k string) string {
53+
v := envs[k]
54+
if strings.Contains(v, "\n") {
55+
v = fmt.Sprintf("%q", v)
56+
}
57+
return v
58+
}
59+
60+
// evaluates string replacement expressions and returns an
61+
// update configuration.
62+
config, err := envsubst.Eval(string(rawsource), subf)
63+
if err != nil {
64+
return err
65+
}
66+
67+
// parse and lint the configuration
68+
manifest, err := manifest.ParseString(config)
69+
if err != nil {
70+
return err
71+
}
72+
73+
// a configuration can contain multiple pipelines.
74+
// get a specific pipeline resource for execution.
75+
resource, err := resource.Lookup(c.Stage.Name, manifest)
76+
if err != nil {
77+
return err
78+
}
79+
80+
// compile the pipeline to an intermediate representation.
81+
comp := &compiler.Compiler{
82+
Pipeline: resource,
83+
Manifest: manifest,
84+
Build: c.Build,
85+
Netrc: c.Netrc,
86+
Repo: c.Repo,
87+
Stage: c.Stage,
88+
System: c.System,
89+
Environ: c.Environ,
90+
Secret: secret.StaticVars(c.Secrets),
91+
}
92+
spec := comp.Compile(nocontext)
93+
94+
// encode the pipeline in json format and print to the
95+
// console for inspection.
96+
enc := json.NewEncoder(os.Stdout)
97+
enc.SetIndent("", " ")
98+
enc.Encode(spec)
99+
return nil
100+
}
101+
102+
func registerCompile(app *kingpin.Application) {
103+
c := new(compileCommand)
104+
c.Environ = map[string]string{}
105+
c.Secrets = map[string]string{}
106+
107+
cmd := app.Command("compile", "compile the yaml file").
108+
Action(c.run)
109+
110+
cmd.Flag("source", "source file location").
111+
Default(".drone.yml").
112+
FileVar(&c.Source)
113+
114+
cmd.Flag("secrets", "secret parameters").
115+
StringMapVar(&c.Secrets)
116+
117+
cmd.Flag("environ", "environment variables").
118+
StringMapVar(&c.Environ)
119+
120+
// shared pipeline flags
121+
c.Flags = internal.ParseFlags(cmd)
122+
}

0 commit comments

Comments
 (0)