Skip to content

Commit

Permalink
T973: add build script for node_exporter package
Browse files Browse the repository at this point in the history
  • Loading branch information
rebortg committed Sep 17, 2024
1 parent 3463386 commit ece653f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/node_exporter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tar.gz
node_exporter-*
debian
29 changes: 29 additions & 0 deletions packages/node_exporter/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2020-2024 VyOS maintainers and contributors
//
// This program is free software; you can redistribute it and/or modify
// in order to easy exprort images built to "external" world
// it under the terms of the GNU General Public License version 2 or later as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
@NonCPS

// Using a version specifier library, use 'current' branch. The underscore (_)
// is not a typo! You need this underscore if the line immediately after the
// @Library annotation is not an import statement!
@Library('vyos-build@current')_

def pkgList = [
['name': 'node_exporter',
'scmCommit': 'master',
'scmUrl': 'https://github.com/prometheus/node_exporter',
'buildCmd': 'cd ..; ./build.py'],
]
// Start package build using library function from https://github.com/vyos/vyos-build
buildPackage('node_exporter', pkgList, null, true, "**/packages/node_exporter/**")
49 changes: 49 additions & 0 deletions packages/node_exporter/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3

from pathlib import Path
from subprocess import run
import requests
import tarfile

response = requests.get("https://api.github.com/repos/prometheus/node_exporter/releases/latest")
data = response.json()

version = data['tag_name'].replace('v', '')
for asset in data['assets']:
if 'linux-amd64' in asset['name']:
url = asset['browser_download_url']
name = asset['name']
break

# download the tarball from url
response = requests.get(url)
with open(name, 'wb') as f:
f.write(response.content)

# create the install dir
path = Path('debian/usr/sbin')
path.mkdir(parents=True, exist_ok=True)


# extract the tarball to current directory
with tarfile.open(name, "r:gz") as tar:
filenames = tar.getnames()
for filename in filenames:
if filename.endswith('node_exporter'):
tar.extract(filename)
break


# move the binary to install dir
Path(filename).rename(f"{path}/{filename.split('/')[1]}")

fpm_cmd = [
'fpm', '--input-type', 'dir', '--output-type', 'deb', '--name', 'node-exporter',
'--version', version, '--deb-compression', 'gz',
'--maintainer', 'VyOS Package Maintainers <[email protected]>',
'--description', 'Prometheus exporter for machine metrics',
'--license', 'Apache-2.0', '-C', 'debian', '--package', '..'

]

run(fpm_cmd)

0 comments on commit ece653f

Please sign in to comment.