Skip to content

Commit bcf958e

Browse files
Merge pull request #904 from appwrite/fix-cli-dev-cleanup
Fix: Dev function cleanup experience
2 parents e9f48f9 + c557f51 commit bcf958e

File tree

2 files changed

+12
-47
lines changed

2 files changed

+12
-47
lines changed

templates/cli/lib/commands/run.js.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
8686
log("If you wish to change your local settings, update the appwrite.json file and rerun the 'appwrite run' command.");
8787
hint("Permissions, events, CRON and timeouts dont apply when running locally.");
8888

89-
await dockerCleanup();
89+
await dockerCleanup(func.$id);
9090

9191
process.on('SIGINT', async () => {
9292
log('Cleaning up ...');
93-
await dockerCleanup();
94-
success();
93+
await dockerCleanup(func.$id);
94+
success("Local function successfully stopped.");
9595
process.exit();
9696
});
9797

templates/cli/lib/emulation/docker.js.twig

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ async function dockerBuild(func, variables) {
7272
params.push('-e', 'APPWRITE_ENV=development');
7373
params.push('-e', 'OPEN_RUNTIMES_ENV=development');
7474
params.push('-e', 'OPEN_RUNTIMES_SECRET=');
75-
params.push('-l', 'appwrite-env=dev');
7675
params.push('-e', `OPEN_RUNTIMES_ENTRYPOINT=${func.entrypoint}`);
7776

7877
for(const k of Object.keys(variables)) {
@@ -133,7 +132,6 @@ async function dockerStart(func, variables, port) {
133132
params.push('--rm');
134133
params.push('--name', id);
135134
params.push('-p', `${port}:3000`);
136-
params.push('-l', 'appwrite-env=dev');
137135
params.push('-e', 'APPWRITE_ENV=development');
138136
params.push('-e', 'OPEN_RUNTIMES_ENV=development');
139137
params.push('-e', 'OPEN_RUNTIMES_SECRET=');
@@ -163,50 +161,18 @@ async function dockerStart(func, variables, port) {
163161
success(`Visit http://localhost:${port}/ to execute your function.`);
164162
}
165163

166-
async function dockerCleanup() {
167-
await dockerStopActive();
164+
async function dockerCleanup(functionId) {
165+
await dockerStop(functionId);
168166

169-
const functions = localConfig.getFunctions();
170-
for(const func of functions) {
171-
const appwritePath = path.join(process.cwd(), func.path, '.appwrite');
172-
if (fs.existsSync(appwritePath)) {
173-
fs.rmSync(appwritePath, { recursive: true, force: true });
174-
}
175-
176-
const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz');
177-
if (fs.existsSync(tempPath)) {
178-
fs.rmSync(tempPath, { force: true });
179-
}
180-
}
181-
}
182-
183-
async function dockerStopActive() {
184-
const listProcess = childProcess.spawn('docker', ['ps', '-a', '-q', '--filter', 'label=appwrite-env=dev'], {
185-
stdio: 'pipe',
186-
});
187-
188-
const ids = [];
189-
function handleOutput(data) {
190-
const list = data.toString().split('\n');
191-
for(const id of list) {
192-
if(id && !id.includes(' ')) {
193-
ids.push(id);
194-
}
195-
}
167+
const func = localConfig.getFunction(functionId);
168+
const appwritePath = path.join(process.cwd(), func.path, '.appwrite');
169+
if (fs.existsSync(appwritePath)) {
170+
fs.rmSync(appwritePath, { recursive: true, force: true });
196171
}
197172

198-
listProcess.stdout.on('data', (data) => {
199-
handleOutput(data);
200-
});
201-
202-
listProcess.stderr.on('data', (data) => {
203-
handleOutput(data);
204-
});
205-
206-
await new Promise((res) => { listProcess.on('close', res) });
207-
208-
for(const id of ids) {
209-
await dockerStop(id);
173+
const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz');
174+
if (fs.existsSync(tempPath)) {
175+
fs.rmSync(tempPath, { force: true });
210176
}
211177
}
212178

@@ -215,6 +181,5 @@ module.exports = {
215181
dockerBuild,
216182
dockerStart,
217183
dockerCleanup,
218-
dockerStopActive,
219184
dockerStop,
220185
}

0 commit comments

Comments
 (0)