Skip to content

Latest commit

 

History

History
175 lines (124 loc) · 4.21 KB

HACKING.md

File metadata and controls

175 lines (124 loc) · 4.21 KB

Development Setup

To quickly make changes:

We have a docker-compose config that you can use to quickly spin up dev environment.

From the root of the repo, run:

$ docker-compose -d up

Logs from docker:

  • Logs from database and web server as they are generated:
$ docker-compose logs -f
  • from just webserver:
$ docker-compose logs -f mcaptcha

Setting up elaborate development environment

Toolchain

You'll have to install before you can start writing code.

  1. Install Rust: Install Cargo(Rust toolchain) using rustup with:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install Node v14.16.0: Please refer to official instructions

  2. Install yarn: npm install -g yarn For more details, refer to official instructions

  3. GNU Make: If you are on Linux, it's probably already installed on your machine.

You can check it's existence by running:

$ make --version

If it's not available, you download it with your package manager or refer to official instructions

External Dependencies:

mCaptcha currently implements support for the following database:

  1. Postgres
  2. mariadb(MySQL)

For development purposes, currently it is recommended to setup both databases as tests will break without it. In future, mechanisms will be implemented for working with select databases.

Postgres database:

I use Postgres in Docker.

  1. To install Docker, please refer to [official instructions](https://docs.docker.com/engine/install/].

  2. Create create database user:

$ docker create --name mcaptcha-postgres \
	-e POSTGRES_PASSWORD=password \
	-p 5432:5432    postgres
  1. Start database container:
$ docker start mcaptcha-postgres
  1. Set configurations:
cd mcaptcha # your copy of https://github.com/mCaptcha/mcaptcha
echo 'export POSTGRES_DATABASE_URL="postgres://postgres:password@localhost:5432/postgres"' >> .env

mariadb database

I use mariadb also in Docker

  1. To install Docker, please refer to [official instructions](https://docs.docker.com/engine/install/].

  2. Create create database user:

docker create \
	-p 3306:3306 \
	--name some-mariadb \
	--env MARIADB_USER=maria \
	--env MARIADB_PASSWORD=password \
	--env MARIADB_ROOT_PASSWORD=password \
	--env MARIADB_DATABASE=maria  \
	mariadb:latest
  1. Start database container:
docker start mcaptcha-mariadb
  1. Set configurations:
cd mcaptcha # your copy of https://github.com/mCaptcha/mcaptcha
echo 'export MARIA_DATABASE_URL="mysql://maria:password@localhost/maria"' >> .env

Database migrations

This step is only required when migrations are updated. The server binary has inbuilt migrations manager but that can only be used after the server is compiled. Since we are trying to compile the server here, we can't use that. However, this project ships with a utility to run migrations!

$ cd mcaptcha # your copy of https://github.com/mCaptcha/mcaptcha
make migrate

That's it, you are all set!

Build commands:

Compile:

$ cd mcaptcha # your copy of https://github.com/mCaptcha/mcaptcha
$ make

Additional commands:

➜  mcaptcha git:(master) ✗ make help
default                        Run app in debug mode
clean                          Delete build artifacts
coverage                       Generate code coverage report in HTML format
dev-env                        Setup development environment
doc                            Generate documentation
docker                         Build Docker image
docker-publish                 Build and publish Docker image
frontend                       Build frontend
frontend-test                  Run frontend tests
lint                           Lint codebase
migrate                        Run database migrations
release                        Build app with release optimizations
test                           Run all available tests
xml-test-coverage              Generate code coverage report in XML format
help                           Prints help for targets with comments