Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T973: add build script for node_exporter package #757

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 additions & 0 deletions packages/node_exporter/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 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',
'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/**")
43 changes: 43 additions & 0 deletions packages/node_exporter/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

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

VERSION = '1.8.2'
rebortg marked this conversation as resolved.
Show resolved Hide resolved
URL = f'https://github.com/prometheus/node_exporter/releases/download/v{VERSION}/node_exporter-{VERSION}.linux-amd64.tar.gz'
TARNAME = f'node_exporter-{VERSION}.linux-amd64.tar.gz'

# download the tarball from url
response = requests.get(URL)
with open(TARNAME, '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(TARNAME, "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)
Loading