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
Create a new empty git repository on your version control server (i.e. GitHub, GitLab, Jenkins).
-
Create an access token so that the Data Plane API can access your remote repository.
-
On your HAProxy Enterprise server, configure the
/etc/hapee-2.4/
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-2.4/ $ sudo git init $ sudo git remote add origin https://gitlab.mycompany.com/username/repo.git $ sudo git fetch $ sudo git reset origin/master
-
Set your username and email for commits.
$ sudo git config --global user.name "Your Name" $ sudo git config --global user.email "name@mycompany.com"
-
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
-
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-2.4/", "config_file": "hapee-lb.cfg" }
-
Edit the file
/etc/hapee-extras/dataplaneapi.hcl
.Add the
git_mode
andgit_settings_file
fields to thedataplaneapi
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-2.4/maps" ssl_certs_dir = "/etc/hapee-2.4/ssl" spoe_dir = "/etc/hapee-2.4/spoe" } }
-
Restart the Data Plane API. If using the
program
section in yourhapee-lb.cfg
file, you can do this by restarting the HAProxy Enterprise service:$ sudo systemctl restart hapee-extras-dataplaneapi
-
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
Dynamic Data Updates