Git Product home page Git Product logo

buildkite / agent Goto Github PK

View Code? Open in Web Editor NEW
789.0 45.0 288.0 35.33 MB

The Buildkite Agent is an open-source toolkit written in Go for securely running build jobs on any device or network

Home Page: https://buildkite.com/

License: MIT License

Go 92.42% Shell 5.56% Ruby 0.28% Batchfile 0.01% PowerShell 1.08% Dockerfile 0.66%
go docker continuous-integration continuous-deployment continuous-delivery buildkite llamas cicd

agent's Introduction

Buildkite Agent

Build status Go Reference

The buildkite-agent is a small, reliable, and cross-platform build runner that makes it easy to run automated builds on your own infrastructure. It’s main responsibilities are polling buildkite.com for work, running build jobs, reporting back the status code and output log of the job, and uploading the job's artifacts.

Full documentation is available at buildkite.com/docs/agent.

$ buildkite-agent --help
Usage:

  buildkite-agent <command> [options...]

Available commands are:

  acknowledgements  Prints the licenses and notices of open source software incorporated into this software.
  start             Starts a Buildkite agent
  annotate          Annotate the build page within the Buildkite UI with text from within a Buildkite job
  annotation        Make changes to an annotation on the currently running build
  artifact          Upload/download artifacts from Buildkite jobs
  env               Process environment subcommands
  lock              Process lock subcommands
  meta-data         Get/set data from Buildkite jobs
  oidc              Interact with Buildkite OpenID Connect (OIDC)
  pipeline          Make changes to the pipeline of the currently running build
  step              Get or update an attribute of a build step
  bootstrap         Run a Buildkite job locally
  help              Shows a list of commands or help for one command

Use "buildkite-agent <command> --help" for more information about a command.

Dependencies

The agent is fairly portable and should run out of the box on most supported platforms without extras. On Linux hosts it requires dbus.

Installing

The agents page on Buildkite has personalised instructions, or you can refer to the Buildkite docs. Both cover installing the agent with Ubuntu (via apt), Debian (via apt), macOS (via homebrew), Windows and Linux.

Docker

We also support and publish Docker Images for the following operating systems. Docker images are tagged using the agent SemVer components followed by the operating system.

For example, agent version 3.45.6 is published as:

  • 3-ubuntu-20.04, tracks minor and bugfix updates in version 3 installed in Ubuntu 20.04
  • 3.45-ubuntu-20.04, tracks bugfix updates in version 3.45 installed in Ubuntu 20.04
  • 3.45.6-ubuntu-20.04, tracks the exact version installed in Ubuntu 20.04

Supported operating systems

  • Alpine 3.18
  • Ubuntu 18.04 LTS (x86_64), supported to end of standard support for 18.04
  • Ubuntu 20.04 LTS (x86_64), supported to end of standard support for 20.04
  • Ubuntu 22.04 LTS (x86_64), supported to end of standard support for 22.04

Starting

To start an agent all you need is your agent token, which you can find on your Agents page within Buildkite, and a build path. For example:

buildkite-agent start --token=<your token> --build-path=/tmp/buildkite-builds

Telemetry

By default, the agent sends some information back to the Buildkite mothership on what features are in use on that agent. Nothing sensitive or identifying is sent back to Buildkite, but if you want, you can disable this feature reporting by adding the --no-feature-reporting flag to your buildkite-agent start call. Features that we track can be found inside AgentStartConfig.Features.

Development

These instructions assume you are running a recent macOS, but could easily be adapted to Linux and Windows.

# Make sure you have Go installed.
brew install go

# Download the code somewhere - no GOPATH required.
git clone https://github.com/buildkite/agent.git
cd agent

# Create a temporary builds directory.
mkdir /tmp/buildkite-builds

# Build an agent binary and start the agent.
go build -o /usr/local/bin/buildkite-agent .
buildkite-agent start --debug --build-path=/tmp/buildkite-builds --token "abc"

# Or, run the agent directly and skip the build step.
go run *.go start --debug --build-path=/tmp/buildkite-builds --token "abc"

