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

Add Vagrantfile #1459

Merged
merged 12 commits into from
Dec 6, 2018
Merged

Add Vagrantfile #1459

merged 12 commits into from
Dec 6, 2018

Conversation

natanfelles
Copy link
Contributor

Description

Closes #1452

Work in progress. Idea is to be able to just clone the repository and simply run a vagrant up.

Adding two vhost - one for the framework, another for PHPUnit Code Coverage HTML.

I did not have time with docker yet - I think is not possible adjust everything in a single file with docker...

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@jim-parry
Copy link
Contributor

If I read the vagrantfile correctly, the two virtual hosts are on the VM itself, right.
And the intent is to take the current folder and sync it to those inside the VM.
Looks good, but I think we will need a bit of a writeup in the user guide, inclugin setting up VB & Vagrant, and getting the appropriate vagrantbox. It feels like a new page at user_guide_src/testing/vagrant.rst would be the most appropriate, with user_guide_src/indexrst updated as well. If you want to take a stab at that, that would be good. If not, leave it for me, as I plan a few more explanations for installation/setup/testing.

@natanfelles
Copy link
Contributor Author

Yes.

http://localhost:8080 for the framework.
http://localhost:8081 for local code coverage.

Tested MySQL and Postgres with Debian Testing all OK. But in Debian it is more complicated to configure the PHP version. Testing is coming with 7.3 and I noticed some bugs (do not recognize constant values as default values as function params).

Tuning to work with Ubuntu.

Instructions in the manual will be very good. Sorry, my English is not good.

@jim-parry
Copy link
Contributor

@lonnieezell I seem to recall you mentioning that you use vagrant. If that is the case, does this seem like a suitably generic approach? Anything to add?

@lonnieezell
Copy link
Member

I used to use a virtual machine for it but currently just use it in MacOS. The script looks excellent (especially like the 3 different ports!). One thing I would love to see, though, is support for multiple PHP versions, since we sometimes need to debug in different versions to track down issues.

I use a great little script, php-version which makes that painless. It would be awesome if this was supported out of the box.

My only other concern is if this might conflict with using the built-in php spark serve. I almost never use a full server anymore for development, though I guess that's needed to support the multiple port mapping.

@jim-parry
Copy link
Contributor

@lonnieezell I think it is easier to configure the VM to have apache running as a service, than it would be to have it use the spark server. Not sure how easy it would be to configure the spark server as an O/S service, hmmm.
I think that a developer testing their app would find the spark server easier, but for testing the framework and proposed contributions, the VM would seem more "authentic".
Just a thought - even with a VM fired up with Apache, like this PR does, one can always "vagrant ssh" into the box and run the spark server locally. It would not have a port mapped for the host platform, but would still be usable inside the VM, eg REST API testing or unit testing for the app.

@jim-parry
Copy link
Contributor

@natanfelles Why the "bionic" version of ubuntu? "trusty" has the lion's share of vagrantbnox downloads. I don't know if the platform version has (or should have) any effect on the testing/unit testing.

@natanfelles
Copy link
Contributor Author

@jim-parry Because it is the most current LTS version: https://www.ubuntu.com/about/release-cycle
And it comes with PHP 7.2 by default.

@lonnieezell I have not had the opportunity to use php-version yet. It would be nice to be able to test in several versions of PHP, in the VM.

In the morning I was studying phpcov to merge the various tests and show them in the same coverage-html of the VM. To the local coverage be more similar to coverage/coveralls.

The Vagrantfile is working. The VM occupies ~600MB RAM when running PHPUnit. And ~180MB of downloaded packages (~700MB after installation).

Ah, @jim-parry , also with Sphinx ready to be used. I think this will help in editing the user guide.

@jim-parry
Copy link
Contributor

@natanfelles Good call, then :)

@natanfelles
Copy link
Contributor Author

.env for tests

app.baseURL = 'http://example.com'
database.tests.hostname = localhost
database.tests.database = codeigniter
database.tests.username = root
database.tests.password = password
database.tests.DBDriver = Postgre # MySQLi, Postgre, SQLite3
database.tests.port = 5432 # MySQLi = 3306 # Postgre = 5432

Possible gaps:

Apache is down after vagrant up

Motive: Unknown
Solution: Login with vagrant ssh and run sudo systemctl restart apache2

PHPUnit error:

There was 1 error:

1) CodeIgniter\CodeIgniterTest::testRunDefaultRoute
ErrorException: Undefined variable: value

Motive: Unknown - probably is related with vagrant symlinks issues
Solution: Run phpunit directly by ./vendor/phpunit/phpunit/phpunit

Vagrantfile Outdated
# Display the VirtualBox GUI when booting the machine
vb.gui = false
# Customize the amount of memory on the VM:
vb.memory = "768"
Copy link
Contributor Author

@natanfelles natanfelles Nov 15, 2018

Choose a reason for hiding this comment

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

VM runs with 400MB, 308MB "stopped". Required ~600MB when running tests

Copy link
Contributor

Choose a reason for hiding this comment

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

I run mine with 1024m. Probably overkill, but hoping/planning for near-complete code coverage eventually.
Is there much of a penalty specifying more memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It depends on the user's machine. Thinking about taking up as little resources as possible, I started with 512MB, but PHPUnit broke for not having enough memory to do the coverage. I run again and saw that it occupies about 600MB at most (MySQLi driver). I increased 256MB.

Testing now with the SQLite3 driver, PHPUnit also could not gererate the code coverage:

Type:        ErrorException
Message:     proc_open(): fork failed - Cannot allocate memory
Filename:    /var/www/codeigniter/vendor/sebastian/version/src/Version.php
Line Number: 89

I'll go up to 1024 and test again. But this seems to me a very high value, I'm thinking of maybe already letting in the script instructions to create a swap file, because the memory only rises so much when it's generating code coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SQLite3 with database.tests.database = ':memory:'...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Increased the default vb.memory to 1024 and added script to auto add 1GB of swap if the VM has low RAM.

Tested using SQLite3 with vb.memory = "512" and no problem. It used ~120MB of swap during coverage.

@lonnieezell
Copy link
Member

@natanfelles I really like what you're building here. Thanks!

@natanfelles
Copy link
Contributor Author

natanfelles commented Nov 21, 2018

What do yous prefer to be the default:

  1. Use Forwarded Ports with CodeIgniter at http://localhost:8080 (current)
  2. Use a Private Network, with custom domain (codeigniter.test ?) - this way all VM services will be available by domain or private IP (192.168.10.10 ?)

I prefer the second option, but the user will need to update their hosts file to access by domain.

192.168.10.10    codeigniter.test

@jim-parry
Copy link
Contributor

I prefer the virtual host approach myself - more realistic IMHO.
I presume that 192.168.10.10 is inside the VM? or are you tinking that the alias be defined in the host (developer) platform. If the latter, then not everyone would have 192.168.x.x

@natanfelles
Copy link
Contributor Author

Yes. 192.168.10.10 is the VM IP.

The developer can access directly or by a custom domain (codeignter.test by default, maybe)

@natanfelles
Copy link
Contributor Author

captura de tela de 2018-11-20 23-12-39

@natanfelles
Copy link
Contributor Author

or example.com because it is the domain used in the tests

@jim-parry jim-parry added this to the 4.0.0 milestone Nov 29, 2018
@natanfelles natanfelles changed the title WIP - Add Vagrantfile Add Vagrantfile Dec 1, 2018
@jim-parry
Copy link
Contributor

"Vagrantfile" & ".vagrant" are currently in the .gitignore file.
We should rename "Vagrantfile" in this PR to "Vagrantfile.dist", so it doesn't clobber an existing setup.
If you can do that, I will merge this and start on the docs for it :)

@jim-parry jim-parry merged commit 40e2d4c into codeigniter4:develop Dec 6, 2018
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.

3 participants