1
1
const activeDockerIds = {};
2
2
3
- export async function dockerStop(id) {
3
+ async function dockerStop(id) {
4
4
delete activeDockerIds[id];
5
5
const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], {
6
6
stdio: 'pipe',
@@ -9,7 +9,7 @@ export async function dockerStop(id) {
9
9
await new Promise((res) => { stopProcess.on('close', res) });
10
10
}
11
11
12
- export async function dockerPull(func) {
12
+ async function dockerPull(func) {
13
13
log('Pulling Docker image of function runtime ...');
14
14
15
15
const runtimeChunks = func.runtime.split("-");
@@ -29,7 +29,7 @@ export async function dockerPull(func) {
29
29
await new Promise((res) => { pullProcess.on('close', res) });
30
30
}
31
31
32
- export async function dockerBuild(func, variables) {
32
+ async function dockerBuild(func, variables) {
33
33
log('Building function using Docker ...');
34
34
35
35
const runtimeChunks = func.runtime.split("-");
@@ -63,7 +63,7 @@ export async function dockerBuild(func, variables) {
63
63
buildProcess.stdout.on('data', (data) => {
64
64
process.stdout.write(`\n${data}`);
65
65
});
66
-
66
+
67
67
buildProcess.stderr.on('data', (data) => {
68
68
process.stderr.write(`\n${data}`);
69
69
});
@@ -95,19 +95,19 @@ export async function dockerBuild(func, variables) {
95
95
const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz');
96
96
if (fs.existsSync(tempPath)) {
97
97
fs.rmSync(tempPath, { force: true });
98
- }
98
+ }
99
99
}
100
100
101
- export async function dockerStart(func, variables, port) {
101
+ async function dockerStart(func, variables, port) {
102
102
log('Starting function using Docker ...');
103
103
104
104
log("Permissions, events, CRON and timeouts dont apply when running locally.");
105
105
106
106
log('💡 Hint: Function automatically restarts when you edit your code.');
107
107
108
108
success(`Visit http://localhost:${port}/ to execute your function.`);
109
-
110
-
109
+
110
+
111
111
const runtimeChunks = func.runtime.split("-");
112
112
const runtimeVersion = runtimeChunks.pop();
113
113
const runtimeName = runtimeChunks.join("-");
@@ -136,7 +136,7 @@ export async function dockerStart(func, variables, port) {
136
136
params.push('-v', `${functionDir}/.appwrite/errors.txt:/mnt/logs/dev_errors.log:rw`);
137
137
params.push('-v', `${functionDir}/.appwrite/build.tar.gz:/mnt/code/code.tar.gz:ro`);
138
138
params.push(imageName, 'sh', '-c', `helpers/start.sh "${tool.startCommand}"`);
139
-
139
+
140
140
childProcess.spawn('docker', params, {
141
141
stdio: 'pipe',
142
142
pwd: functionDir
@@ -145,7 +145,7 @@ export async function dockerStart(func, variables, port) {
145
145
activeDockerIds[id] = true;
146
146
}
147
147
148
- export async function dockerCleanup() {
148
+ async function dockerCleanup() {
149
149
await dockerStop();
150
150
151
151
const functions = localConfig.getFunctions();
@@ -162,9 +162,18 @@ export async function dockerCleanup() {
162
162
}
163
163
}
164
164
165
- export async function dockerStopActive() {
165
+ async function dockerStopActive() {
166
166
const ids = Object.keys(activeDockerIds);
167
167
for await (const id of ids) {
168
168
await dockerStop(id);
169
- }
170
- }
169
+ }
170
+ }
171
+
172
+ module.exports = {
173
+ dockerStop,
174
+ dockerPull,
175
+ dockerBuild,
176
+ dockerStart,
177
+ dockerCleanup,
178
+ dockerStopActive,
179
+ }
0 commit comments