Go Version and Dependency Management

The latest agent version is typically compiled with the highest-numbered stable release of Go. Previous Go versions may work, but are not guaranteed to. We are using newer language features such as generics, so compiling on Go < 1.18 will fail.

We're using Go Modules to manage our Go dependencies. Dependencies are not vendored into the repository unless necessary.

The Go module published by this repo (i.e. the one you could use by adding import "github.com/buildkite/agent/v3" to your code) is not considered to be versioned using semantic versioning. Breaking changes may be introduced in minor releases. Use the agent as a runtime depedency of your Go app at your own risk.

Platform Support

We provide support for security and bug fixes on the current major release only.

Our architecture and operating system support is primarily limited by what Go itself supports.

Architecture Support

We offer support for the following machine architectures (inspired by the Rust language platform support guidance).

Tier 1, guaranteed to work

  • linux x86_64
  • linux arm64
  • windows x86_64

Tier 2, guaranteed to build

  • linux x86
  • windows x86
  • darwin x86_64
  • darwin arm64

Tier 3, community supported

We release binaries for various other platforms, and it should be possible to build the agent anywhere supported by Go, but official support is not provided for these Tier 3 platforms.

Operating System Support

We currently provide support for running the Buildkite Agent on the following operating systems. Future minor releases may drop support for end-of-life operating systems (typically as they become unsupported by the latest stable Go release).

The agent binary is fairly portable and should run out of the box on most UNIX like systems, as well as Windows.

  • Ubuntu 18.04 and newer
  • Debian 8 and newer
  • Red Hat RHEL 7 and newer
  • CentOS
    • CentOS 7
    • CentOS 8
  • Amazon Linux 2
  • macOS 1
    • 10.15 (Catalina)
    • 11 (Big Sur)
    • 12 (Monterey)
    • 13 (Ventura)
    • 14 (Sonoma)
  • Windows Server
    • 2016
    • 2019
    • 2022

Contributing

See ./CONTRIBUTING.md

Contributors

Many thanks to our fine contributors! You're all amazing, and we greatly appreciate your input ❤️

Copyright

Copyright (c) 2014-2023 Buildkite Pty Ltd. See LICENSE for details.

Footnotes

  1. See https://github.com/golang/go/issues/23011 for macOS / Go support and Supported macOS Versions for the last supported version of the Buildkite Agent for versions of macOS prior to those listed above.

agent's People

Contributors

amu-g avatar benmoss avatar chloeruka avatar dabarrell avatar dbaggerman avatar dependabot[bot] avatar drjosh9000 avatar eleanorakh avatar garypwhite avatar goodspark avatar grosskur avatar jayco avatar keithduncan avatar keithpitt avatar kevingreen avatar kouky avatar lox avatar matthewborden avatar moskyb avatar patrobinson avatar pda avatar plaindocs avatar sj26 avatar tessereth avatar ticky avatar tommeier avatar toolmantim avatar toothbrush avatar triarius avatar yob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agent's Issues

can't find 'scripts path' in project settings

At https://github.com/buildbox/buildbox-agent it says "The biggest change you'll notice is that you no longer define your build scripts on Buildbox. You instead should write these scripts and save them to your projects source control." and then "Next, go to your Project Settings on Buildbox and update the "Script Path" field with the path to your new build script (here we used scripts/buildbox.sh)."

I can't find a "scripts path" anywhere in my project settings... am I missing something?

screen shot 2014-08-05 at 4 17 53 pm

Agent ignoring multiple values for same meta data keys

Running an agent with something like:

buildbox agent start --token [token] --meta-data ruby=2.1.2 --meta-data ruby=2.0.0 --meta-data mysql=5.5

Yields only the following metadata in the interface:

ruby=2.0.0
mysql=5.5

And won't run builds configure for:

ruby=2.1.2

Multiple instances of buildbox

Hi,

I encountered a situation where I inadvertently started up two copies of the buildbox-agent on the same system, using the same access token. Both appeared to be able to start builds, and there was of course a high potential to conflict if they built the same project.

