Skip to content

feat:(CLI) add delete app, bundle and entry points#75

Open
thabti wants to merge 7 commits intostaticdeploy:masterfrom
thabti:feat/delete-app
Open

feat:(CLI) add delete app, bundle and entry points#75
thabti wants to merge 7 commits intostaticdeploy:masterfrom
thabti:feat/delete-app

Conversation

@thabti
Copy link
Copy Markdown

@thabti thabti commented Sep 28, 2021

issue: #74

Adding CLI to support delete app, bundle and all attached entry points

usage:

export STATICDEPLOY_API_URL=http://abc.com/api
./bin/staticdeploy.js delete --app abc-master --tag master

@thabti thabti marked this pull request as draft September 28, 2021 08:51
@thabti thabti marked this pull request as ready for review September 28, 2021 08:51
@thabti thabti changed the title feat: add delete app, bundle and entry points feat:(CLI) add delete app, bundle and entry points Sep 28, 2021
@pscanf
Copy link
Copy Markdown
Member

pscanf commented Sep 29, 2021

Hello @sabeurthabti , great PR, thanks!

Sorry had a busy day yesterday and didn't get around to review it yet, but I should be able to take a look at it tonight.

For updating the website and the documentation, I think the only two files that need updating are the reference documentation for the CLI, and the CLI's README.

@thabti
Copy link
Copy Markdown
Author

thabti commented Sep 29, 2021

No rush mate, thanks for the support. I'd like to contribute more, getting understanding of the architecture.
I couldn't understand why the build was failing, will spend some time to fix the build also.

@thabti
Copy link
Copy Markdown
Author

thabti commented Oct 3, 2021

@pscanf any update on this? the ci command runs perfectly fine on my machine. I tried to spend time to debug it .. not luck.

@pscanf
Copy link
Copy Markdown
Member

pscanf commented Oct 3, 2021

Hadn't looked at the build yet, sorry. Definitely an odd error.

Seeing that it's thrown by the aws-sdk lib, and considering its version is pinned (so there cannot have been rogue updates) I would point my finger at the system aws-sdk talks to, i.e. the minio/minio container. From the docker hub image page, it seems they published a few new versions recently, you could try pulling the latest tag on your dev machine and see if you can replicate the error. If that does it, we can either try to update the aws-sdk lib, or downgrade the minio server.

Unfortunately these last days I got a bit swamped with work, so I can't offer much help until the second half of next week.

@pscanf
Copy link
Copy Markdown
Member

pscanf commented Oct 4, 2021

As I suspected, the issue is caused by newer versions of minio, that behave differently when an "empty" deleteObjects operation is issued:

s3Client.deleteObjects({
  Bucket: "bucket",
  Delete: { Objects: [] },
})

Maybe this was not a legal operation to begin with, but older versions of minio apparently didn't mind and returned a positive response, while newer versions do not (I did not try to figure out when the change happened).

In any case, I updated the integration test so that it won't issue such operations, and also updated the aws-sdk dependency for good measure.

Some CI steps still fail, but I think it's because - for security reasons - some secret env variables are not injected in the PR pipelines, so those steps should succeed when the PR is merged.

Alas, still haven't reviewed the code, will try to do that tomorrow.

Copy link
Copy Markdown
Member

@pscanf pscanf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than a few nitpicks, I have one change request and one doubt.

Change request

Split the delete command in two commands deleteAppWithEntrypoints (or maybe cleanupApp, or teardownApp) and deleteBundles.

Motivation

There is no connection between apps and bundles. They might have the same name, but it's by choice of whoever creates them, not a general rule. I could, for example, have bundles for my webapp my-webapp, which I sell to two different clients and deploy to the two apps client-A and client-B.

Doubt

The deleteApp command deletes entrypoints one by one, then deletes the app. This process could fail at any point, leaving StaticDeploy in an "unexpected" state. That is, the developer expects the app and all its entrypoints to have been deleted, but only a few entrypoints were deleted, while the others and the app still exist.

Solution

The ideal solution would be to move the process to the server, adding a CleanupAppByName usecase which issues all the delete commands in a transaction. However, this would greatly complicate things, so I think that given the unlikelihood of these failures, and given the relative harmless consequences, we can stick to the current implementation. I would however add some logs, for instance after each entrypoint deletion, so that it's easier for the user to see at which point of the process things went wrong (there are operation logs for that as well, but more feedback doesn't hurt).

// Read the config file
const config = readStaticdeployConfig(configPath);

// Return the deploy config, defaulting to an empty object
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: deploydelete

// Options for the deploy command as specified above
},
delete: {
// Options for the deploy command as specified above
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: deploydelete

});

const apps = await client.apps.getAll();
const app = apps.find((item) => item.name === argv.app);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you should handle the possibility of the app not existing, occurring for instance when the user specifies a non-existing app name, and throwing an error.

const apps = await client.apps.getAll();
const app = apps.find((item) => item.name === argv.app);
const appId = String(app?.id);
const appEntries = await client.entrypoints.getAll({ appId });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appEntries entrypoints

const appId = String(app?.id);
const appEntries = await client.entrypoints.getAll({ appId });

for (const index of appEntries.keys()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (const { id } of entrypoints) {
    await client.entrypoints.delete(id);
}

@@ -0,0 +1,168 @@
// import StaticdeployClient from "@staticdeploy/sdk";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove commented import

@pscanf
Copy link
Copy Markdown
Member

pscanf commented Oct 10, 2021

(Btw, sorry for the delay in reviewing, busy work period)

@thabti
Copy link
Copy Markdown
Author

thabti commented Oct 11, 2021

thanks fo rthe comments, will spend today resolving them. @pscanf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants