Hello,
I have a function in my workflow that does some video encoding and needs a CPU optimized droplet to run efficiently.
The thing is I only need it to run a few times a day. So I wanted a way to initiate a task that creates a droplet (possibly a docker container), has it run a task and then destroy it.
I know I can create a cheap droplet and code it with the DigitalOcean API to accept tasks, create a droplet, run the task and then destroy it but I was wondering if there was already something built out that I can use to not reinvent the wheel.
Any help or hints in the right direction would be helpful. Thank you!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there @mindglitch,
I don’t think that there is built-in functionality to do that via the DigitalOcean control panel directly. Though I think that this is a great idea, sounds like it’d be super useful!
The best thing to do to get your voice heard regarding this would be to head over to our Product Ideas board and post a new idea, including as much information as possible for what you’d like to see implemented.
On another note, I have a small bash script that I use for similar tasks.
NOTE: Please, carefully review the whole script before using it.
The prerequisites are:
You need to have the
doctl
installed and authenticated, you can do that by following the steps here: https://www.digitalocean.com/community/tutorials/how-to-use-doctl-the-official-digitalocean-command-line-clientYou need to have your SSH Key on the machine that you are going to run the script on
You need Your SSH key ID
What the script does is:
In the
run_commands
function you can change the command/commands which you would like to execute.Hope that this helps! Regards, Bobby
I wrote a script that is similar to Bobby’s but I used cloud-init to provide the script to execute to the droplet.
The only downside to this approach is that you still need a machine running locally to either make the SSH connection, or to monitor the droplet to figure out when it’s done. If that local machine goes away (e.g. needs to be rebooted), or your locally running script errors out (the one that monitors the droplet), or whatever, the droplet will sit there until you go manually remove it. In my case, the last thing my script does is shut down the droplet, so I just poll every 30 seconds to see if the droplet is powered on and if it is not, I destroy it.
What would really be nice is if there was an “ephemeral” droplet option, where you could instruct DO to automatically destroy the droplet when it is powered off. Much like the
--rm
option on a Docker container. Could be a parameter in the create API for example. Then you could just use cloud-init to provide the script to run.