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

Vagrant with ansible #81

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.vagrant/
*.log

/app/bootstrap.php.cache
/app/config/parameters.yml
/build/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ before_install:
# Create database, schema and fixtures
install:
- composer install -q
- cp app/config/parameters.yml.dist app/config/parameters.yml
- cp app/config/parameters.yml.test app/config/parameters.yml

# Run script
script:
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ if your dev installation is older than 2015-05-15 you will need to add the initi
php app/console do:mi:version --add 20150515104913
```

development setup (vagrant)
---------------------------
Prerequirements: Vagrant installed, Virtualbox installed, Ansible installed

* ```vagrant up```
Copy link
Owner

Choose a reason for hiding this comment

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

does this even render in Markdown? some combination of inline code block and fenced code block? to see what I was talking about? https://raw.githubusercontent.com/tolry/talkly/master/README.md

* ```vagrant ssh```
* ```cd /srv/www```
* ```bin/console fo:us:cr``` (follow the steps)
* run https://mental.www/app_dev.php in browser and log in with your credentials
dragonito marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"

unless Vagrant.has_plugin?("vagrant_hostupdater")
config.vm.hostname = "mental.www"
end

config.vm.network "private_network", ip: "192.168.179.2"
config.vm.network "forwarded_port", guest: 80, host: 8888

config.vm.synced_folder ".", "/srv/www", :nfs => true

config.vm.provision "shell", inline: "which python || sudo apt -y install python"

config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/playbook.yml"
end

end
1 change: 1 addition & 0 deletions ansible/playbook.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default
12 changes: 12 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- hosts: all
become: yes
vars_files:
- vars/main.yml
roles:
- { role: geerlingguy.nginx }
- { role: geerlingguy.mysql }
- { role: geerlingguy.php }
- { role: geerlingguy.composer }
dragonito marked this conversation as resolved.
Show resolved Hide resolved
- { role: ocha.yarn }
- { role: memcached }
- { role: initproject }
6 changes: 6 additions & 0 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- geerlingguy.mysql
- geerlingguy.nginx
- geerlingguy.php
- geerlingguy.php-versions
- ocha.yarn
- geerlingguy.composer
14 changes: 14 additions & 0 deletions ansible/roles/initproject/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- composer:
command: install
working_dir: /srv/www/

- name: create database
command: bin/console do:da:cr --if-not-exists
args:
chdir: /srv/www/

- name: run migrations
command: bin/console --no-interaction do:mi:mi
args:
chdir: /srv/www/
4 changes: 4 additions & 0 deletions ansible/roles/memcached/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: install memcached
apt:
name: memcached
62 changes: 62 additions & 0 deletions ansible/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
mysql_root_password: root

mysql_databases:
- name: mental
encoding: utf8
collation: utf8_general_ci

mysql_users:
- name: root
host: "%"
password: root
priv: "mental.*:ALL"

nginx_vhosts:
- listen: "443 ssl http2"
server_name: "mental.www"
root: "/srv/www/web"
index: "app_dev.php"
state: "present"
template: "{{ nginx_vhost_template }}"
filename: "mental.www.conf"
extra_parameters: |
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include fastcgi_params;
}
location ~ \.php$ {
return 404;
}
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;

php_packages_state: "latest"
php_webserver_daemon: "nginx"
php_version: "7.2"
php_default_version_debian: "7.2"
php_enable_php_fpm: true
php_memory_limit: "128M"
php_max_execution_time: "90"
php_upload_max_filesize: "256M"
php_packages:
- php
- php-fpm
- php-cli
- php-common
- php-gd
- php-mbstring
- php-pdo
- php-xml
- php-mysql
- php-apcu
- php-curl
- php-memcached
- php-zip
4 changes: 2 additions & 2 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: symfony
database_name: mental
database_name_testing: symfony
database_user: root
database_password: ~
database_password: root
database_platform: 5.6

mailer_transport: smtp
Expand Down
23 changes: 23 additions & 0 deletions app/config/parameters.yml.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
parameters:
Copy link
Owner

Choose a reason for hiding this comment

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

you will need to change

- cp app/config/parameters.yml.dist app/config/parameters.yml

To make travis use this file, Scrutinizer is configured within scrutinizer, I think - will have to check

Copy link
Owner

Choose a reason for hiding this comment

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

scrutinizer automatically uses parameters.dist.yml, see https://scrutinizer-ci.com/g/tolry/mental-note/inspections/d8c5ac24-1fe8-4334-a5ea-a26616bb512c/log

sed -i 's/database_host: .*/database_host: 127.0.0.1/' app/config/parameters.yml.dist

so I would really prefer keeping the dist.yml as template as well as for the tests (travis, scrutinizer) and your setup using a different file or seding your settings or similar

database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: mental
database_name_testing: symfony
database_user: root
database_password: ~
database_platform: 5.6

mailer_transport: smtp
mailer_host: localhost
mailer_user: ~
mailer_password: ~

locale: en
secret: Ohthaechoosheekohngov2iepaothae5ahd5ya9kie

session_memcache_host: localhost
session_memcache_port: 11211
session_memcache_prefix: mn_sess
session_memcache_expire: 604800 # 1 week

2 changes: 1 addition & 1 deletion src/AppBundle/Entity/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Entry extends AbstractEntity
private $id;

/**
* @ORM\Column(type="string", length=500)
* @ORM\Column(type="string", length=2048)
* @Assert\Url
*/
private $url;
Expand Down
2 changes: 1 addition & 1 deletion web/app_dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['192.168.179.1', '127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
Expand Down