You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
4.2 KiB
206 lines
4.2 KiB
3 years ago
|
---
|
||
|
nav_order: 2
|
||
|
---
|
||
|
|
||
|
# Local development
|
||
3 years ago
|
|
||
|
The most common way to run a development version of the application is run with local dependencies.
|
||
|
|
||
|
Dependencies:
|
||
|
|
||
3 years ago
|
- [Ruby](https://www.ruby-lang.org/en/)
|
||
|
- [Rails](https://rubyonrails.org/)
|
||
|
- [PostgreSQL](https://www.postgresql.org/)
|
||
|
- [NodeJS](https://nodejs.org/en/)
|
||
3 years ago
|
- [Gecko driver](https://github.com/mozilla/geckodriver/releases) (for running Selenium tests)
|
||
3 years ago
|
|
||
3 years ago
|
We recommend using [RBenv](https://github.com/rbenv/rbenv) to manage Ruby versions.
|
||
3 years ago
|
|
||
|
1. Install PostgreSQL
|
||
|
|
||
3 years ago
|
macOS:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
brew install postgresql
|
||
|
brew services start postgresql
|
||
|
```
|
||
|
|
||
|
Linux (Debian):
|
||
|
|
||
|
```bash
|
||
|
sudo apt install -y postgresql postgresql-contrib libpq-dev
|
||
|
sudo systemctl start postgresql
|
||
|
```
|
||
3 years ago
|
|
||
|
2. Create a Postgres user
|
||
3 years ago
|
|
||
|
```bash
|
||
|
sudo su - postgres -c "createuser <username> -s -P"
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
3. Install RBenv and Ruby-build
|
||
3 years ago
|
|
||
3 years ago
|
macOS:
|
||
|
|
||
|
```bash
|
||
|
brew install rbenv
|
||
|
rbenv init
|
||
|
mkdir -p ~/.rbenv/plugins
|
||
|
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
|
||
|
```
|
||
|
|
||
|
Linux (Debian):
|
||
|
|
||
|
```bash
|
||
|
sudo apt install -y rbenv git
|
||
|
rbenv init
|
||
|
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
|
||
|
mkdir -p ~/.rbenv/plugins
|
||
|
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
|
||
|
```
|
||
|
|
||
|
4. Install Ruby and Bundler
|
||
|
|
||
|
```bash
|
||
|
rbenv install 3.1.2
|
||
|
rbenv global 3.1.2
|
||
|
source ~/.bashrc
|
||
|
gem install bundler
|
||
|
```
|
||
|
|
||
|
5. Install JavaScript dependencies
|
||
|
|
||
|
macOS:
|
||
|
|
||
|
```bash
|
||
|
brew install node
|
||
|
brew install yarn
|
||
|
```
|
||
|
|
||
|
Linux (Debian):
|
||
|
|
||
|
```bash
|
||
|
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
|
||
|
sudo apt -y install nodejs
|
||
|
mkdir -p ~/.npm-packages
|
||
|
npm config set prefix ~/.npm-packages
|
||
|
echo 'NPM_PACKAGES="~/.npm-packages"' >> ~/.bashrc
|
||
|
echo 'export PATH="$PATH:$NPM_PACKAGES/bin"' >> ~/.bashrc
|
||
|
source ~/.bashrc
|
||
|
npm install --location=global yarn
|
||
|
```
|
||
3 years ago
|
|
||
|
6. Clone the repo
|
||
|
|
||
3 years ago
|
```bash
|
||
|
git clone https://github.com/communitiesuk/submit-social-housing-lettings-and-sales-data.git
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
## Application setup
|
||
3 years ago
|
|
||
|
1. Copy the `.env.example` to `.env` and replace the database credentials with your local postgres user credentials.
|
||
|
|
||
3 years ago
|
2. Install the dependencies:
|
||
|
|
||
|
```bash
|
||
|
bundle install && yarn install
|
||
|
```
|
||
|
|
||
|
3. Create the database & run migrations:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
bundle exec rake db:create db:migrate
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
4. Seed the database if required:
|
||
|
|
||
|
```bash
|
||
|
bundle exec rake db:seed
|
||
|
```
|
||
3 years ago
|
|
||
|
5. Start the dev servers
|
||
|
|
||
3 years ago
|
a. Using Foreman:
|
||
|
|
||
|
```bash
|
||
|
./bin/dev
|
||
|
```
|
||
|
|
||
|
b. Individually:
|
||
3 years ago
|
|
||
3 years ago
|
Rails:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
bundle exec rails s
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
JavaScript (for hot reloading):
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
yarn build --mode=development --watch
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
If you’re not modifying front end assets you can bundle them as a one off task:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
yarn build --mode=development
|
||
|
```
|
||
|
|
||
|
Development mode will target the latest versions of Chrome, Firefox and Safari for transpilation while production mode will target older browsers.
|
||
|
|
||
|
The Rails server will start on <http://localhost:3000>.
|
||
3 years ago
|
|
||
3 years ago
|
6. Install Gecko Driver
|
||
|
|
||
3 years ago
|
Linux (Debian):
|
||
|
|
||
|
```bash
|
||
|
wget https://github.com/mozilla/geckodriver/releases/download/v0.31.0/geckodriver-v0.31.0-linux64.tar.gz
|
||
|
tar -xvzf geckodriver-v0.31.0-linux64.tar.gz
|
||
|
rm geckodriver-v0.31.0-linux64.tar.gz
|
||
|
chmod +x geckodriver
|
||
|
sudo mv geckodriver /usr/local/bin/
|
||
|
```
|
||
|
|
||
|
Running the test suite (front end assets need to be built or server needs to be running):
|
||
|
|
||
|
```bash
|
||
|
bundle exec rspec
|
||
|
```
|
||
|
|
||
|
## Using Docker
|
||
3 years ago
|
|
||
3 years ago
|
1. Build the image:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
docker-compose build
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
2. Run the database migrations:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
docker-compose run --rm app /bin/bash -c 'rake db:migrate'
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
3. Seed the database if required:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
docker-compose run --rm app /bin/bash -c 'rake db:seed'
|
||
|
```
|
||
3 years ago
|
|
||
3 years ago
|
4. To be able to debug with Pry run the app using:
|
||
3 years ago
|
|
||
3 years ago
|
```bash
|
||
|
docker-compose run --service-ports app
|
||
|
```
|
||
3 years ago
|
|
||
|
If this is not needed you can run `docker-compose up` as normal
|
||
|
|
||
|
The Rails server will start on <http://localhost:8080>.
|
||
3 years ago
|
|
||
|
5. To run the test suite in docker:
|
||
|
|
||
|
```bash
|
||
|
docker-compose run --rm app /bin/bash -c ' RAILS_ENV=test rspec'
|
||
|
```
|