Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftp exist check #178

Merged
merged 13 commits into from Nov 14, 2022
Merged

Ftp exist check #178

merged 13 commits into from Nov 14, 2022

Conversation

phocks
Copy link
Member

@phocks phocks commented Nov 3, 2022

Hi all, I'm going to open this PR as it basically works as is and could be merged, but I could maybe do with some feedback about developing it more and how to handle some edge cases, also as I'm not too familiar with Yeoman and all its user interaction stuff.

So what it does is this:

When a user generates a new project with aunty new it uses Yeoman's validate feature to run a function that lists the contents of the /www/res/sites/news-projects/ FTP directory and checks the folder names against the sluggified project name. If a match is found it doesn't let the user proceed and asks them to choose a different project name.

So the edge cases are:

  • If a user is not on the ABC network the FTP request will obviously fail and throw an FTP error to the cli then continue (with no FTP exist check)
  • If a user is offline the same thing will happen
  • If a user doesn't have their .abc-credentials file the same thing will happen
  • If a user's FTP password is out of date the same thing will happen

I guess my question is, what do we do when one of these errors happens. My feeling is that maybe we just console.log a warning that the FTP check failed and that there is a small possibility that the project already exists on the server, and then just leave it to the user to check manually or pray that it doesn't exist.

Keen to hear feedback.

@phocks
Copy link
Member Author

phocks commented Nov 3, 2022

Screen Shot 2022-11-03 at 1 58 48 pm

^example screenshot when it finds an existing directory

Also aunty init may need an ftp check (though it will be more difficult because we basically would have to tell the user to exit the generation process, change the directory name, and then try again).

ps. PR closes #105

Copy link
Member

@drzax drzax left a comment

Choose a reason for hiding this comment

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

Our conversation earlier makes a lot more sense now I've looked at this.

I had assumed the check would be at deploy time which is why I wasn't concerned that the check might fail if you weren't connected to the network (because the deploy would also fail).

I like the idea of checking at project init and this is a useful check, but I think we need check at deploy time too.

@@ -41,6 +41,7 @@
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.1.0",
"babel-loader": "^8.2.2",
"basic-ftp": "^5.0.2",
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there's anything ftp-deploy does that's special. It'd be ideal if we didn't depend on two separate FTP packages.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I agree. I had to use the alternate FTP package because ftp-deploy simply deploys and doesn't have too much other functionality.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @drzax I spoke to @colingourlay a bit this morning. My thinking on this is I'd like to not mess around with ftp-deploy which we've relied on in production for ages and it does its 1 job very well, as I don't know the full functionality of basic-ftp. Technically it should deploy the same, but seeing as the 1 job of this PR is to check for existing directories and not overwrite them, I don't really want to be messing around with implementing a different deploy library, which may even have unexpected consequences of overwriting other directories if not properly battle-tested with different configs and environments etc.

Happy to go to work on this feature straight away after merging this PR though. What do you think?


// Ours
const { OUTPUT_DIRECTORY_NAME } = require('../../constants');
const { cmd, hvy, opt, sec } = require('../../utils/color');
const { success } = require('../../utils/logging');
const { installDependencies } = require('../../utils/npm');
const { combine } = require('../../utils/structures');
const { getCredentials } = require('../../config/deploy');

const DEPLOY_DIRECTORY = '/www/res/sites/news-projects/';
Copy link
Member

Choose a reason for hiding this comment

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

Deploy directory isn't necessarily a constant. It would be good if (a) this path were not defined in multiple places (it's also here) and, (b) at deploy time, it checked based on the actual deploy where contentftp is the deploy target in .aunty/deploy.json.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK after talking with @colingourlay I'm going to get the deploy directory elsewhere and delete this.

@@ -139,3 +139,16 @@ module.exports.addProfileProperties = config => {

return combine(config, profileProps);
};

module.exports.getCredentials = () => {
Copy link
Member

Choose a reason for hiding this comment

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

The config resolution is quite complex so it might be best if @colingourlay could advise, but it would be nice if credentials were fetched the same way as for deploy. For example, it seems from https://github.com/abcnews/aunty/blob/main/src/config/deploy.js#L123 that it's possible to set the profiles file path to something other than the default for the purposes of deploy and we wouldn't want to end up with a mismatch here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this would be nice. @colingourlay I might grab you to run through a few things when I can.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same with this, should be able to get it from getDeployConfig from what @colingourlay tells me.

@phocks
Copy link
Member Author

phocks commented Nov 4, 2022

Thanks @drzax these are really helpful and yep @colingourlay's help on this would be great too. I agree we should probably have it check at deploy and release time and just ask the user if they're sure they want to overwrite to the directory each time. I just had concerns because after a project is created and deployed for the 1st time, then the user will have to say Y (yes) they want to overwrite on every subsequent deploy/release.

I'm just spitballing here now having a think .... what if we generated a unique ID for each project when created and put it in the base directory or something, that way we could check that the remote unique ID matches the local unique ID on deploy/upload and then we wouldn't even really need to ask them every time. Would that work?

@drzax
Copy link
Member

drzax commented Nov 4, 2022

I would want it to check if the specific branch or tag I'm deploying already exists. So for most release commands it wouldn't need to ask, but for a branch deploy it would ask on all but the first deploy, but I think that's good — branch deploys should be rare anyway.

@phocks
Copy link
Member Author

phocks commented Nov 8, 2022

Implemented a warning if the FTP check fails when generating a new project due to no network or no credentials.

⣾⢷⡾⢷⡾⣷ aunty
⢿⡾⢷⡾⢷⡿ generate project

? What is your project called? (New Project)

 Error: getaddrinfo ENOTFOUND contentftp.abc.net.au
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'XXXXXXXXXXXXXXX'
}

Warning: Unable to check if project name already exists, most likely due to a connection or credentials error. Please check manually before deploying.

? What is your project called? New Project
? What type of project is it? (Use arrow keys)
❯ Basic
  Preact
  React
  Svelte

@phocks phocks requested a review from drzax November 11, 2022 04:22
@phocks
Copy link
Member Author

phocks commented Nov 11, 2022

Okay, I think this is pretty much ready to go. Simplified the process of getting credentials. Talked over all the functionality with @colingourlay

Tested and working.

Copy link

@jtfell jtfell left a comment

Choose a reason for hiding this comment

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

Code all looks good to me. I think it makes sense to prioritise being cautious about changing the ftp deploy process over reducing npm deps.

👍 👍


const overwriteSelection = (
await cliSelect({
defaultValue: 0,
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how cliSelect config works, but it seems like 'Yes' might be the default here? 'No' would be a safer choice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that was a deliberate choice as most of the time you'll want to do the overwrite so it's just a single keypress confirmation, but absolutely a No default would be safer. Personally, I use aunty build && aunty deploy quite a bit to make latest working changes to interactives available to others while in the dev process and then proxy my local dev server using "Resource Override" in the browser. I can default it to No though and we'll check how it feels with the extra downarrow keypress.

@phocks phocks merged commit fd3015f into main Nov 14, 2022
@phocks phocks deleted the ftp-exist-check branch November 15, 2022 04:40
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.

None yet

4 participants