It would be good if a second agent using an access token that's currently in use by another agent would get rejected.

It would also be good if the log file output would note the PID so this situation can be spotted easily while tailing logs.

Agent crashes when running under launchd

I have an agent running on OS X Mavericks. It was originally running the Ruby agent, using a launch daemon .plist that I think I might have written. Here's the contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>io.buildbox.buildbox-ruby</string>

  <key>UserName</key>
  <string>_buildbox</string>

  <key>ProgramArguments</key>
  <array>
    <string>/usr/bin/buildbox</string>
    <string>agent:start</string>
  </array>

  <key>KeepAlive</key>
  <true/>

  <key>RunAtLoad</key>
  <true/>

  <key>StandardOutPath</key>
  <string>/var/log/buildbox.log</string>

  <key>StandardErrorPath</key>
  <string>/var/log/buildbox.log</string>

  <key>EnvironmentVariables</key>
  <dict>
    <key>PATH</key>
    <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
  </dict>
</dict>
</plist>

This worked great. Now I'm upgrading to this Golang agent, so I installed it as the _buildbox user. I modified the launch daemon:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>io.buildbox.buildbox-golang</string>

  <key>UserName</key>
  <string>_buildbox</string>

  <key>ProgramArguments</key>
  <array>
    <string>/Users/_buildbox/.buildbox/buildbox-agent</string>
    <string>start</string>
  </array>

  <key>KeepAlive</key>
  <true/>

  <key>RunAtLoad</key>
  <true/>

  <key>StandardOutPath</key>
  <string>/var/log/buildbox.log</string>

  <key>StandardErrorPath</key>
  <string>/var/log/buildbox.log</string>

  <key>EnvironmentVariables</key>
  <dict>
    <key>PATH</key>
    <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>

    <key>BUILDBOX_AGENT_ACCESS_TOKEN</key>
    <string>secret</string>
  </dict>
</dict>
</plist>

The agent starts up and waits for work. When I trigger a build, the interface on the website indicates that the agent started running the job (the job turns yellow). But there's never any build output, or activity on the machine. The log file contains:

2014/05/08 12:54:17 Started buildbox-agent `Beaver` (version 0.1)
2014/05/08 12:54:24 Starting job f1febf1f-5845-4e52-8ef9-5466f1982aad
2014/05/08 12:54:25 Running script `bootstrap.sh` from inside /Users/_buildbox/.buildbox
2014/05/08 12:54:27 Started buildbox-agent `Beaver` (version 0.1)

launchd says the agent died, so it respawns it:

May  8 12:54:25 Beaver com.apple.launchd[1] (io.buildbox.buildbox-golang[1294]): Exited with code: 2
May  8 12:54:25 Beaver com.apple.launchd[1] (io.buildbox.buildbox-golang): Throttling respawn: Will start in 1 seconds

When I run the agent as the _buildbox user in the foreground, it works fine.

Potential for lifeless containers in failure scenarios

https://github.com/buildbox/agent/blob/master/templates/bootstrap.sh#L144

These sorts of failure scenarios where exit or buildbox-exit-if-failed is called can result in rogue containers staying around and not being cleaned up. I.e fig kill and fig rm are not called since it exited.

Also if a build from the UI is cancelled then depending on where in the build step it is performed, it can also leave around containers.

Chris suggested a trap finish EXIT with a finish function declared as a possible solution to this particular problem.

Help text incorrect

Really not a big one, but:

$ buildbox-agent artifact upload help
buildbox: missing agent access token
See 'buildbox artifact download --help'

upload/download mixed up.

Make some .debs

All of our systems are managed via chef. Installing packages is much easier than piping curl to sh, and much easier to make idempotent.

io.Copy error in agent log

Seeing this in the log file:

