Skip to content

Instantly share code, notes, and snippets.

@Maxim-Filimonov
Last active August 29, 2015 14:21
Show Gist options
  • Save Maxim-Filimonov/3d9831d3d10735b2dc6f to your computer and use it in GitHub Desktop.
Save Maxim-Filimonov/3d9831d3d10735b2dc6f to your computer and use it in GitHub Desktop.
Buildkite agent cloud init config

Prerequisites

Tested only on google cloud, might need some adjustment in image path to make it work on AWS/DigitalOcean. Google instance should have two disks attached named: var-lib-docker and buildkite var-lib-docker will be used to store docker images so give it as much space as you can buildkite is stored to store buildkite builds and artifacts

Variables

Just search for < to find what to replace

#cloud-config
write_files:
- path: /root/.ssh/id_rsa
permissions: 0600
owner: root
content: |
-----BEGIN RSA PRIVATE KEY-----
<YOUR_SSH_KEY_TO_PULL_PRIVATE_GITHUB_REPO>
-----END RSA PRIVATE KEY-----
- path: /root/.dockercfg
permissions: 0600
owner: root
content: |
{
"https://index.docker.io/v1/": {
"auth": "<DOCKER_HUB_AUTH_TOKEN>",
"email": "<EMAIL>"
}
}
coreos:
etcd:
# generate a new token for each unique cluster from https://discovery.etcd.io/new?size=1
# specify the intial size of your cluster with ?size=X
discovery: https://discovery.etcd.io/<TOKEN>
# multi-region and multi-cloud deployments need to use $public_ipv4
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
# Attached storage mount to avoid space overfow with default tiny GCE drive
- name: format-var-lib-docker.service
command: start
content: |
[Unit]
Description=Formats the var-lib-docker drive
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/wipefs -f /dev/disk/by-id/google-var-lib-docker
ExecStart=/usr/sbin/mkfs.btrfs -f /dev/disk/by-id/google-var-lib-docker
- name: var-lib-docker.mount
command: start
content: |
Before=docker.service
[Mount]
What=/dev/disk/by-id/google-var-lib-docker
Where=/var/lib/docker
Type=btrfs
- name: format-buildkite.service
command: start
content: |
[Unit]
Description=Formats the buildkite drive
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/wipefs -f /dev/disk/by-id/google-buildkite
ExecStart=/usr/sbin/mkfs.btrfs -f /dev/disk/by-id/google-buildkite
- name: buildkite.mount
command: start
content: |
Before=docker.service
[Mount]
What=/dev/disk/by-id/google-buildkite
Where=/buildkite
Type=btrfs
- name: fail2ban.service
command: start
content: |
[Unit]
Description=Fail2ban systemd monitoring service
After=docker.service
[Service]
User=core
TimeoutStartSec=10m
EnvironmentFile=/etc/environment
ExecStartPre=-/usr/bin/docker kill fail2ban
ExecStartPre=-/usr/bin/docker rm fail2ban
ExecStart=/usr/bin/docker run --name fail2ban --privileged --net=host -v /run/systemd:/var/run/systemd ianblenke/fail2ban
ExecStop=/usr/bin/docker kill fail2ban
ExecStop=/usr/bin/docker rm fail2ban
Restart=on-failure
TimeoutSec=10
RestartSec=5
[X-Fleet]
Global=true
- name: buildagent.service
command: start
content: |
[Unit]
Description=CI build agent
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/docker run -e BUILDKITE_AGENT_TOKEN=<BUILDKITE_TOKEN> -v /var/lib/docker:/var/lib/docker -v /var/run/docker.sock:/var/run/docker.sock -v /buildkite/builds/:/buildkite/builds/ -v /root/.ssh:/root/.ssh -v /root/.dockercfg:/root/.dockercfg buildkite/agent:ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment