This repo serves these purposes:
- Sharing an instruction for the development environment setup.
- Enabling reproducible and easy deployments to staging and production environments.
- We leave the version unspecified for some dependencies (namely system dependencies, installed via
apt
). This is ok, but we should be explicit about doing this. - Git history records the past working versions on production. It helps us revert to old deployments in case of problems.
- We leave the version unspecified for some dependencies (namely system dependencies, installed via
- If your host OS is Windows, install WSL 2 and Linux. All below instructions are run in a Linux or Mac.
- Prepare your ssh key. To generate a new key, see here. If your host OS is Windows, copy your key(s) between the host Windows and the guest Linux.
- Set up your GitHub account with your SSH key.
- Install a node version manager, e.g. nvm.
- Below, if you're developing the vis only, skip database and api.
- First-time setup
- Database
- Option 1: docker
- Install docker.
- Dump the test data into MongoDB.
cd ccn-coverage-deploy/ docker compose run --rm \ -v "${PWD}/assets/dev/mongo-data-mock:/mongo-data-mock" \ mongo \ /mongo-data-mock/initialize.sh
- Option 2: mongo version manager
- There are several tools for this. Search online for the most up-to-date recommendations.
- Option 1: docker
- Api
cd your-development-dir/ git clone [email protected]:Local-Connectivity-Lab/ccn-coverage-api.git
- Vis
cd your-development-dir/ git clone [email protected]:Local-Connectivity-Lab/ccn-coverage-vis.git
- Database
- Bringup & Teardown
- Database
- Option 1: docker
- Bringup:
cd ccn-coverage-deploy/ docker compose up -d
- Teardown:
cd ccn-coverage-deploy/ docker compose down
- Bringup:
- Option 1: docker
- Api
- Bringup:
cd ccn-coverage-api/ nvm use npm start
- Teardown: Ctrl + c
- Bringup:
- Vis
- Bringup:
cd ccn-coverage-vis/ nvm use npm start # If you want vis to talk to your local api, specify the below environment variable. # REACT_APP__API_URL='http://localhost:3000' npm start
- Teardown: Ctrl + c
- Bringup:
- Database
Fist-time setup:
- Provision a compute instance on cloud.
- CPUs = 1
- Memory = 2GB
- Your local environment should be configured with an ssh key that authorizes you on GitHub and on the remote environment. In addition, every time you ssh into a remote environment (staging or production), you want to "forward" your local ssh key there. To do so:
- Edit your
~/.ssh/config
. Add these lines:Host *.seattlecommunitynetwork.org ForwardAgent yes
- Edit your shell configuration file:
~/.bashrc
on Linux or~/.zshrc
on Mac. Add these lines. (This may be optional, but is likely needed on a WSL Linux.)if [ -z "$SSH_AUTH_SOCK" ] ; then eval `ssh-agent -s` ssh-add fi
- Edit your
- Ansible depends on python. Install a python version manager, e.g. pyenv. Then, install a python runtime: e.g.
pyenv install 3.11
. - Install ansible (
pip install ansible
). - Copy Api's keys to here.
Do deploy:
- Back up data.
ssh <environment>.seattlecommunitynetwork.org
- At the remote environment:
cd /tmp/ rm -r ./dump.tgz ./dump/ mongodump tgz -zxf ./dump.tgz ./dump/
- Upload the dump.tgz to our Google Drive.
- At the remote environment:
rm -r /tmp/.dump.tgz /tmp/dump/
- Configure a target environment via Ansible.
cd ccn-coverage-deploy/ ansible-playbook -i ./environments/staging ./playbook.yaml
- Commit whatever changes you made to this
ccn-coverage-deploy
repo, and push it.