Skip to content

Commit c557f51

Browse files
committed
Improve cleanup experience
1 parent b9cd545 commit c557f51

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
@@ -74,7 +74,6 @@ async function dockerBuild(func, variables) {
7474
params.push('-e', 'APPWRITE_ENV=development');
7575
params.push('-e', 'OPEN_RUNTIMES_ENV=development');
7676
params.push('-e', 'OPEN_RUNTIMES_SECRET=');
77-
params.push('-l', 'appwrite-env=dev');
7877
params.push('-e', `OPEN_RUNTIMES_ENTRYPOINT=${func.entrypoint}`);
7978

8079
for(const k of Object.keys(variables)) {
@@ -136,7 +135,6 @@ async function dockerStart(func, variables, port) {
136135
params.push('-d');
137136
params.push('--name', id);
138137
params.push('-p', `${port}:3000`);
139-
params.push('-l', 'appwrite-env=dev');
140138
params.push('-e', 'APPWRITE_ENV=development');
141139
params.push('-e', 'OPEN_RUNTIMES_ENV=development');
142140
params.push('-e', 'OPEN_RUNTIMES_SECRET=');
@@ -158,50 +156,18 @@ async function dockerStart(func, variables, port) {
158156
success(`Visit http://localhost:${port}/ to execute your function.`);
159157
}
160158

161-
async function dockerCleanup() {
162-
await dockerStopActive();
159+
async function dockerCleanup(functionId) {
160+
await dockerStop(functionId);
163161

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

193-
listProcess.stdout.on('data', (data) => {
194-
handleOutput(data);
195-
});
196-
197-
listProcess.stderr.on('data', (data) => {
198-
handleOutput(data);
199-
});
200-
201-
await new Promise((res) => { listProcess.on('close', res) });
202-
203-
for(const id of ids) {
204-
await dockerStop(id);
168+
const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz');
169+
if (fs.existsSync(tempPath)) {
170+
fs.rmSync(tempPath, { force: true });
205171
}
206172
}
207173

@@ -210,6 +176,5 @@ module.exports = {
210176
dockerBuild,
211177
dockerStart,
212178
dockerCleanup,
213-
dockerStopActive,
214179
dockerStop,
215180
}

0 commit comments

Comments
 (0)