Simple Gradle Project with an IDE¶
This is a small example of using the IntelliJ IDE to develop groovy scripts together with Gradle and p6sync as build and export/import tools.
Use p6sync to pull a new instance disk image¶
Start by using p6sync on your laptop to create a filesystem that mirrors your Platform 6 instance configuration.
Here’s an example command line:
p6sync -instance simont-test -profile gradle -p6proxyoverride http://localhost:8480 -pull new
Note
Here we use the -profile option to specify a named project template to use when creating the filesystem
Open the new Gradle IDE Project¶
Simply select Open
from the IDE and select the app filesystem created by p6sync above.
For security, you will be asked by IntelliJ to confirm you wish to open this pre-created Gradle project:
Select Trust Project
and the IDE will import, initialise and build this Gradle Project.
Once built, Groovy and the DSL API will be added to your development classpath, and your groovy scripts are marked as source folders
Disable Auto Packaging¶
Auto Packaging
is something Platform 6 performs by default. It enables a user to create scripts with no need for package
declarations. It also adds a number of import
statements and runtime behavioural attributes to each script.
This default functionality works against IDEs as they use package
statements and import
s to validate source code as it is entered.
By disabling auto packaging
you must use package
and import
statements in all your scripts.
Note
By disabling auto packaging you will ensure the source executed is as it is displayed in your IDE making remote debug of executing scripts possible!
To disable auto packaging simply edit the meta.json associated with each script module:
Adding New Script Modules¶
Duplicating an existing script module folder or manually creating the folder structure allows new script modules to be created. Ensure you have a valid meta.json file in each script module folder.
Push Updates to Platform 6 Instance¶
Finally, use p6sync
to push your new or updated scripts to your Platform 6 instance for execution
Here’s an example command line:
p6sync -instance simont-test -p6proxyoverride http://localhost:8480 -push update
Excluding Files/Folders with .p6ignore¶
Ideally, files and folders that belong to an app and are not directly embedded within service configuration should be excluded from being ‘pushed’ to Platform 6 (User interface modules that build custom forms for example)
Although Platform 6 will ignore configuration that is not formatted for an installed service it is more efficient to simply ignore the folders in your local filesystem
To instruct p6sync to ignore files/folders simply create the file .p6ignore
and add the exclusions:
libs
gradle
ui
Execution and Remote Debugging¶
Once your scripts have been accepted by your instance they can be executed using the Scripts Service user interface. As a developer you will be modifying code, pushing to the instance and executing in an iterative manner so optimising this workflow using IDE and/or shell tools is a good idea
If auto packaging
is disabled then remote debugging of your scripts is also possible.
To enable remote debugging of your instance you must add the environment variable P6_DEBUG_ENABLED
to your docker-compose.yml and restart the instance.
This will start Platform 6 with a remote debug port of 5005
open and ready for connections.
ports:
- "2222:2222"
- "2221:2221"
- "5005:5005" # DEBUG
- "8080:8080"
environment:
- S6_KILL_GRACETIME=300000
- TZ=Etc/UTC
- XMX=1g
- P6_DATA_TEMPLATE=/opt/p6template.data
- P6_DATA=/opt/p6core.data
- P6_DEBUG_ENABLED
- p6core_instance_id=${INSTANCE_ID}
- p6auth_client_id=${CLIENT_ID}
- p6auth_client_secret=${CLIENT_SECRET}
Using the IDE, add a breakpoint to your script and start the platform6 debug:
Use the IDE controls to step over or into script statements and display or update variables as required.