@@ -9,7 +9,7 @@ const logger = require('../logger');
99const util = require ( '../util' ) ;
1010const { getConfig, tempDockerDir, faasFolder} = require ( '../config' ) ;
1111const docker = require ( '../docker/docker' ) ;
12- const { pullImage} = require ( '../docker/util' ) ;
12+ const { pullImage, pruneDocker } = require ( '../docker/util' ) ;
1313const { build} = require ( '../docker/build' ) ;
1414const { start} = require ( '../docker/start' ) ;
1515const getTemplates = require ( '../docker/templates' ) ;
@@ -90,6 +90,15 @@ const deploy = async ({username, folder, existing, resultStream}) => {
9090 await template . executeTemplate ( templateProps ) ;
9191} ;
9292
93+ // schedule docker prune for next tick (if enabled in config)
94+ const schedulePrune = ( ) => {
95+ // get server config
96+ const serverConfig = getConfig ( ) ;
97+ if ( serverConfig . autoprune ) {
98+ process . nextTick ( pruneDocker ) ;
99+ }
100+ } ;
101+
93102const scheduleCleanup = ( { username, project, existing} ) => {
94103 process . nextTick ( async ( ) => {
95104 // wait a bit for it to start
@@ -119,6 +128,9 @@ const scheduleCleanup = ({username, project, existing}) => {
119128 const notRemoved = existing . filter ( c => ! toRemove . find ( rc => rc . Id === c . Id ) ) ;
120129 scheduleCleanup ( { username, project, existing : notRemoved } ) ;
121130 }
131+
132+ // run prune on next tick if enabled in config
133+ schedulePrune ( ) ;
122134 } ) ;
123135} ;
124136
@@ -138,7 +150,7 @@ module.exports = fastify => {
138150 // create new highland stream for results
139151 const resultStream = _ ( ) ;
140152 // run deploy
141- deploy ( { username, folder, resultStream} ) ;
153+ deploy ( { username, folder, resultStream} ) . then ( ( ) => schedulePrune ( ) ) ;
142154 // reply with deploy stream
143155 const responseStream = new Readable ( ) . wrap ( resultStream ) ;
144156 reply . code ( 200 ) . send ( responseStream ) ;
0 commit comments