Package: drone-plugin-exec
drone-plugin-execDrone plugin to execute commands in a configured environment on the host the container is running on.
The target side clones the repo and checks out the commit given by Drone, runs the command, then cleans up after itself.BuildPythonpython3-mvenvbuildvenvsourcebuildvenv/bin/activate
pipinstallbuildtwine
python3-mbuildDockerBuild the docker image with the following commands:dockerbuild.-tlocal/drone-plugin-execPlugin Configurationprivkey(required) - The plugin side private key.script(required) - A string with commands to run. This can be multiple lines.target_address(required) - The IP address or unix socket uri of the target side.target_port(required) - The port configured for the target side. Not required when using a unix socket.target_pubkey(required) - The target side public key string.checkout- Iftruethen the repo is checked out. Defaults totrue.log_level- The plugin side log level. Defaults toINFO.shell- The program to use to run the script. Defaults to/bin/bash.submodules- Iftrueall git submodules are updated. Defaults tofalse.teardown- When to teardown the runtime environment. Defaults toon-success.always- Always teardown after execution.on-success- Only teardown after successful execution.never- Never teardown. Always leave the temporary environment in place.umask- Set the umask for the script execution. Defaults to unset.user- Set the user to execute the script as. Defaults to unset (whoever the target is running as).Target ConfigurationThe target config is a toml file.address(required) - The address to listen on. This can be an IP or unix socket uri. Not required if usingdocker_network.port(required) - The port to listen on. Not required if using a unix socket.target_privkey_path(required) - The path to the target side private key file.plugin_pubkey(required) - The plugin side public key.docker_network- The docker network to attach to.docker_uri- The docker API uri if not the default. Defaults to whatever is set in the environment variables or the local socket.tmp_path_root- The directory to create temporary directories in. Defaults to/tmp/drone-plugin-exec-target.SetupOn The TargetInstall the targetsudoPIPX_HOME=/opt/pipxPIPX_BIN_DIR=/usr/local/binpipxinstalldrone-plugin-execGenerate the key pairssudomkdir-p/usr/local/etc/drone-plugin-exec/
sudodrone-plugin-exec-genkeypair--output/usr/local/etc/drone-plugin-exec/target_keyGenerate the plugin key pairThis only has to happen once and doesn't necessarily need to happen on the target but it's convenient to do on the first target.drone-plugin-exec-genkeypair--outputplugin_keyUpload the keys as secretsdronesecretadd--repository<yourusername>/<yourrepo>--nameplugin_exec_privkey--data@plugin_keyOrdroneorgsecretadd<yourorginization>plugin_exec_privkey@plugin_keyOptionally shred the plugin private key once it's been added as a secret.shred-uxplugin_keyConfigure the target/usr/local/etc/drone-plugin-exec/target.tomlplugin_pubkey='base64:<your base64 encoded plugin public key>'target_privkey_path='/usr/local/etc/drone-plugin-exec/target_key'tmp_path_root='/tmp/drone-exec-plugin-test-temp'address='unix:///var/run/drone-plugin-exec.sock'Run the target daemonDirectlydrone-plugin-exec-target--config<pathtotheconfig>Systemd/usr/local/lib/systemd/system/drone-plugin-exec-target.service[Unit]Description=Drone Plugin Exec DaemonAfter=network.target,docker.service[Service]Type=execExecStart=/usr/local/bin/drone-plugin-exec-target --config /usr/local/etc/drone-plugin-exec/target.toml[Install]WantedBy=multi-user.targetsudosystemctlenabledrone-plugin-exec-target.service
sudosystemctlstartdrone-plugin-exec-target.serviceHello WorldBelow are example configs for a target and a plugin.Target/usr/local/etc/drone-plugin-exec/target.tomlplugin_pubkey='base64:<your base64 encoded plugin public key>'target_privkey_path='/usr/local/etc/drone-plugin-exec/target_key'tmp_path_root='/tmp/drone-exec-plugin-test-temp'address='unix:///var/run/drone-plugin-exec.sock'PluginThis uses thenodeoption to limit execution to nodes with a target daemon labeled withdrone-plugin-exec-target=true..drone.yml---kind:pipelinename:Example exectype:dockernode:drone-plugin-exec-target:truesteps:-name:hello worldimage:haxwithaxe/drone-plugin-exec:latestvolumes:-/var/run/drone-plugin-exec.sock:/var/run/drone-plugin-exec.socksettings:checkout:truelog_level:INFOprivkey:from_secret:plugin_exec_privkeyrepo_type:httpscript:whoamiaddress:/var/run/drone-plugin-exec.socktarget_pubkey:base64:<base64 encoded target public key>teardown:on-success