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:

  1. class Form(forms.BaseForm):
  2.  
  3. enable_debug_toolbar = forms.CheckboxField(
  4. 'Enable Django Debug Toolbar',
  5. required=False,
  6. initial=True,
  7. )
  8.  
  9. [...]
  10.  
  11. def to_settings(self, data, settings):
  12.  
  13. if settings["DEBUG"] and data['enable_debug_toolbar']:
  14.  
  15. [...]

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:

  1. {
  2. "package-name": "tutorial-django-debug-toolbar",
  3. "installed-apps": [
  4. "tutorial_django_debug_toolbar"
  5. ]
  6. }

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:

  1. divio addon validate
  2. Addon is valid!

and it’s ready to be uploaded with divio addon upload:

  1. divio addon upload
  2. warning: no files found matching '*' under directory '*/boilerplates'
  3. warning: no files found matching '*' under directory '*/templates'
  4. warning: no files found matching '*' under directory '*/static'
  5. warning: no files found matching '*' under directory '*/locale'
  6. warning: check: missing required meta-data: url
  7.  
  8. ok
  9. Configuration file is valid
  10.  
  11.  
  12. New version 1.8.0.1 of tutorial-django-debug-toolbar uploaded to alpha channel
  13.  
  14. 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.
'Divio app'
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