---
# System prepended metadata

title: Installation of Buildkite-Agent

---

# Installation of Buildkite-Agent

## Notes

Official installation instructions for the Buildkite agent:

https://buildkite.com/docs/agent/v3/ubuntu

Systemd documentation

https://nts.strzibny.name/systemd-user-services/


## Installation 2023-07-01

I have installed the `en_US.UTF-8` local because the Buildkite logs kept complaining about `LC_ALL`

    sudo apt-get install locales
    sudo locale-gen en_US.UTF-8

### Specific to `buildkite-agent`

I have performed the following steps to install buildkite agent on the machine.
The advantage of installing it using `apt` is that in addition to the binary, it will also set up

* a `buildkite-agent` user
* a `systemd` service
* 

```bash
    curl -fsSL https://keys.openpgp.org/vks/v1/by-fingerprint/32A37959C2FA5C3C99EFBC32A79206696452D198 | sudo gpg --dearmor -o /usr/share/keyrings/buildkite-agent-archive-keyring.gpg
    
    echo "deb [signed-by=/usr/share/keyrings/buildkite-agent-archive-keyring.gpg] https://apt.buildkite.com/buildkite-agent stable main" | sudo tee /etc/apt/sources.list.d/buildkite-agent.list
    
    sudo apt-get update & sudo apt-get install -y buildkite-agent
    
    sudo sed -i "s/xxx/INSERT-YOUR-AGENT-TOKEN-HERE/g" /etc/buildkite-agent/buildkite-agent.cfg
```

After configuring the other things, I have started the agent with

```bash
    sudo systemctl enable buildkite-agent && sudo systemctl start buildkite-agent
```

I have edited the configuration file more

```bash
    less /etc/buildkite-agent/buildkite-agent.cfg
```

```
    name="machine:zurich.12-agent:%spawn"
    spawn=6
    no-color=true
    tag="queue=adrestia,queue=cardano-wallet,system=x86_64-linux"`.
```

### Specific to `nix`

As `buildkite-agent` user, I have symlinked a `.nix-profile`

    cd $HOME
    ln -s /nix/var/nix/profiles/default .nix-profile

I have set up a nix profile 

    mkdir -p $HOME/.config/nix/
    cat > nix.conf
      experimental-features = nix-command flakes
      max-jobs = auto
      cores = 0
      


I have added an environment hook for buildkite

```bash
less /etc/buildkite-agent/hooks/environment
```

```
#!/bin/bash

# The `environment` hook will run before all other commands, and can be used
# to set up secrets, data, and so on. Anything exported in hooks will be available
# to the build script.
#
# For example:
#
# export SECRET_VAR=token

# Note that as the script is sourced not run directly, the shebang line will be ignored
# See https://buildkite.com/docs/agent/v3/hooks#creating-hook-scripts

set -e

# PATH
# 2023-07-01 by apfelmus: Bring nix into the path
if [ -e /nix/var/nix/profiles/default/etc/profile.d/nix.sh ]; then
    . /nix/var/nix/profiles/default/etc/profile.d/nix.sh
    nix --version
fi
```

### Specific to `cardano-wallet`

I have linked the `/cache` directory.

    sudo ln -s /tmp /cache

### To make docker images build

Follow verbatim the instructions from [official](https://docs.docker.com/engine/install/ubuntu/)

Add docker group to the user

```
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo   "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" |   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -G docker -a buildkite-agent
sudo systemctl restart buildkite-agent
```

### To push docker images