2014-09-04 07:56:43 [INFO ] Starting job 4b797e6e-dd55-4960-a905-770150b3d5d7
2014-09-04 07:56:44 [INFO ] Starting to run script: /opt/buildbox/bootstrap.sh
2014-09-04 07:56:44 [INFO ] Process is running with PID: 23709
2014-09-04 07:57:04 [ERROR] io.Copy failed with error: *os.PathError: read /dev/ptmx: input/output error
2014-09-04 07:57:04 [INFO ] Finished job 4b797e6e-dd55-4960-a905-770150b3d5d7

bootstrap.sh and RSA key fingerprints

It seems like the default bootstrap.sh is not behaving well on CentOS 7. I don't have time to debug it, but it gets stuck on the "RSA key fingerprint" step. The "yes yes" piping does not help. The solution is to do this:

ssh -o StrictHostKeyChecking=no github.com ls

Which essentially tries to login without strict key checking, which will populate known_hosts file. Just pipe the output of IN/ERR to /dev/null, because the command will error out.

Pull request support for remote repos

Hi all,

Should the agent support pull requests for remote repositories? Personally, I think it should.

I've noticed that the pull request phonegap/ios-deploy/pull/68 is failing because the commit cannot be found. From the looks of it, the agent is trying to checkout the commit from the origin repository, rather than adding the remote's repository.

I haven't dug into the code, but I'm open to adding support for remotes. However, I want to make sure this is a legit bug and desired feature of the agent :)

agent does not work after suspend+resume cycle

The OSX buildbox-agent/1.0-beta.6 (darwin; 386) stops working after a laptop suspend+resume cycle.
It doesn't exit, it just sits there quietly and wont show up in the UI agent list.

Since always-on OSX hardware is a bit scarce this is a big show stopper for me.

observing cert verification failures

We are running the latest buildbox go-agent.
Currently observing the following messages on the agent output:

Problem with updating job ded6a18c-93f4-44aa-812a-5b58ba05c0bc%!(EXTRA *url.Error=Put https://agent.buildbox.io/v1/6145c05b9566560d1d54187414819cd2eac222500ab27a3776/jobs/ded6a18c-93f4-44aa-812a-5b589f05c0bc: x509: certificate signed by unknown authority (possibly because of "x509: cannot verify signature: algorithm unimplemented" while trying to verify candidate authority certificate "COMODO RSA Certification Authority"))

This seems to put all builds under the "wait" status.

Docker & Fig implementations not as robust as could be

Your docker & fig related clean up is missing some things. You should use --rm here or provide an option to do so. If you do not use --rm here containers will build up on the host machine and may cause problems if people ever try docker rmi. You may also want to consider adding -t. I haven't seen any harm come from this and it will make people's test out put more similar their development environment. You should consider using -v here. -v will also remove docker volumes. It's unfortunate it's disable by default. Without -v the docker VFS will slowly grow over time (depending on how many images have volumes of course). This can create real pain over time because you run out space for when you don't expect it. This problem is definitely more pronounced on CI machines that have high container churn rate. The same issues apply to the default fig commands. fig run should most likely have --rm and fig rm should have -v as well. Also if you use --rm on fig run you do not need to trap and clean up. I offer these suggestion from my experience using docker/fig and various combinations for them for CI things in various arrangements. You maybe able to save less knowledgeable customers some pain.

Missing buildbox-data dir causes install to fail on Ubuntu 13.10

I get the following failure:

-- https://buildbox.io

Installing Version: v0.1
Destination: /home/ubuntu/.buildbox

Downloading https://github.com/buildboxhq/buildbox-agent/releases/download/v0.1/buildbox-agent-linux-amd64.tar.gz
chmod: cannot access ‘/home/ubuntu/.buildbox/buildbox-data’: No such file or directory

When I created /home/ubuntu/.buildbox/buildbox-data it works.

Automatically cancel a long running build

It would be great if we could set a maximum build time and automatically cancel and kill a build if it goes over this time. We've got a few builds that spawn parallel processes and occasionally one of these hangs, leaving us in a situation where a build goes on indefinitely until it's manually cancelled.

buildbox-artifact hanging

This initially seemed similar to #30 however I am not seeing any certificate errors, and I've also upgraded to the version listed in this issue (0.2-beta.3) but I am still seeing the issue.

Basically it seems that artifacts are uploaded to S3 (Amazon) correctly but the process never finishes, and builds will hang forever on this step. Running an strace against the process doesn't yield anything particularly useful, other than it looping through some kind of wait state.

build-agent exits when triggering a build on OSX

I have an instance of the agent running on OSX Mavericks. It starts up fine and will pick up a build, but it dies right after logging "running bootstrap.sh" in the log file. No other errors are reported.

Feature Request: auto-expand groups with errors

It would be great if there was a way to only expand, or auto-expand, the sections of the build output where errors have occurred.

As far as implementing it goes, perhaps another special string can be checked for by buildbox for sections of interest, similar to the way buildbox currently looks for ---, e.g. if the build script hits an error it could trap and output something *** or similar, and buildbox would treat that as an erroring section.

Meta data values should be wildcarded

Say I have two agents with different versions of mysql:

buildbox agent start --token [token] --meta-data mysql=5.5
buildbox agent start --token [token] --meta-data mysql=5.1

And I only care about having mysql in general. Maybe in my project settings I could ask for meta data:

mysql=*

And it will run on either?

(I tried this and it doesn't currently work.)

Elastic agent is missing buildbox-artifact

After an otherwise successful build the elastic agent complains about missing buildbox-artifact:

ERROR: buildbox-artifact could not be found in /home/maglun/.buildbox

buildbox-agent version: buildbox-agent/1.0-beta.6 (darwin; 386)

buildbox-artifact gateway timeout

With many, many small files to upload, buildbox-artefact produces the following for me:

2014-06-19 21:04:57 [INFO ] Found 9840 files that match "results/**/*; log/**/*; tmp/capybara/**/*" 
2014-06-19 21:05:56 [FATAL] Failed to upload artifacts: Unexpected error: 504 Gateway Timeout 

(Example build id: "f9b0776ae49392e31dbff3ae6663076a9f54ab9a")

Integrate directly with Dpl

Dpl is an open source software made by Travis that allows you to deploy to multiple targets including S3.
It's completely open source so there is no reason why you shouldn't.

Add support for running with travis.yml

Most build services nowadays use a YAML file in order to generate the bootstrap.sh script.
You can ask the travis support team to generate it for you but I don't see why you should.

Feature request: on failure step

Hi,

It would be great if we could introduce a on-build-failure step so we can add things like notifications or cleanup steps.

Case study: we had some code merged that left some assets that subsequently broke every build after that. I had to (temporarily) add an asset wiper to the bootstrap script to get around this, however we don't generally want to wipe the assets as these take time to generate and don't need to be completely recreated all the time. If there was an on-fail step we could add the asset wiper into this and only do this type of cleanup when a build has a problem. It would of course need to run on the same CI boxes that ran the broken build step(s).

Thanks.

Code formatting

I know we all hate how github/tools format code with tabs but it would be nicer for contributors if this code was in line with golang formatting.

The reason I mention this is while hacking around on this project to try out some refactoring I discovered I pretty much had to disable every code check tool I have to avoid making massive white space changes. This in turn led to the "big list of compile issues" I used to get..

Note I am interested to hear what tools your using now, and why this code base is formatted the way it is, however it is pretty frustrating to edit with standard tools at the moment.

debug output is going to STDOUT rather than STDERR

Any logging or debug-type output from buildbox-agent commands should go to STDERR so that var setting (MY_VAR=$(buildbox-agent build-data get my-var) and redirection (buildbox-agent build-data get my-var > my-var.txt) still work as expected and the logging / debug output still shows up on the console running the script.

Windows startup flow

  • Figure out the best way to install the agent on a windows machine
  • Easy way to enter the agent token, it'd suck to have to "right click -> command line options" type deal

Changing repo URL

The default bootstrap.sh does not support changing git remotes. It will only check the existence of a .git folder and not if it is an related repository.

(I changed from github to gitlab with a project, had to destroy all .git folders to recover)

Remotes could be grepped from running git remotes -v in the clone condition.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.