Skip to content

Vagrant

Xalok Go Vagrant Local is the repository to create the virtual machine to Xalok go with all the required configuration defined by provision.

Project configuration

A common pipeline to generate local environments and releases will avoid issues in all future Xalok Go projects.

All custom project params must be defined in the file starbase.config.example.yml:

yaml
app_name: st4
app_source: "/var/www/sites/enabled/{{ app_name }}"
repo: "git@git.xalok.com:webflow/xalok-go-starbase.git"
version: develop
bundle: st4rbasebundle
static:
_parameters:
  database_name: "{{ app_name }}"
  cms_main_domain: "starbase.lo"
  cms_main_images_domain: "https://starbase.lo"
  s3_bucket: ""
  s3_bucket_thumbs: ""
  aws_region: ""
  aws_key: ""
  aws_secret_key: ""
  fastly_api_key: ""
  fastly_service_id: ""
  wf_tracking.nodejs.host: "0.0.0.0"
  wf_tracking.nodejs.url: "https://starbase.lo"
  wf_tracking.nodejs.port: "8091"
  lock_host: "0.0.0.0"
  lock_port: "9001"
  youtube_public_key: __YOUTUBE_PUBLIC_KEY__
  js_autocollect_translations: true
  customize_add_prefix_bundles: ''
  assets_base_url: ''
  kernel.logs_dir: '/var/log/xalok'
  ports_renderer: "8081"
  classora_active: false
  lock_binding_port: ''
  fos_elastica.index_name: st4
  wf_cms.templating.external_renderer.host: 127.0.0.1
  wf_cms.templating.external_renderer.port: 8081
  jw_platform_key_id: KYO9smw
  jw_platform_secret_access_key: 6VMp29387tycfv3p498ytvw34pg9y8vw3b5tmwn

It is required to set a environment variable, STARBASE_CONFIG_YML, before the vagrant commands:

Set the env var:

shell
$ STARBASE_CONFIG_YML=../starbase.config.example.yml <comando...>

To set the env var to all current shell:

shell
$ export STARBASE_CONFIG_YML=../starbase.config.example.yml

To set it permanently in Linux add the line export... in ~/.bashrc

IMPORTANT: From now it is assumed that the STARBASE_CONFIG_YML variable is defined.

Destroy a previous image

In vagrant directory simply execute:

shell
jbarco@saloc:~/xgo/vagrant$ vagrant destroy
==> default: Running action triggers before destroy ...
==> default: Running trigger...
    default: Running local script: umount_nfs.sh
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...

Configure new image

  1. Clone vagrant with provision branch:

    shell
    ~$ git clone https://git.xalok.com/vagrant/vagrant-local.git
    ...
    ~$ mv vagrant-local xgo # or another name
    ~$ cd xgo
    ~/xgo$ git checkout xv6-focal
    ...
    ~/xgo$ cd vagrant
    ~/xgo/vagrant$
  2. Create and configure virtual machine with default provisions:

    shell
    ~/xgo/vagrant$ vagrant up --provision-with services,file,shell,starbase

    Now the application is up and running.

  3. Maybe the file pemissions on git folders has changed (diffier from git repo), simpliy run inside vagrant:

    shell
    www-data@ubuntu-focal:/var/www/sites/enabled/st4/vendor/xalok-go/cobase$ git checkout .
  4. Maybe the redis-service is disabled, simply run inside vagrant:

    shell
    vagrant@ubuntu-focal:~$ sudo systemctl enable redis-server && sudo systemctl start redis-server
  5. If you use make dev probably you do not want to let the renderer service running by default, simply run inside vagrant:

    shell
    vagrant@ubuntu-focal:~$ sudo systemctl disable render_st4 && sudo systemctl stop render_st4

Update config file

To add/change some param in starbase_config, after add it to the file, it must be reloaded.

shell
~$ cat $STARBASE_CONFIG_YML | vagrant ssh -- 'cat - > /tmp/starbase_config.yml'

Development environment

Local environment

Project ip address is 10.253.253.5

Add the following lines to /etc/hosts:

shell
jbarco@saloc:~$ grep starb /etc/hosts
10.253.253.5 starbase.lo
10.253.253.5 admin.starbase.lo
10.253.253.5 www.starbase.lo

Codebase

Codebase is available in the host inside vagrant folder in the www folder.

Enter the virtual machine:

shell
~/xgo/vagrant$ vagrant ssh
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-99-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
New release '20.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Tue Mar  8 15:33:39 2022 from 10.0.2.2
vagrant@localhost:~$ sudo su - www-data
www-data@localhost:~$

The code is in /var/www/sites/enabled/st4:

shell
www-data@localhost:~$ cd /var/www/sites/enabled/st4/
www-data@localhost:/var/www/sites/enabled/st4$

Developer git account config

Configure developer git account:

shell
www-data@localhost:~$ git config --global user.email jbarco@hiberus.com
www-data@localhost:~$ git config --global user.name jbarco

Default user

admin / ..admin.

Watch

To see live changes in templates, scripts, etc disable the renderer:

shell
~$ sudo systemctl stop render_st4.service

To disable it permanently:

shell
~$ sudo systemctl disable render_st4.service

Activate watcher:

shell
www-data@localhost:/var/www/sites/enabled/st4/vendor/xalok-go/cobase$ make dev

Debug

Web requests

Xdebug is defined by default so no xdebug install and config is needed in the vagrant machine.

Xdebug listens to 10.253.253.1.

Add xdebug helper extension to the browser.

In PhpStorm:

  • Configure run/debug with PHP Remote Debug.
  • First time PhpStorm asks for listening new domains (admin.starbase.lo, starbase.lo).
  • File -> Settings -> PHP -> Servers:
    • admin.starbase.lo/starbase.lo:
      • 8080 port
      • Click on use path mappings:
        • /home/user/xgo/www/st4/vendor/xalok-go/cobase/src -> /var/www/sites/enabled/st4/vendor/xalok-go/cobase/src
        • /home/user/xgo/www/st4/vendor/xalok-go/cobase/vendor -> /var/www/sites/enabled/st4/vendor/xalok-go/cobase/vendor
        • /home/user/xgo/www/st4/vendor/xalok-go/cobase/web -> /var/www/sites/enabled/st4/vendor/xalok-go/cobase/web

CLI

By default vagrant disable debug of scripts, so reque, scheduler requests are not debugged.

To activate this debug:

shell
~$ sudo phpenmod -s cli xdebug

To disable it:

shell
~$ sudo phpdismod -s cli xdebug

To execute a command with debug:

shell
~$ SERVER_PORT=9000 \
   SERVER_NAME=10.253.253.1 \
   php -dxdebug.remote_autostart=On \
       ./app/admin/console wf:cms:wf-assets http://admin.clublv.lo