Corteza Server
Corteza server is the back-end of the Corteza ecosystem. The core logic is written in GO, using go-chi for the routing.
Communication between the Corteza server and web applications is done using the REST API and web sockets. Communication between back-end services (Corteza server and Corredor) is done using gRPC.
Non-binary data is handled by the store layer and stored inside a database — currently MySQL and PostgreSQL. We will add support for additional databases in the future.
Binary data is handled using minIO and stored either locally or on a supported cloud provider.
Development setup
Corteza server runs on GO 1.16. This guide assumes that your GO development environment is already set up on the correct version. |
Fork the Corteza server
Core contributors should skip this part. |
-
go to the https://github.com/cortezaproject/corteza-server repository
-
click on the Fork button in the top right corner and follow the instructions on the screen.
Clone the repository
-
open the CLI
-
navigate to your working folder
-
run the
git clone git@github.com:$YOUR_USERNAME_HERE/corteza-server.git
command
Refer to the repository if you wish to use an alternative method. |
Configure the environment
corteza-server
directory:-
run
cp .env.example .env
-
open the
.env
file using VIM, Nano, or any other editor and modify the configuration as you see fit
Setup data storage
If your work requires persistent storage, make sure that you’ve set up a supported database engine.
You can run the database either locally or inside a Docker container.
Make sure to change the DB_DSN=
.env
variable.
If your work does not require persistent storage (you will work solely using tests), you can skip this step, and the testing framework will use the in-memory SQLite server.
Make sure to remove the DB_DSN=
.env
variable.
Setup SMTP
For local development, you can use MailHog to log the emails sent from the server.
Run the make mailhog.up
command to start MailHog.
Alternatively, you can use an actual SMTP provider like Gmail or MailGun.
Make sure to change the SMTP_*=
.env
variables.
You can skip this part of your workflow does not require emails.
Make sure to remove the SMTP_*=
.env
variables.
Serve the web applications
Corteza server allows you to serve all of the Corteza web applications for cases where you need to quickly test something on a user interface.
Refer to the corteza-server/webapp/README.adoc
file for details on how to set it up.
Make sure you’ve properly set the Port 80 is not available on Windows. |
The authentication server uses the If the login screen doesn’t do anything when you try to login, check if the cookie has the correct domain set. |
Run the server
Run the make watch
command to start the server.
The server will automatically restart when changes to the code are detected.
The watcher can be a bit wonky at times. Manually restart the server if the changes are not getting picked up. |
Run the tests
-
test.integration
to run integration tests (test files inside/tests
) -
test.store
to run store tests (test files inside/store/tests
) -
test.all
to run all tests -
test.unit
to run unit tests -
test.pkg
to run test files for the/pkg
directory
All commands, but the |
Integration testing gotcha: To prevent your tests from interacting with your development database, you can define an integration test specific Store testing gotcha: The same test suite runs over all supported databases.
If you wish to test for a particular database, you must define the corresponding See the setup containerized database section if you wish to run your test databases in a container. |
Setup containerized database
MySQL
We usually use the Percona fork of the MySQL database.
export DOCKER_NAME=percona;
export ROOT_PWD=root;
export MYSQL_PORT=3306;
-
docker run --name $DOCKER_NAME -e MYSQL_ROOT_PASSWORD=$ROOT_PWD -d -p $MYSQL_PORT:3306 percona:8.0;
-
docker exec -it $DOCKER_NAME mysql -uroot -p$ROOT_PWD;
-
CREATE DATABASE corteza;
-
CREATE USER 'corteza'@'172.17.0.1' IDENTIFIED BY 'corteza';
-
GRANT ALL PRIVILEGES ON corteza.* TO 'corteza'@'172.17.0.1';
-
FLUSH PRIVILEGES;
DB_DSN
.env
variable:DB_DSN="corteza:corteza@tcp(localhost:$MYSQL_PORT)/corteza?collation=utf8mb4_general_ci"
PostgreSQL
We usually use the official PostgreSQL image.
export DOCKER_NAME=pgsql2;
export ROOT_PWD=root;
export PGSQL_PORT=5432;
-
docker run --name $DOCKER_NAME -e POSTGRES_PASSWORD=$ROOT_PWD -d -p $PGSQL_PORT:5432 postgres:13;
-
docker exec -it $DOCKER_NAME psql -U postgres;
-
CREATE DATABASE corteza;
-
CREATE USER corteza WITH PASSWORD 'corteza';
-
GRANT ALL PRIVILEGES ON DATABASE corteza TO corteza;
DB_DSN
.env
variable:DB_DSN="postgres://corteza:corteza@localhost:$PGSQL_PORT/corteza?sslmode=disable"
Setup procedure
The initial procedure is located in the root app
package which defines orchestration structures to configure, initialize, and start different parts of the system.
CLI commands run boot procedures from the first (setup) to the level required by the command. |
Setup procedure levels
Configures and initializes low-level components, structures required through the entire lifecycle. More notable components:
|
|||
Establishes a connection to the configured database. The post connection procedures run database migrations to conform the schema to the current version. |
|||
Initializes all of the services as well as RBAC, resource translations, and (if enabled) federation. |
|||
The provision step assures that the initial resources (users, roles, namespaces, …) are imported from the provision files. |
|||
All of the previously initialized and configured services are started/activated including their watchers. |