Using a virtual machine most of the software dependencies get installed automatically and it avoids installing a lot of software and services directly on the development machine.
Note: The provision scripts configure the sofware dependencies to play nice with each other while they are inside the same virtual development environment but this means that said configuration is not optimized for a production environment.
-
Install Vagrant and Virtual Box (with the extension package).
-
Retrieve the project from Git
git clone https://github.com/MakerNetwork/MakerNet.work.git
-
From the project directory, run:
vagrant up
-
Once the virtual machine finished building, reload it and log into it with:
vagrant reload vagrant ssh
-
While logged in, navigate to the project folder and install the Gemfile dependencies:
cd /vagrant bundle install -
Load
.envrcvalues as environment variables:source ~/.envrc
Be sure to check the information about setting up values for the configuration variables.
-
Set a directory for Sidekick pids:
mkdir -p tmp/pids
-
Set up the databases. (Note that you should provide the desired admin credentials and that these specific set of commands must be used to set up the database as some raw SQL instructions are included in the migrations):
# create database bundle exec rake db:create # apply migrations bundle exec rake db:migrate # include seed data ADMIN_EMAIL=youradminemail ADMIN_PASSWORD=youradminpassword bundle exec rake db:seed # build elasticsearch stats bundle exec rake fablab:es_build_stats
-
Start the application and visit
http://localhost:3000on your browser to check that it works:bundle exec foreman s -p 3000 -
Email notifications will be caught by MailCatcher. To see the emails sent by the platform, open your web browser at
http://localhost:1080to access the MailCatcher interface.
These are the recomended set of steps when making changes to the MaketNet codebase. Try to follow them as much as posible to facilitate the integration of features and fixes into the codebase.
-
Checkout the branch that will be the base for the changes. It is usually the
developmentbranch, but better ask the lead developer. -
Create a new branch prefixing it with
feature/for new features orfix/to work with bugs. Then, checkout your new branch. -
Start the following processes in different terminals from the
/vagrantdirectory of the virtual environment. (Don't forget to runsource ~/.envrc):bundle exec mailcatcher --foreground --ip=0.0.0.0bundle exec sidekiq -C ./config/sidekiq.ymlbundle exec rails s -b 0.0.0.0
-
Star coding! Remember the follwing:
- Check the application opening a browser at http://localhost:3000 (a private window is suggested).
- Check the emails opening a browser tab at http://localhost:1080
- You can stop the execution of the application at a certain point using the instruction
byebuginside the application code. Then, a session with the variables and at that point of the execution will be avaiable at the Rails terminal. Check the ByeBug docs to learn more. - Use TDD as much as posible.
-
When finished, rebase your branch with the most recent changes in its parent branch, push to your branch and issue a pull request to its parent branch.
The virtual machine can also emulate the production environment using Docker.
Note: Although Docker can be used alone on a developmen system, it is recomended to work with this virtual machine as the production environment applies optimizations in the host system that may not be suitable for everyday work systems.
-
Install Vagrant and Virtual Box (with the extension package).
-
Retrieve the project from Git
git clone https://github.com/MakerNetwork/MakerNet.work.git -
Open the
Vagrantfile with your editor and change the value to use the Docker provision scripts.USE_DOCKER_VERSION = true -
From the project directory, run:
vagrant up -
Once the virtual machine finished building, reload it and log into it with:
vagrant reload vagrant ssh
-
Login with your Docker credentials. (Note that you must be added as project collaborator over Docker Hub beforehand).
docker login -
Navigate to the project folder and pull the project images. Note: By default, the command will fetch the most recent build from the maser branch of the project. If using a different build is needed, edit the
makernet/docker-compose.ymlfile and add the desired tag to the image name.cd makernet docker-compose pull -
It is required to set the Rails and Devise secret in the env file, that can be done by running the following commands from the project folder:
# Generate a new secret string docker-compose run --rm makernet bundle exec rake secret # Copy the ouput value and place it in the env file sudo nano .env
-
Prepare the database. (Running the migrations manually is required):
# create the database docker-compose run --rm makernet bundle exec rake db:create # run all the migrations docker-compose run --rm makernet bundle exec rake db:migrate # seed the database: replace xxx with your default admin email/password docker-compose run --rm -e ADMIN_EMAIL=xxx -e ADMIN_PASSWORD=xxx makernet bundle exec rake db:seed
-
Build assets
docker-compose run --rm makernet bundle exec rake assets:precompile -
Prepare ElasticSearch
docker-compose run --rm makernet bundle exec rake fablab:es_build_stats
-
Start the application and visit
http://localhost:3000on your browser to check that it works:docker-compose up -d
- Set up email provider in the
envfile to receive email notifications:
SMTP_ADDRESS=<your provider server url>
SMTP_PORT=<usually port 587>
SMTP_USER_NAME=<service user>
SMTP_PASSWORD=<service password>Restart the application with docker-compose restart makernet
- Set the desired time zone in the virtual machine:
sudo dpkg-reconfigure tzdata
Then, edit the env file to set the same value in the TIME_ZONE variable and restart the
application with docker-compose restart makernet.
Check the list of commands that will help you manage the application containers.