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
Node and npm
Download link: https://nodejs.org/en/download/
GIT with SSH key set up
Download instructions: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
A code editor (VScode, sublime, etc)
VS code installation instructions: https://code.visualstudio.com/docs/setup/setup-overview
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.
Open a new Terminal for Mac/Linux or Command Prompt for Windows
Move to the desired folder
cd /path/to/folder
Where the path to the folder is your desired installation directory
Clone this repository into that folder
git clone https://github.com/precision-sustainable-ag/dst-selector
Adding
covercrops
at the end causes it to be installed into a folder calledcovercrops
in the home directory. If you don't putcovercrops
at the end, it will just install directly into the home directory, which won't work.
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/.
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
From the Terminal/Command Prompt, move into the cloned directory
cd ~/covercrops
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.
npm install
You may run into some vulnerabilities. Run
npm audit
to see the full list of vulnerabilities. Runnpm 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.
Create a file called
.env
insrc/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 keysREACT_APP_GOOGLE_API_KEY="<google key>" REACT_APP_OPEN_WEATHER_API_KEY="<open weather key>"
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.
Google maps API key docs: https://developers.google.com/maps/documentation/javascript/get-api-key
After the dependencies have been installed and the .env file has been created, type the following to run the code locally:
npm start
Juliet’s Note: “I had trouble here with Node Sass. I rebuilt Node Sass to fix this issue:
Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (88).”
Fix:
npm rebuild node-sass
This will compile the JSX code into Javascript and open up a new browser window with the current version of the covercrops project!
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:
Open up Terminal for Mac/Linux or Command Prompt for Windows
cd path/to/covercrops
git pull
npm install
if changes topackage.json
were madenpm start
DEPLOYING TO A NEW SERVER
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
Memory: 2GB
1vCPU
Transfer: 2TB
SSD Disk: 25GB
Operating system: Ubuntu 18.04.3 (LTS) x64
Public IP address 142.93.253.91
Cost: $10/Month
SSH into the root user of your droplet. You will be emailed a temporary password for the new droplet
Update the droplet using
sudo apt get update
Install MongoDB, instructions for ubuntu can be found below https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-18-04-source
Clone mongo airtable using into /root
Update the .env file
Copy create_json_files.sh and all the .mongo files into /root
Clone covercrops repo onto the server using
mkdir /var/www/covercrop.tools/
cd /var/www/covercrop.tools/
git clone git@github.com:sudokita/covercrops.git covercrops
ensure the newest data is on the droplet
git pull
Run create_json_files.sh to fetch the newest Airtable data and convert it into JSON format
sudo -i
cd /root
sh ./create_json_files.sh
This shell script is detailed further here
Update the repository with the new Airtable data
git push
Point URL to your new droplets IP address
CONNECTING TO THE SERVER
Recommended way
Use VS Code to open a remote connection to the server so you can view and edit files
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.