HAProxy Enterprise Documentation 1.8r2

Git Integration

The Data Plane API integrates with git, enabling you to sync the changes you've made to your HAProxy Enterprise configuration to a remote git repository.

Configure git integration

  1. Install the Data Plane API.

  2. Create a new empty git repository on your version control server (i.e. GitHub, GitLab, Jenkins).

  3. Create an access token so that the Data Plane API can access your remote repository.

  4. On your HAProxy Enterprise server, configure the /etc/hapee-1.8/ directory as a git clone, as shown below:

    • initialize the directory as a local git clone,

    • set its remote URL to be the URL of your git repository,

    • fetch and check out the latest changes.

    $ cd /etc/hapee-1.8/
    $ sudo git init
    $ sudo git remote add origin https://gitlab.mycompany.com/username/repo.git
    $ sudo git fetch
    $ sudo git reset origin/master
  5. Set your username and email for commits.

    $ sudo git config --global user.name "Your Name"
    $ sudo git config --global user.email "name@mycompany.com"
  6. Commit and push the local hapee-lb.cfg file to the remote repository.

    $ sudo git add .
    $ sudo git commit -m "Initial commit"
    $ sudo git push origin master
  7. Add the file /etc/hapee-extras/git.settings with the following fields.

    • Set url to the URL of your git repository,

    • Set auth_access_token to your remote repository's access token.

    {
      "url": "https://gitlab.mycompany.com/username/repo.git",
      "auth_method": "access_token",
      "auth_access_token": "C4Axa1kCcxPv-fzrhsde",
      "storage_type": "dir",
      "storage_dir": "/etc/hapee-1.8/",
      "config_file": "hapee-lb.cfg"
    }
  8. Edit the file /etc/hapee-extras/dataplane-api.hcl.

    Add the git_mode and git_settings_file fields to the dataplaneapi block.

    dataplaneapi {
      host = "0.0.0.0"
      port = 5555
    
      git_mode = true
      git_settings_file = "/etc/hapee-extras/git.settings"
    
      userlist {
        userlist = "hapee-dataplaneapi"
      }
    
      resources {
        maps_dir      = "/etc/hapee-1.8/maps"
        ssl_certs_dir = "/etc/hapee-1.8/ssl"
        spoe_dir      = "/etc/hapee-1.8/spoe"
      }
    
    }
  9. Restart the Data Plane API. If using the program section in your hapee-lb.cfg file, you can do this by restarting the HAProxy Enterprise service:

    $ sudo systemctl restart hapee-1.8-lb
  10. Call the pull API endpoint to sync the Data Plane API with changes from the repository.

    $ curl -X POST \
        -u admin:adminpwd \
        -H 'Content-Type: application/json' \
        -d '{ "action":"pull"}' \
        '127.0.0.1:5555/v2/services/git/actions'

Sync changes with the remote repository

Once the configuration directory has been initialized as a local git clone, you can sync any changes by calling the commit and push actions.

For example, you could add a new server to an existing backend named webservers:

$ curl -X POST \
    -u admin:adminpwd \
    -H "Content-Type: application/json" \
    -d '{"name":"anotherserver", "address":"127.0.0.1", "port":8080, "check":"enabled"}' \
    '127.0.0.1:5555/v2/services/haproxy/configuration/servers?backend=webservers&version=1'

Then commit the change by calling the commit action on the /services/git/actions API endpoint:

$ curl -X POST \
    -u admin:adminpwd \
    -H 'Content-Type: application/json' \
    -d '{ "action":"commit", "commit_message":"add new web server" }' \
    '127.0.0.1:5555/v2/services/git/actions'

Then push the change to the remote repository by calling the push action:

$ curl -X POST \
    -u admin:adminpwd \
    -H 'Content-Type: application/json' \
    -d '{ "action":"push" }' \
    '127.0.0.1:5555/v2/services/git/actions'

You can also pull the latest changes from the repository by calling the pull action:

$ curl -X POST \
    -u admin:adminpwd \
    -H 'Content-Type: application/json' \
    -d '{ "action":"pull" }'
    '127.0.0.1:5555/v2/services/git/actions'

Next up

High Availability