7. Package an addon (deployment)¶
Our Django Debug Toolbar Addon can now install and configure itself in a localproject; next is to complete the work of packaging it so that it can do thesame in a Divio Cloud project online.
As noted previously, when addons are installed into projects from the ControlPanel, they can expose their settings to the user via a web form in thealdryn_config.py
file.
7.1. Add a field to the configuration form¶
We’ll add a checkbox field, to control whether the user wants the Debug Toolbarto be active or not. The value of the new enable_debug_toolbar
field willbe passed to the to_settings()
method, in the data
dictionary. Thenwe’ll also test for data['enable_debug_toolbar']
before enabling theToolbar:
- class Form(forms.BaseForm):
- enable_debug_toolbar = forms.CheckboxField(
- 'Enable Django Debug Toolbar',
- required=False,
- initial=True,
- )
- [...]
- def to_settings(self, data, settings):
- if settings["DEBUG"] and data['enable_debug_toolbar']:
- [...]
We can’t actually test this locally - we’ll have to upload it before we can dothat.
7.2. Add the remaining packaging files¶
7.2.1. LICENSE¶
The addon needs a LICENSE
, so download that from the Control Panel and moveit to the package.
7.2.2. MANIFEST.in¶
Do the same for the MANIFEST.in
. The default MANIFEST.in
lists thelicence file as well as other directories that an addon is likely to have,though we don’t use any of those in this addon.
7.2.3. addon.json¶
The final packaging file is specific to the Divio Cloud, addon.json
, whichprovides some additional metadata:
- {
- "package-name": "tutorial-django-debug-toolbar",
- "installed-apps": [
- "tutorial_django_debug_toolbar"
- ]
- }
Download it and add it to the addon.
7.3. Validate and upload the addon¶
Make sure you’re in the addons-dev/tutorial-django-debug-toolbar
directory.
Now, running divio addon validate
should now confirm that the addon isvalid:
- ➜ divio addon validate
- Addon is valid!
and it’s ready to be uploaded with divio addon upload
:
- ➜ divio addon upload
- warning: no files found matching '*' under directory '*/boilerplates'
- warning: no files found matching '*' under directory '*/templates'
- warning: no files found matching '*' under directory '*/static'
- warning: no files found matching '*' under directory '*/locale'
- warning: check: missing required meta-data: url
- ok
- Configuration file is valid
- New version 1.8.0.1 of tutorial-django-debug-toolbar uploaded to alpha channel
- Configure your addon here https://control.divio.com/account/my-addons/878/
Don’t worry about the warnings - as long as there are no errors, all is inorder.
As the output notes, this version of the addon has been placed into the Alpha_release channel. If you visit the its _Versions page, you’ll be able to changethe release channel.
7.4. Install the addon in a Cloud project¶
If you now visit your project (or any project you have access to) in theControl Panel, and select its Addons menu, you’ll be able to select, installand configure your new addon, complete with the checkbox field you createdearlier.
If you deploy your Stage server, you’ll have the Debug Toolbar running in thecloud project.
7.5. Manage the addon via the Control Panel¶
You can manage your addon, moving particular versions of it into the Beta orStable channels, make it public and so on.
If you make it public, then other users will be able to use it in their projectstoo.
原文: http://docs.divio.com/en/latest/introduction/07-package-addon-cloud.html