Deployment

Local deployment is the fastest way to develop because the changes can be observed in real time instead of having to deploy changes to the server before seeing them. It also allows for the users changes to not affect the live application. Server deployment will make changes to the site live.

 

System Requirements

To develop locally the users machine will need the following programs

  1. Node and npm

    1. Download link: https://nodejs.org/en/download/  

  2. GIT with SSH key set up

    1. Download instructions: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git  

  3. A code editor (VScode, sublime, etc)

    1. VS code installation instructions: https://code.visualstudio.com/docs/setup/setup-overview

  4. An SSH client (Putty, etc) if using windows to access the server. Linux and Mac have built in SSH through the terminal.

Putty installation instructions: https://www.ssh.com/ssh/putty/windows/install

NOTE: Make sure to not update the react-leaflet or react-leaflet-google-maps libraries

 

LOCAL DEPLOYMENT

Once the above prerequisites have been met, please follow these steps sequentially.

  1. Open a new Terminal for Mac/Linux or Command Prompt for Windows

  2. Move to the desired folder

    1. cd /path/to/folder

    2. Where the path to the folder is your desired installation directory

  3. Clone this repository into that folder

    1. git clone https://github.com/precision-sustainable-ag/dst-selector

    2. Adding covercrops at the end causes it to be installed into a folder called covercrops in the home directory. If you don't put covercrops at the end, it will just install directly into the home directory, which won't work.

  4. Since this is a private repository, the user would be asked for their GitHub username and password. Once validated, the repository would be downloaded to the desired folder under the structure ~/covercrops/.

    1. You can also use a personal access token or a key instead of your password. GitHub authentication docs are listed here: https://medium.com/@amanze.ogbonna/accessing-pushing-to-github-without-username-and-password-3022feb077fb  

  5. From the Terminal/Command Prompt, move into the cloned directory

    1. cd ~/covercrops

  6. From the same command window, run the following to install project dependencies. A full list of the dependencies can be found in package.json. If you are running on a windows machine delete package-lock.json prior to running the below command.

    1. npm install

    2. You may run into some vulnerabilities. Run npm audit to see the full list of vulnerabilities. Run npm audit fix to automatically fix things that are possible. Others will be harder to run, may need some packages to be updated, and may require you to explore errors on the internet to figure out how to fix them.

  7. Create a file called .env in src/shared. The file will contain the below keys. This document is in the git ignore, so it (and your API keys) won't be pushed to the repository. Ask @Mikah Pinegar for the values of the keys

    REACT_APP_GOOGLE_API_KEY="<google key>" REACT_APP_OPEN_WEATHER_API_KEY="<open weather key>"
    1. REACT_APP_GOOGLE_API_KEY is used for google maps - there is one for the specific project. Ask Mikah or Juliet for it. Each developer does not need their own.

  8. After the dependencies have been installed and the .env file has been created, type the following to run the code locally:

    1. npm start

    2. Juliet’s Note: “I had trouble here with Node Sass. I rebuilt Node Sass to fix this issue:

      1. Error:  Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (88).”

      2. Fix: npm rebuild node-sass

    3. This will compile the JSX code into Javascript and open up a new browser window with the current version of the covercrops project! 

  9. There will be some warnings from js lint in the terminal about unused variables and functions, these can be ignored for now.

 

DOWNLOADING CHANGES

The above-mentioned are one-time installation instructions. Once the repository has new changes to be downloaded to an already cloned repository, follow these steps sequentially:

  1. Open up Terminal for Mac/Linux or Command Prompt for Windows

    1. cd path/to/covercrops

    2. git pull

    3. npm install if changes to package.json were made

    4. npm start

 

DEPLOYING TO A NEW SERVER

  1. Deploy your digital ocean droplet (The current server parameters are listed below but can be scaled up as needed) *Note operating system must be Linux because shell scripts are used

    1. Memory: 2GB

    2. 1vCPU

    3. Transfer: 2TB

    4. SSD Disk: 25GB

    5. Operating system: Ubuntu 18.04.3 (LTS) x64

    6. Public IP address 142.93.253.91

    7. Cost: $10/Month

  2. SSH into the root user of your droplet. You will be emailed a temporary password for the new droplet

  3. Update the droplet using sudo apt get update

  4. Install MongoDB, instructions for ubuntu can be found below https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-18-04-source

  5. Clone mongo airtable using into /root

  6. Update the .env file

  7. Copy create_json_files.sh and all the .mongo files into /root

  8. Clone covercrops repo onto the server using 

    1. mkdir /var/www/covercrop.tools/

    2. cd /var/www/covercrop.tools/

    3. git clone git@github.com:sudokita/covercrops.git covercrops

  9. ensure the newest data is on the droplet

    1. git pull

  10. Run create_json_files.sh to fetch the newest Airtable data and convert it into JSON format

    1. sudo -i

    2. cd /root

    3. sh ./create_json_files.sh

    4. This shell script is detailed further here

  11. Update the repository with the new Airtable data

    1. git push

  12. Point URL to your new droplets IP address

 

CONNECTING TO THE SERVER

  • Recommended way

  • Not recommended way

    • On a mac or Linux machine the user can run the following command 

      • ssh <username>@<server ip address> 

      • Enter password when prompted

    • On a PC the user will have to download an SSH client such as Putty and connect using that software.

    • Once connected the user will be able to navigate and run commands using the command line.