Development - NatLabRockies/alfalfa GitHub Wiki
How to Set Up a Development Environment
Prerequisites
Alfalfa leverages containers for running code and thus has only a few prerequisites for development
Setting up
- Clone Alfalfa repository
git clone [email protected]:NREL/alfalfa.git - Enter the repository folder
cd alfalfa - Install Python dependencies
poetry install
How to Deploy Alfalfa for Development
Alfalfa has several configurations in which it can be run. These can be selected by using combinations of the docker-compose.yml files in the repo.
docker-compose.ymlis the base compose file needed for all alfalfa deploymentsdocker-compose.dev.ymladds auto reloading and rebuilding of worker and web containers on source code changesdocker-compose.historian.ymladds influxdb and grafana for recording timeseries data and plotting
Example compose commands
For documentation on docker compose command see here.
docker compose build
Build Alfalfa images for base compose file.
docker compose up -d
Run Alfalfa from base compose file. --build can be added to any up command to rebuild any changes, this insures that the images are up to date. -d runs the containers in detached mode.
docker compose down -v
Delete containers and associated volumes. Clears all databases, good for cleaning house every now and then.
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build
Run alfalfa with auto reloading and rebuilding of worker and web containers when source code is updated. --build will rebuild images before running.
How to Run Local Tests
Unit Tests
- Start services for Alfalfa
docker compose up -d mongo redis minio mc goaws - Run unit tests
poetry run pytest
Docker-based Simulation Tests
-
Run docker dev stack locally (in detached mode)
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build -d -
Run simulation tests
docker exec alfalfa_worker_1 bash -c "cd /alfalfa && pytest -m docker tests/jobs" -
Clean up stack
docker compose down
Integration Tests
- Run stack locally in detached mode
docker compose up --build -d - Run integration tests
poetry run pytest -m "integration" - Clean up stack
docker compose down
Release Instructions
- Release dependent projects as needed (e.g., alfalfa-client).
- Update version in
pyproject.toml,package.jsonand pointalfalfa-clientdependency inpyproject.tomlto point to releasedalfalfa-client - Create a PR with the release prep branch against
develop. - Update the change log. It is easiest to use GitHub's "Generate Release Notes" which is accessible on the Draft New Release Page. Add in a tag and target (to the release prep branch), then click on the "Generate Release Notes".
- Wait for tests to pass
- Merge to
develop - Create a tag on
developwith the formatvX.X.X - Create PR against
main. - Wait for tests and MERGE PR (squashing or rebasing will lead to strange behavior between
mainanddevelop) - After merge to
mainimages will automatically be released to Docker Hub under the following images. It is recommended to verify that these images are updated (which can take up to an hour).
- Release drafted release in Alfalfa repo
- Celebrate!