@@ -9,7 +9,7 @@ const logger = require('../logger');
9
9
const util = require ( '../util' ) ;
10
10
const { getConfig, tempDockerDir, faasFolder} = require ( '../config' ) ;
11
11
const docker = require ( '../docker/docker' ) ;
12
- const { pullImage} = require ( '../docker/util' ) ;
12
+ const { pullImage, pruneDocker } = require ( '../docker/util' ) ;
13
13
const { build} = require ( '../docker/build' ) ;
14
14
const { start} = require ( '../docker/start' ) ;
15
15
const getTemplates = require ( '../docker/templates' ) ;
@@ -90,6 +90,15 @@ const deploy = async ({username, folder, existing, resultStream}) => {
90
90
await template . executeTemplate ( templateProps ) ;
91
91
} ;
92
92
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
+
93
102
const scheduleCleanup = ( { username, project, existing} ) => {
94
103
process . nextTick ( async ( ) => {
95
104
// wait a bit for it to start
@@ -119,6 +128,9 @@ const scheduleCleanup = ({username, project, existing}) => {
119
128
const notRemoved = existing . filter ( c => ! toRemove . find ( rc => rc . Id === c . Id ) ) ;
120
129
scheduleCleanup ( { username, project, existing : notRemoved } ) ;
121
130
}
131
+
132
+ // run prune on next tick if enabled in config
133
+ schedulePrune ( ) ;
122
134
} ) ;
123
135
} ;
124
136
@@ -138,7 +150,7 @@ module.exports = fastify => {
138
150
// create new highland stream for results
139
151
const resultStream = _ ( ) ;
140
152
// run deploy
141
- deploy ( { username, folder, resultStream} ) ;
153
+ deploy ( { username, folder, resultStream} ) . then ( ( ) => schedulePrune ( ) ) ;
142
154
// reply with deploy stream
143
155
const responseStream = new Readable ( ) . wrap ( resultStream ) ;
144
156
reply . code ( 200 ) . send ( responseStream ) ;
0 commit comments