Development
Steps for new developers to get up and running with the Bend data-service
Dependencies
You will need Rust, NodeJS, and a number of other tools to develop properly on the data-service
- Rust stable
- NodeJS LTS
- For formatting, you'll need
rustfmt
rustup component add rustfmt
Setting up the database
- Install diesel for MySQL:
cargo install diesel_cli --no-default-features --features mysql
- Copy
example.env
to .env
and replace with PlanetScale database details - Run
diesel migration run
Seeding Data
Run scripts/seed_factors_and_categories.sql to initialize the following:
- Codat Factors
- MCC Factors
- UNSPSC Factors
- Bend categories
- Bend category to mcc mappings
Run scripts/seed_db.sql to initialize the following:
- a v0 privileged API key for local use
- default user accounts
- a Bend org with memberships for the users
- a simulation bank connection with 9 months of transaction history
Run the service
cargo run
Testing the Docker Image
Run docker run -d -p 8000:8000 --env-file .env [IMAGE ID]
to start the containerized api-service in a detached process.
Note that when targeting a PlanetScale database, the containerized service requires that ?ssl_mode=verify_identity&ssl_ca=/etc/ssl/certs/ca-certificates.crt
be appended to the DATABASE_URL to specify the Certificate Authority roots for the debian environment. (See DB Connectivity)
Publishing the Image
- Install Google Cloud SDK
- Ensure you have access to the Container Registrar service account in GCP IAM & Admin
- Run
gcloud auth login
using an account with access to the Container Registrar - Build the image
docker build . --tag tcmoore/bend-api-service
- Run
docker tag tcmoore/bend-api-service gcr.io/bend-330614/api-service
(You can find the project id here) - Run
docker push gcr.io/bend-330614/api-service
Once logged in, you can also use the publish.sh
script.
DB Connectivity
The data-service can be pointed at a remote PlanetScale database, or at a local MySQL server with a DATABASE_URL like mysql://root:@localhost:3306/bend
(see the example.env
file)
Tunneling to Local API Service
We use ngrok for the purpose of Local Tunneling, such as when testing the Brex integration
Example: ngrok http --region=us --hostname=bend.ngrok.io 8000
Troubleshooting & Notes
- Models use UUID v4 for primary keys
- Note that PlanetScale is a UX layer over Vitess, and inherits some limitations from Vitess. This imposes some restrictions on what MySQL features we use; for example, TRIGGERS are not supported. UUID ids therefore must be set at the application level.
- E0658 Unstable Errors during the Docker build probably indicate an outdated version of Rust in the Dockerfile
- version `GLIBC_2.29' not found when running the Docker image indicates a mismatched binary between the build container and the runner (both must use the same version of debian). This unexpected failure first occurred in June 2022 likely as a result of building from the latest cargo-chef image—it was resolved by updating the runner to debian bullseye