@@ -171,9 +171,17 @@ ${exec}
171171
172172echo "Execution completed."` ;
173173
174+ const cleanupCommands = {
175+ containers : "docker container prune --force" ,
176+ images : "docker image prune --all --force" ,
177+ builders : "docker builder prune --all --force" ,
178+ system : "docker system prune --all --force" ,
179+ volumes : "docker volume prune --all --force" ,
180+ } ;
181+
174182export const cleanupContainers = async ( serverId ?: string ) => {
175183 try {
176- const command = "docker container prune --force" ;
184+ const command = cleanupCommands . containers ;
177185
178186 if ( serverId ) {
179187 await execAsyncRemote ( serverId , dockerSafeExec ( command ) ) ;
@@ -189,7 +197,7 @@ export const cleanupContainers = async (serverId?: string) => {
189197
190198export const cleanupImages = async ( serverId ?: string ) => {
191199 try {
192- const command = "docker image prune --all --force" ;
200+ const command = cleanupCommands . images ;
193201
194202 if ( serverId ) {
195203 await execAsyncRemote ( serverId , dockerSafeExec ( command ) ) ;
@@ -203,7 +211,7 @@ export const cleanupImages = async (serverId?: string) => {
203211
204212export const cleanupVolumes = async ( serverId ?: string ) => {
205213 try {
206- const command = "docker volume prune --all --force" ;
214+ const command = cleanupCommands . volumes ;
207215
208216 if ( serverId ) {
209217 await execAsyncRemote ( serverId , dockerSafeExec ( command ) ) ;
@@ -219,7 +227,7 @@ export const cleanupVolumes = async (serverId?: string) => {
219227
220228export const cleanupBuilders = async ( serverId ?: string ) => {
221229 try {
222- const command = "docker builder prune --all --force" ;
230+ const command = cleanupCommands . builders ;
223231
224232 if ( serverId ) {
225233 await execAsyncRemote ( serverId , dockerSafeExec ( command ) ) ;
@@ -235,7 +243,7 @@ export const cleanupBuilders = async (serverId?: string) => {
235243
236244export const cleanupSystem = async ( serverId ?: string ) => {
237245 try {
238- const command = "docker system prune --all --force" ;
246+ const command = cleanupCommands . system ;
239247
240248 if ( serverId ) {
241249 await execAsyncRemote ( serverId , dockerSafeExec ( command ) ) ;
@@ -256,6 +264,34 @@ export const cleanupAll = async (serverId?: string) => {
256264 await cleanupSystem ( serverId ) ;
257265} ;
258266
267+ export const cleanupAllBackground = async ( serverId ?: string ) => {
268+ Promise . allSettled (
269+ Object . values ( cleanupCommands ) . map ( async ( command ) => {
270+ try {
271+ if ( serverId ) {
272+ await execAsyncRemote ( serverId , dockerSafeExec ( command ) ) ;
273+ } else {
274+ await execAsync ( dockerSafeExec ( command ) ) ;
275+ }
276+ } catch ( error ) { }
277+ } ) ,
278+ )
279+ . then ( ( results ) => {
280+ const failed = results . filter ( ( r ) => r . status === "rejected" ) ;
281+ if ( failed . length > 0 ) {
282+ console . error ( `Docker cleanup: ${ failed . length } operations failed` ) ;
283+ } else {
284+ console . log ( "Docker cleanup completed successfully" ) ;
285+ }
286+ } )
287+ . catch ( ( error ) => console . error ( "Error in cleanup:" , error ) ) ;
288+
289+ return {
290+ status : "scheduled" ,
291+ message : "Docker cleanup has been initiated in the background" ,
292+ } ;
293+ } ;
294+
259295export const startService = async ( appName : string ) => {
260296 try {
261297 await execAsync ( `docker service scale ${ appName } =1 ` ) ;
0 commit comments