Welcome to the codebase for BC's Housing Permit Portal
The codebase uses Rails on the back-end, and React/MST stack on the front-end.
Ensure you have the following:
- Ruby 3.2.2
- Postgres 13+
- Redis
- Node 20.10+
- Install Dependencies:
bundle installandnpm install - Ensure you have a
.envfile with required variables (reference.env.example) - Set up Database credentials following the official Rails guide. One of the ways is to have an environment variable called
DATABASE_URL - (Only first time) Create a database:
rails db:create - (Only first time or if there are changes) Run migrations:
rails db:migrate - (Only first time or if there are changes) Generate seed data:
rails db:seed - Start the server:
rails s - Start the front-end dev server for hot-reloading:
npm run dev
The app uses the Sidekiq library for background job processing. To run this locally:
- Ensure you have
Redisinstalled locally - Set ENV var
REDIS_URL=localhost:6379/0 - Run
bundle exec sidekiq(add a-q queue_name) to start that particular queue, you can see which queues are currently in the app inconfig/initializers/sidekiq.rbunderconfig.queues
- Note that the Openshift deployed versions make use of HA-Redis via Sentinels so the environment variables required for that are different
The app uses Anycable to serve websockets in a scalable way. To run the websocket server locally:
- Ensure to
bundle install - Download the
anycable-gowebsocket server on OSX:brew install anycable-go - Add an ENV var
ANYCABLE_REDIS_URL=redis://localhost:6379/2. It is recommended to set this value to a different Redis db than Sidekiq.
After installation run both the anycable-go websocket server as well as the RPC server
- RPC Server:
bundle exec anycable - Anycable-Go Sockets:
anycable-go --port=8080
- For local development, ensure you have the right test endpoint. The dev / test / production environments are set up with a licensed version running in its own container.
- For the local environment, if you want to test the full file upload process, you would want to run a local version of minio to simulate the object storage environment.
- Install minio:
brew install minio
minio server --address 127.0.0.1:9001 ~/Documents/whatever-your-folder-for-storage-is
- Log into minio with the admin/password provided and set up the environment.
- Set up a bucket (in our example we call it
hous-local)
- Set up a user (in our example, we call it
hous-formio-user)
- Set up a policy (in our example, we call it
formioupload)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListBucket",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::hous-local"
]
},
{
"Sid": "UploadFile",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListMultipartUploadParts",
"s3:PutObject",
"s3:AbortMultipartUpload",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::hous-local/*"
]
},
{
"Sid": "crossdomainAccess",
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::hous-local/crossdomain.xml"
]
}
]
}
-
note that "s3:PutObjectAcl" is ignored at the moment since we are at the root bucket, but we may need it later
-
You will need to add the following to your .env files:
BCGOV_OBJECT_STORAGE_ENDPOINT=http://127.0.0.1:9001(or_whatever_you want)
BCGOV_OBJECT_STORAGE_BUCKET=your-local-bucket-name
BCGOV_OBJECT_STORAGE_ACCESS_KEY_ID=your-local-user-access-key
BCGOV_OBJECT_STORAGE_SECRET_ACCESS_KEY=your-local-user-secret-access
BCGOV_OBJECT_STORAGE_REGION=us-east-1
Our folder structure for our bucket is designed as follows:
- :bucket_name/permit-applications/:id/*
The overall process of a file upload is as follow:
- The front-end form allows you to upload files
- Upon selecting files, it calls the backend to get a presigned url for upload
- The files are directly uploaded into the /cache/ folder
- Upon saving the file, it persists gainst the application as a 'supporting_document'
See the /devops folder for Dockerfiles and Helm-Charts
All unit tests should be run like the following:
bundle exec rspec
Some other notes
- For digital seal tests, the we have not uploaded documents with the real document to the repo, but captured the request responses
- To generate up to date erd diagrams, make sure you have graphiviz installed locally
bundle exec erd
