Back-end code repository for the Saving Satoshi platform. You can find our front-end code repository here.
The contributor branching model is loosely inspired by git-flow. The main branch of this repository is develop, which contains the latest features and is used to spin up an ephemeral staging site, destroyed each day.
Workflow:
- Developer creates new features in a "feature" branch in their forked repository and opens a pull request against
develop. - Pull request is merged into
developby a maintainer and the staging site is instatiated for testing. - When the maintainers are ready to release a new set of features, the
developbranch is merged intomaster, which deploys the production site.
The staging site can also be spun-up and destroyed manually by running the CI workflow on the develop branch from the GitHub Actions admin.
This guide will help you set up this project for local development.
Ensure you have the following installed on your machine:
- Node.js
- yarn
- PostgreSQL (optional, can be provisioned via docker)
- Docker
Before setting up the project, you should have the base image for the REPL which includes all the dependencies for each programming language.
cd src/base_images- choose any of the language you want to build for, for example,
to build base image for
c++, cd intocppin the base_images directory and run the following command
docker build -t cpp-base .To build base image for javascript, cd into javascript in the base_images directory and run the following command
docker build -t js-base .To build base image for python, cd into python in the base_images directory and run the following command
docker build -t py-base .- Clone the code from this repository.
- Copy the
.env.examplefile to.env. - Build the project by running
yarn build - Run
make initto setup the database, run migration, copy necessary files and run the project for the first time. - Optional: Run the tests with
yarn test - Run
make runto start the server. - To stop the server, run
ctlr C, then runmake stop-depsto stop the database.
To execute the tests you need to have a postgres database running. Running the database in docker is highly recommended so the tests don't have access to other, unrelated data that may be in a local instance of postgres. If you followed the steps above, the dockerized postgres instance will already be set up. Simply run make start-deps to bring the database up.
- Run
yarn testto run the tests. The tests use theDATABASE_URLdefined in.env - Optional: take down the database with
make stop-deps
- Run
make start-depsto start the database. - Run
make runto start the project. - You can now access the project at
http://localhost:8000.
You can access the database using the DATABASE_URL credentials in the .env file for local development. You can use any DB client of your choice.
After pushing lesson content to master a chapter will remain disabled until a new feature flag is pushed. To unlock a new chapter you must push a feature flag request to the api with the chapter number specified. Here is the necessary scaffold to unlock the next chapter.
curl --location --request PUT '${backend.api}/v1/features/' \
--header 'Origin: http://localhost:3000/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ${token}' \
--data '{
"feature_name": "chapter_#_enabled",
"feature_value": 1
}'You can find our Postman workspace here.
The entire deployment process is automated using Terraform (terraform/) and Ansible (ansible/). The corresponding GitHub workflow is .github/workflows/deploy.yml.
To resize an instance in production, update the AWS_EC2_INSTANCE_TYPE variable (Settings > Secrets and variables > Actions > toggle Variables tab) and rerun the Deploy workflow in GitHub Actions.