|
@@ -0,0 +1,183 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+#
|
|
|
+# Copyright: © 2023 Netdata Inc.
|
|
|
+# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
+'''Bundle the v2 dashboard code into the agent repo.
|
|
|
+
|
|
|
+ This is designed to be run as part of a GHA workflow, but will work fine outside of one.'''
|
|
|
+
|
|
|
+import os
|
|
|
+import shutil
|
|
|
+import subprocess
|
|
|
+
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+os.chdir(Path(__file__).parent.absolute())
|
|
|
+
|
|
|
+BASEDIR = 'v2'
|
|
|
+
|
|
|
+BASEPATH = Path(BASEDIR)
|
|
|
+
|
|
|
+TMPPATH = Path('tmp')
|
|
|
+
|
|
|
+URLSRC = 'https://app.netdata.cloud/agent.tar.gz'
|
|
|
+
|
|
|
+MAKEFILETEMPLATE = '''
|
|
|
+# Auto-generated by bundle_dashboard_v2.py
|
|
|
+# Copyright: © 2023 Netdata Inc.
|
|
|
+# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
|
|
|
+
|
|
|
+dist_noinst_DATA = \\
|
|
|
+ $(srcdir)/README.md
|
|
|
+
|
|
|
+webv2dir=$(webdir)/v2
|
|
|
+
|
|
|
+dist_webv2_DATA = \\
|
|
|
+ {0} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticdir=$(webv2dir)/static
|
|
|
+dist_webv2static_DATA = \\
|
|
|
+ {1} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticemailimgdir=$(webv2staticdir)/email/img
|
|
|
+dist_webv2staticemailimg_DATA = \\
|
|
|
+ {2} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticimgdir=$(webv2staticdir)/img
|
|
|
+dist_webv2staticimg_DATA = \\
|
|
|
+ {3} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticimgintegrationsdir=$(webv2staticimgdir)/integrations
|
|
|
+dist_webv2staticimgintegrations_DATA = \\
|
|
|
+ {4} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticimglogososdir=$(webv2staticimgdir)/logos/os
|
|
|
+dist_webv2staticimglogosos_DATA = \\
|
|
|
+ {5} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticimglogosservicesdir=$(webv2staticimgdir)/logos/services
|
|
|
+dist_webv2staticimglogosservices_DATA = \\
|
|
|
+ {6} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticimgmaildir=$(webv2staticimgdir)/mail
|
|
|
+dist_webv2staticimgmail_DATA = \\
|
|
|
+ {7} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitealarmsdir=$(webv2staticdir)/site/alarms
|
|
|
+dist_webv2staticsitealarms_DATA = \\
|
|
|
+ {8} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitepageserror404dir=$(webv2staticdir)/site/pages/error-404
|
|
|
+dist_webv2staticsitepageserror404_DATA = \\
|
|
|
+ {9} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitepageserror500dir=$(webv2staticdir)/site/pages/error-500
|
|
|
+dist_webv2staticsitepageserror500_DATA = \\
|
|
|
+ {10} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitepageserror501dir=$(webv2staticdir)/site/pages/error-501
|
|
|
+dist_webv2staticsitepageserror501_DATA = \\
|
|
|
+ {11} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitepageserror502dir=$(webv2staticdir)/site/pages/error-502
|
|
|
+dist_webv2staticsitepageserror502_DATA = \\
|
|
|
+ {12} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitepageserror503dir=$(webv2staticdir)/site/pages/error-503
|
|
|
+dist_webv2staticsitepageserror503_DATA = \\
|
|
|
+ {13} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitepageserror5xxdir=$(webv2staticdir)/site/pages/error-5xx
|
|
|
+dist_webv2staticsitepageserror5xx_DATA = \\
|
|
|
+ {14} \\
|
|
|
+ $(NULL)
|
|
|
+
|
|
|
+webv2staticsitepagesholding503dir=$(webv2staticdir)/site/pages/holding-page-503
|
|
|
+dist_webv2staticsitepagesholding503_DATA = \\
|
|
|
+ {15} \\
|
|
|
+ $(NULL)
|
|
|
+'''
|
|
|
+
|
|
|
+
|
|
|
+def copy_dashboard():
|
|
|
+ '''Fetch and bundle the dashboard code.'''
|
|
|
+ print('Preparing target directory')
|
|
|
+ shutil.rmtree(BASEPATH)
|
|
|
+ TMPPATH.mkdir()
|
|
|
+ print('::group::Fetching dashboard release tarball')
|
|
|
+ subprocess.check_call(f'curl -L -o agent.tar { URLSRC }', shell=True)
|
|
|
+ print('::endgroup::')
|
|
|
+ print('::group::Extracting dashboard release tarball')
|
|
|
+ subprocess.check_call(f"tar -xvf agent.tar -C { TMPPATH } --strip-components=1 --exclude='*.br' --exclude='*.gz'", shell=True)
|
|
|
+ print('::endgroup::')
|
|
|
+ print('Copying files')
|
|
|
+ (TMPPATH / BASEDIR).rename(BASEPATH)
|
|
|
+ (TMPPATH / 'index.html').rename(Path('./v2live.html'))
|
|
|
+ shutil.copytree(TMPPATH / 'static', Path('./static'), dirs_exist_ok=True)
|
|
|
+ shutil.rmtree(TMPPATH)
|
|
|
+ print('Copying README.md')
|
|
|
+ BASEPATH.joinpath('README.md').symlink_to('../.dashboard-v2-notice.md')
|
|
|
+ print('Removing dashboard release tarball')
|
|
|
+ BASEPATH.joinpath('..', 'agent.tar').unlink()
|
|
|
+
|
|
|
+
|
|
|
+def genfilelist(path):
|
|
|
+ '''Generate a list of files for the Makefile.'''
|
|
|
+ files = [f for f in path.iterdir() if f.is_file() and f.name != 'README.md']
|
|
|
+ files = [Path(*f.parts[1:]) for f in files]
|
|
|
+ files.sort()
|
|
|
+ return ' \\\n '.join([("$(srcdir)/" + str(f)) for f in files])
|
|
|
+
|
|
|
+
|
|
|
+def write_makefile():
|
|
|
+ '''Write out the makefile for the dashboard code.'''
|
|
|
+ print('Generating Makefile')
|
|
|
+ MAKEFILEDATA = MAKEFILETEMPLATE.format(
|
|
|
+ genfilelist(BASEPATH),
|
|
|
+ genfilelist(BASEPATH.joinpath('static')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'email', 'img')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'img')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'img', 'integrations')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'img', 'logos', 'os')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'img', 'logos', 'services')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'img', 'mail')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'alarms')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'pages', 'error-404')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'pages', 'error-500')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'pages', 'error-501')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'pages', 'error-502')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'pages', 'error-503')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'pages', 'error-5xx')),
|
|
|
+ genfilelist(BASEPATH.joinpath('static', 'site', 'pages', 'holding-page-503')),
|
|
|
+ )
|
|
|
+
|
|
|
+ BASEPATH.joinpath('Makefile.am').write_text(MAKEFILEDATA)
|
|
|
+
|
|
|
+
|
|
|
+def list_changed_files():
|
|
|
+ '''Create a list of changed files, and set it in an environment variable.'''
|
|
|
+ if 'GITHUB_ENV' in os.environ:
|
|
|
+ print('Generating file list for commit.')
|
|
|
+ subprocess.check_call('echo "COMMIT_FILES<<EOF" >> $GITHUB_ENV', shell=True)
|
|
|
+ subprocess.check_call('git status --porcelain=v1 --no-renames --untracked-files=all | rev | cut -d \' \' -f 1 | rev >> $GITHUB_ENV', shell=True)
|
|
|
+ subprocess.check_call('echo "EOF" >> $GITHUB_ENV', shell=True)
|
|
|
+
|
|
|
+
|
|
|
+copy_dashboard()
|
|
|
+write_makefile()
|
|
|
+list_changed_files()
|