Skip to content

Latest commit

 

History

History
106 lines (70 loc) · 4.54 KB

File metadata and controls

106 lines (70 loc) · 4.54 KB

Saving Satoshi Backend

Back-end code repository for the Saving Satoshi platform. You can find our front-end code repository here.

Contributing

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:

  1. Developer creates new features in a "feature" branch in their forked repository and opens a pull request against develop.
  2. Pull request is merged into develop by a maintainer and the staging site is instatiated for testing.
  3. When the maintainers are ready to release a new set of features, the develop branch is merged into master, 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.

Local development setup

This guide will help you set up this project for local development.

Prerequisites

Ensure you have the following installed on your machine:

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 into cpp in 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 .

Initial setup

  1. Clone the code from this repository.
  2. Copy the .env.example file to .env.
  3. Build the project by running yarn build
  4. Run make init to setup the database, run migration, copy necessary files and run the project for the first time.
  5. Optional: Run the tests with yarn test
  6. Run make run to start the server.
  7. To stop the server, run ctlr C, then run make stop-deps to stop the database.

Local development: running tests

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.

  1. Run yarn test to run the tests. The tests use the DATABASE_URL defined in .env
  2. Optional: take down the database with make stop-deps

Running the Project after initial setup

  1. Run make start-deps to start the database.
  2. Run make run to start the project.
  3. You can now access the project at http://localhost:8000.

Accessing the Database

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.

Releasing a New Chapter

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
}'

Postman

You can find our Postman workspace here.

Deployment Process

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.