2020-03-15 18:31:46 +00:00
# Development
2020-11-20 22:16:27 +00:00
Install instructions in [[INSTALL.md]]. Read it before proceeding.
2020-03-18 19:11:10 +00:00
2020-04-11 12:44:57 +00:00
## Basic commands for development
2020-03-15 18:31:46 +00:00
2020-11-20 22:16:27 +00:00
Load environment variables (**don't skip this step**):
2020-04-05 02:58:41 +00:00
2020-11-20 22:16:27 +00:00
source script/env.sh .env .env.development .env.local .env.development.local
2020-04-05 02:58:41 +00:00
2020-11-14 08:09:59 +00:00
Start development:
2020-03-31 18:46:49 +00:00
2020-11-14 08:09:59 +00:00
docker-compose up --build development
2020-03-31 18:46:49 +00:00
Build or rebuild:
2020-03-28 20:39:41 +00:00
2020-11-20 22:16:27 +00:00
docker-compose build
2020-03-25 23:34:52 +00:00
2020-03-31 18:46:49 +00:00
Debug:
2020-04-08 19:25:24 +00:00
docker attach ensl_development
2020-03-31 18:46:49 +00:00
2020-03-22 17:44:09 +00:00
To get inside docker web+test containers:
2020-03-23 03:24:44 +00:00
2020-11-20 22:16:27 +00:00
docker-compose exec -u root development /bin/bash
docker-compose exec -u web development /bin/bash
docker-compose exec -u root test /bin/bash
docker-compose exec -u web test /bin/bash
2020-03-23 03:24:44 +00:00
2020-03-22 17:44:09 +00:00
Restart the web container
2020-03-23 03:24:44 +00:00
2020-04-06 00:31:05 +00:00
docker-compose restart web`
2020-03-23 03:24:44 +00:00
2020-03-22 17:44:09 +00:00
Run some tests:
2020-03-23 03:24:44 +00:00
2020-11-14 08:09:59 +00:00
docker-compose up --build test
2020-11-20 22:16:27 +00:00
docker-compose exec -u web test bundle exec rspec
docker-compose exec -u web test bundle exec rspec spec/controllers/shoutmsgs_controller_spec.rb
2020-04-05 02:58:41 +00:00
2020-11-15 02:58:28 +00:00
## Debugging
Enable debug:
1. For tests, Make sure ``require 'pry-byebug'`` is uncommented at spec_helper.rb
1. Uncomment add `byebug` anywhere
2020-11-20 22:16:27 +00:00
1. The development console, test command etc. will stop with pry debug options
2020-11-15 02:58:28 +00:00
2020-11-14 08:09:59 +00:00
## Unresolved issues for development
2020-04-10 16:57:08 +00:00
There are some unresolved issues to setup dev env.
2020-04-11 13:40:38 +00:00
1. Make sure docker has access to its dirs. You might have to chown if you have permission issues with docker.
sudo chown -R 1000:1000 .
sudo chown -R 999:999 db/data
2020-11-20 22:16:27 +00:00
1. You might have to run db migrations manually.
2020-05-03 10:16:02 +00:00
bundle exec rake db:migrate`
2020-04-10 16:57:08 +00:00
2020-11-20 22:16:27 +00:00
## Unresolved issues in production
1. Be careful when running docker from multiple directories that you do not start eg. database twice
## Development tips
2020-04-08 19:25:24 +00:00
2020-05-02 13:04:21 +00:00
1. If you need to run stuff on your host (eg. ruby, rubocop, bundle install etc) run all commands from the: `Dockerfile` . It should setup identical setup for your machine.
2020-04-08 19:25:24 +00:00
1. Add docker container names to /etc/hosts. This makes it possible to run test from local machine without using the container since editor/IDE don't integrate with Docker so well.
sudo echo `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ensl_dev_db` db >> /etc/hosts
1. VS Code and RubyMine are great IDE's/editors.
1. To run VS Code plugin Ruby Test Explorer in docker container you need to create path to custom path, copy the formatter and it whines about and it [still fails a bit ](https://github.com/connorshea/vscode-ruby-test-adapter/issues/21 ).
2020-04-11 12:44:57 +00:00
1. You can run tests easier if you setup the stuff on your own computer.
2020-04-08 19:25:24 +00:00
1. Do not commit too much without testing. Also keep commits small for documentation and reversability issues.
1. You need to rebuild the docker image when you change gems.
2020-04-11 22:14:19 +00:00
1. To restart PUMA
touch tmp/restart.txt
2020-04-08 19:25:24 +00:00
## Design of ENSL Application
2020-04-05 02:58:41 +00:00
Read this to understand design decisions and follow them!
1. Env variables should be used everywhere and loaded from .env* files using Dotenv
2020-04-11 12:44:57 +00:00
* Load order is in [here]|(https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)
2020-11-20 22:16:27 +00:00
* Local changes go to .env*local and **not** .env (unlike previous versions)
2020-04-11 12:44:57 +00:00
* Passwords are in ENV variables for now so they don't have to duplicated between DB and Rails.
2020-04-08 19:25:24 +00:00
1. Everything should be running on containers.
2020-04-11 12:44:57 +00:00
* Docker-compose is the heart of deployment
* Dockerfile should contain the gems and prebuilt assets for production
2020-04-12 11:28:35 +00:00
* The app is mounted as **volume** . It will override the Dockerfile content.
* The app is only put inside the Dockerfile to precompile assets for production and staging. It could be removed to reduce space.
* For production or staging could have the content in either image or as a volume. Doesn't really matter.
2020-04-11 12:44:57 +00:00
1. The public directory contains everything public. NGINX will try to find files there and ask from PUMA if it doesn't.
* The local public directories (images, files, icons, avatars etc.) are to be addeed to .gitignore
2020-11-14 08:09:59 +00:00
* Assets are compiled on-fly in development mode.
2020-04-11 12:44:57 +00:00
* In production/staging etc. assets are precompiled and stored. Entry script can do this.
2020-04-12 11:28:35 +00:00
* The public folder is a mix of auto-generated data (assets), static data (images) and user-generated data (avatars/files etc.).
2020-11-14 08:09:59 +00:00
* No app folder in repo outside public is supposed to be shared by webserver.
2020-04-18 04:39:36 +00:00
1. Do not comment out tests that are taken out of use temporarily but use **skip**
2020-04-08 19:25:24 +00:00
## Tags in code
2020-11-15 02:58:28 +00:00
* ``FIXME`` bugs or bad coding that need to fixed one day
* ``TODO`` for things that are left undone
* ``EXPLAIN`` please explain what the following code does
* ``OBSOLETE`` remove this at some point
* ``DEBUG`` uncomment following lines to enable debug
2020-04-08 19:25:24 +00:00
2020-11-20 22:16:27 +00:00
## Assets and state data
1. Currently the following state data exists:
* `log` has all Rails and Rails submodule log files
* `db/data` has SQL database
* `tmp` has temporary data like sockets, pids, cache etc. not in git repo index
* `public` has all public data on website like images etc.
* `public/local` has avatars etc. user uploaded content and is not in git repo index
* `public/assets` is auto-generated by Rails on precompile and is not in git repo index
* `public/files` is stored elsewhere and aliased by nginx, also not in git repo index
2020-04-08 19:25:24 +00:00
## TODO issues for dev
1. Puma should be running (eg. spring), and if debugger is used it should be able to connect via docker-compose up
1. Should directories exist?
1. docker-compose has some .env specific vars and then
2020-04-11 12:53:52 +00:00
1. The env variables are not always loaded causing mysterious issues.
1. How much in env vars?
2020-04-05 02:58:41 +00:00
## Best practices
2020-04-08 19:25:24 +00:00
Take a look at these before writing anything.
2020-04-05 02:58:41 +00:00
1. https://nvie.com/posts/a-successful-git-branching-model/
2020-04-08 19:25:24 +00:00
1. https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
2020-04-05 02:58:41 +00:00
1. https://github.com/rubocop-hq/ruby-style-guide
1. https://rails-bestpractices.com/
1. http://www.betterspecs.org/
1. https://github.com/rubocop-hq/rspec-style-guide
1. Run rubocop