bundlewrap/bundles/netbox/items.py

139 lines
3.5 KiB
Python
Raw Normal View History

2024-05-05 14:49:42 +00:00
users['netbox'] = {
'home': '/opt/netbox',
2021-08-17 16:02:15 +00:00
}
2024-05-05 14:49:42 +00:00
directories['/opt/netbox/src'] = {}
directories['/opt/netbox/media'] = {
'owner': 'netbox',
}
directories['/opt/netbox/scripts'] = {
'owner': 'netbox',
}
git_deploy['/opt/netbox/src'] = {
'repo': 'https://github.com/netbox-community/netbox.git',
'rev': node.metadata.get('netbox/version'),
'triggers': {
'action:netbox_install',
'svc_systemd:netbox-web:restart',
'svc_systemd:netbox-worker:restart',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
'tags': {
'netbox-install',
2021-08-17 16:02:15 +00:00
},
}
2024-05-05 14:49:42 +00:00
# This is a recreation of https://github.com/netbox-community/netbox/blob/develop/upgrade.sh
actions['netbox_create_virtualenv'] = {
'command': '/usr/bin/python3 -m virtualenv -p python3 /opt/netbox/venv',
'unless': 'test -d /opt/netbox/venv/',
'needed_by': {
'action:netbox_install',
2021-08-17 16:02:15 +00:00
},
}
2024-05-05 14:49:42 +00:00
actions['netbox_install'] = {
'triggered': True,
'command': ' && '.join([
'cd /opt/netbox/src',
'/opt/netbox/venv/bin/pip install --upgrade pip wheel setuptools django-auth-ldap gunicorn',
'/opt/netbox/venv/bin/pip install --upgrade -r requirements.txt',
]),
'needs': {
'pkg_apt:build-essential',
'pkg_apt:graphviz',
'pkg_apt:libffi-dev',
'pkg_apt:libldap2-dev',
'pkg_apt:libpq-dev',
'pkg_apt:libsasl2-dev',
'pkg_apt:libssl-dev',
'pkg_apt:libxml2-dev',
'pkg_apt:libxslt1-dev',
'pkg_apt:python3-dev',
'pkg_apt:zlib1g-dev',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
'tags': {
'netbox-install',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
}
last_action = 'netbox_install'
for upgrade_command in (
'migrate',
'trace_paths --no-input',
'collectstatic --no-input',
'remove_stale_contenttypes --no-input',
'reindex --no-input',
'clearsessions',
):
actions[f'netbox_upgrade_{upgrade_command.split()[0]}'] = {
2021-08-17 16:02:15 +00:00
'triggered': True,
2024-05-12 17:42:04 +00:00
'command': f'/opt/netbox/venv/bin/python /opt/netbox/src/netbox/manage.py {upgrade_command}',
2021-08-17 16:02:15 +00:00
'needs': {
2024-05-05 14:49:42 +00:00
f'action:{last_action}',
},
'tags': {
'netbox-upgrade',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
'triggered_by': {
'tag:netbox-install',
},
}
last_action = f'netbox_upgrade_{upgrade_command.split()[0]}'
files['/usr/local/lib/systemd/system/netbox-web.service'] = {
'triggers': {
'action:systemd-reload',
'svc_systemd:netbox-web:restart',
2021-08-17 16:02:15 +00:00
},
}
2024-05-05 14:49:42 +00:00
files['/usr/local/lib/systemd/system/netbox-worker.service'] = {
'triggers': {
'action:systemd-reload',
'svc_systemd:netbox-worker:restart',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
}
files['/opt/netbox/src/netbox/netbox/configuration.py'] = {
'content_type': 'mako',
'triggers': {
'svc_systemd:netbox-web:restart',
'svc_systemd:netbox-worker:restart',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
'needs': {
'git_deploy:/opt/netbox/src',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
'tags': {
'netbox-install',
2021-08-17 16:02:15 +00:00
},
}
2024-05-05 14:49:42 +00:00
files['/opt/netbox/gunicorn_config.py'] = {
'content_type': 'mako',
'triggers': {
'svc_systemd:netbox-web:restart',
2021-08-17 16:02:15 +00:00
},
2024-05-05 14:49:42 +00:00
}
svc_systemd['netbox-web'] = {
'needs': {
'file:/usr/local/lib/systemd/system/netbox-web.service',
'file:/opt/netbox/gunicorn_config.py',
'file:/opt/netbox/src/netbox/netbox/configuration.py',
'tag:netbox-install',
'tag:netbox-upgrade',
},
}
svc_systemd['netbox-worker'] = {
'needs': {
'file:/usr/local/lib/systemd/system/netbox-worker.service',
'file:/opt/netbox/src/netbox/netbox/configuration.py',
'tag:netbox-install',
'tag:netbox-upgrade',
2021-08-17 16:02:15 +00:00
},
}