|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 | import execa from 'execa';
|
| 16 | +import path from 'path'; |
16 | 17 | import { oneLine } from 'common-tags';
|
17 | 18 | import { Task } from './task';
|
18 | 19 | import { ContainerImage } from '../types';
|
@@ -52,8 +53,13 @@ export class BuildFunctionTask extends Task<ContainerImage> {
|
52 | 53 |
|
53 | 54 | // Create a temporary default ignore file
|
54 | 55 | // and delete it when we're done
|
55 |
| - await fs.promises.mkdir(`./${DEFAULT_BUILD_DIR}`, { recursive: true }); |
56 |
| - await fs.promises.writeFile(`./${DEFAULT_BUILD_DIR}/${imageId}.toml`, TOML.stringify(DEFAULT_PROJECT_CONFIG)); |
| 56 | + const contextDirectory = this.service.getDescriptor().context || '.'; |
| 57 | + const contextBuildDirectory = `./${path.join(contextDirectory, DEFAULT_BUILD_DIR)}`; |
| 58 | + |
| 59 | + await fs.promises.mkdir(contextBuildDirectory, { |
| 60 | + recursive: true, |
| 61 | + }); |
| 62 | + await fs.promises.writeFile(`./${contextBuildDirectory}/${imageId}.toml`, TOML.stringify(DEFAULT_PROJECT_CONFIG)); |
57 | 63 |
|
58 | 64 | let baseCmd = oneLine`
|
59 | 65 | build ${imageId}
|
@@ -99,6 +105,14 @@ export class BuildFunctionTask extends Task<ContainerImage> {
|
99 | 105 |
|
100 | 106 | // wait for the process to finalize
|
101 | 107 | await packProcess;
|
| 108 | + |
| 109 | + // clean build files |
| 110 | + await fs.promises.unlink(`./${contextBuildDirectory}/${imageId}.toml`); |
| 111 | + |
| 112 | + // remove build directory if empty |
| 113 | + if (fs.readdirSync(contextBuildDirectory).length === 0) { |
| 114 | + await fs.promises.rmdir(contextBuildDirectory); |
| 115 | + } |
102 | 116 | } catch (e) {
|
103 | 117 | throw new Error(e.message);
|
104 | 118 | }
|
|
0 commit comments