diff --git a/agent/devbox.py b/agent/devbox.py index 87143c53..1510b2a9 100644 --- a/agent/devbox.py +++ b/agent/devbox.py @@ -76,6 +76,16 @@ def create_devbox_home_volume(self): command = f"docker volume create {self.devbox_name}_home" return self.execute(command) + @step("Delete Devbox Database Volume") + def delete_devbox_database_volume(self): + command = f"docker volume rm {self.devbox_name}_db-data" + return self.execute(command) + + @step("Delete Devbox Home Volume") + def delete_devbox_home_volume(self): + command = f"docker volume rm {self.devbox_name}_home" + return self.execute(command) + @step("Run Devbox") def run_devbox(self): command = ( diff --git a/agent/server.py b/agent/server.py index 93487fb8..4ced9d86 100644 --- a/agent/server.py +++ b/agent/server.py @@ -854,3 +854,15 @@ def get_devbox_docker_volumes_size(self, devbox_name): devbox = Devbox(devbox_name=devbox_name, server=self) return devbox.get_devbox_docker_volumes_size() + @step("Delete Devbox Directory") + def destroy_devbox_directory(self, devbox_name): + devboxes_directory = os.path.join(self.devboxes_directory, devbox_name) + shutil.rmtree(devboxes_directory) + + @job("Destroy Devbox", priority="low") + def destroy_devbox(self, devbox_name): + self.destroy_devbox_directory(devbox_name=devbox_name) + devbox = Devbox(devbox_name=devbox_name, server=self) + devbox.stop_devbox() + devbox.delete_devbox_database_volume() + devbox.delete_devbox_home_volume() diff --git a/agent/web.py b/agent/web.py index 0beecc53..237e688e 100644 --- a/agent/web.py +++ b/agent/web.py @@ -1395,7 +1395,14 @@ def get_devbox_status(devbox_name: str): result["duration"] = result["duration"].total_seconds() return jsonify(result) + @application.route("/devboxes//docker_volumes_size", methods=["POST"]) def get_devbox_docker_volumes_size(devbox_name: str): result = Server().get_devbox_docker_volumes_size(devbox_name=devbox_name) return {"message": result} + + +@application.route("/devboxes//destroy", methods=["POST"]) +def destroy_devbox(devbox_name: str): + job = Server().destroy_devbox(devbox_name=devbox_name) + return {"job": job}