natCP icon indicating copy to clipboard operation
natCP copied to clipboard

Refactor code

Open FlamesRunner opened this issue 7 years ago • 16 comments

Yes, I know the code is a pile of spaghetti.

If your OCD is bugging you, and you have a good understanding of how to fix it, be my guest, and I'll add you to the contributor list on the front page.

Thanks!

FlamesRunner avatar Oct 07 '17 03:10 FlamesRunner

I would probably look at starting with composer for auto loading classes and pulling in any dependencies then look at

  • Routing
  • Templating engine
  • ORM
  • Database migrations (replacing raw sql file)

I think a framework would really help but just adding the above and making it a bit more MVC would be good. I would also write a few unit tests to check I am not breaking anything as I go

Happy to have a go but would not want to take it in a direction you don’t want to go

mikebywater avatar Oct 08 '17 07:10 mikebywater

Hey Mike,

Hope you're having a great day.

First off, let me address composer/framework issue: I wrote the base of the system while I wasn't using any sort of framework (e.g Laravel) as a rather terrible programmer at the time. Not the best of things to do IMO.

It'd likely require a rewrite really. It depends on what you're comfortable with, and I'll see what we can do from there.

Thanks again, Andrew

FlamesRunner avatar Oct 08 '17 13:10 FlamesRunner

Hi mate

Laravel is my framework of choice however I agree it would be a significant amount of work. I fancy having a go and would commit a decent amount of time to it but I would probably have a fair few questions about the existing code base so if you think it’s too much work we could be less ambitious.

Cheers

Mike

mikebywater avatar Oct 08 '17 21:10 mikebywater

Hey,

Feel free to ask any questions. I'll be happy to answer them.

Thanks again, Andrew

FlamesRunner avatar Oct 08 '17 22:10 FlamesRunner

Should we create a v2 branch or something and I could submit PR to that for you to review ?

mikebywater avatar Oct 10 '17 21:10 mikebywater

Sounds great. Technically, the panel hasn't yet reached version 1 persay, and I think it's a good idea to move it up to the next major version number.

So yeah, perhaps a release branch is an order.

FlamesRunner avatar Oct 10 '17 22:10 FlamesRunner

Do you want to create a branch for this then and I will submit PR's for you merge into that branch?

I am just setting up a development environment for the work so should be ready to start tonight

mikebywater avatar Oct 14 '17 17:10 mikebywater

I've created a development branch (called "development", located at https://github.com/FlamesRunner/natCP/tree/development) and you may use that. Any updates to the development branch, once you're ready for it to be tested, push it to the staging branch and I'll do some testing. You're free to help out on that as well.

Then, once everything is tested, it'll be merged with the master branch.

Once again, thanks for your help!

FlamesRunner avatar Oct 14 '17 19:10 FlamesRunner

No problem. Having a bit of trouble getting set up at the moment. Have you ran openVZ as a vagrant box? What is your current setup for development?

mikebywater avatar Oct 14 '17 21:10 mikebywater

The way I set up my development environment was with VirtualBox, installed with CentOS 6 x86_64. Then, I'd install the guest additions, and create a snapshot from there.

Depending on which you'd like to setup, the instructions will vary.

If you want to set up a slave server, use the installer from the slave/slaveInstall.sh. You can paste the following commands:

cd /tmp && wget https://raw.githubusercontent.com/FlamesRunner/natCP/master/slave/slaveInstall.sh
bash slaveInstall.sh

You can leave the system for the time being and the installation will be completed. Updating is a little weird; you need to download the contents of slave/, excluding slaveInstall.sh, change the permissions to 755 and move them to /sbin.

The host node is much easier to work with, as updating it simply requires you to unzip the contents of the web/ directory into the web server (which, at the moment, is using NGINX, PHP5 and MySQL.)

Hope this helps!

FlamesRunner avatar Oct 14 '17 22:10 FlamesRunner

I've given you access to the development branch, and you're now a collaborator. Any issues, just create a ticket and I'll answer them as needed. Reviews are required to merge to staging and master branches.

Once again, thank you for your help.

FlamesRunner avatar Oct 14 '17 22:10 FlamesRunner

Perfect. I am nearly sorted I have webapp working in one VM without any major issues and (I think) I have the slave node running properly in another VM in virtualbox. However I just need to work out how to add an ip to the slave vm that i can access from the webapp. Is this how you are set up?

mikebywater avatar Oct 15 '17 02:10 mikebywater

Yes it is. Depending on whether you used Virtualbox, you can create an internal network. In the VM settings tab, go to the network section, click adapter 2 and set the mode to "Internal network."

Do this for both VMs, then, copy down the IP from the slave node and add it to the host.

That should be it.

FlamesRunner avatar Oct 15 '17 04:10 FlamesRunner

OK I have my master VM 192.168.10.10 and the slave VM 192.168.10.11 both can ping each other. I have copied the slave access key. I have gone into admin/addNode.php and entered the ip and access key but get the "Error: Node cannot be added, because either the access key is invalid and/or the node does not have natCP installed" how do I validate that the slave is operating correctly?

mikebywater avatar Oct 15 '17 11:10 mikebywater

To verify whether the slave is working properly, SSH to [email protected] with the access key.

If this doesn't work, stop here, and generate a 32 character string to replace the password with the slave user.

If it does work, there's likely a PHP dependency that wasn't installed. Check the error logs for more information

Thanks again, Andrew

FlamesRunner avatar Oct 15 '17 13:10 FlamesRunner

Ok I am up and running thanks very much. I was being daft the host was rejecting password ssh as I usually only set up public key. I think I can get the basics working in Laravel tonight. Auth, user management and the node add. I think I would then be stuck, I will get that bit done and pushed to develop. I will maintain the current db structure for ease of upgrade.

mikebywater avatar Oct 15 '17 17:10 mikebywater