-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
T973: add build script for node_exporter package
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.tar.gz | ||
node_exporter-* | ||
debian |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/**") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |