01 / 01Guide
Test and deploy Rell code with the Chromia CLI
This guide shows you how to write and run CI pipelines that use the Chromia CLI to test and deploy Rell code on the Chromia blockchain platform. The example pipeline file is split into stages for building, testing, and deploying, and each step is described below.
Defining base image
Start by choosing the base image your pipelines run on. The example uses the latest tag, but pinning a specific version is safer because it prevents unexpected changes between runs.
image: registry.gitlab.com/chromaway/core-tools/chromia-cli/chr:latestimage: registry.gitlab.com/chromaway/core-tools/chromia-cli/chr:latestBuilding the project
The build stage generates the blockchain configuration for every blockchain configured in your project and stores the results as artifacts.
This file also declares the build, test, and deploy stages, which the jobs defined later are assigned to.
stages: - build - test - deploybuild: stage: build script: - chr build artifacts: when: on_success paths: - build/*.xmlpipelines: default: - step: name: Build script: - chr build artifacts: - build/**Running tests
Unit tests need a Postgres service container. Use the Alpine variant of the image, because its collation settings match what is expected.
The database properties are set as global variables so the integration test job can reuse them.
variables: POSTGRES_DB: postchain POSTGRES_USER: postchain POSTGRES_PASSWORD: postchain CHR_DB_URL: jdbc:postgresql://postgres/postchaintest: stage: test services: - postgres:15-alpine script: chr test --test-report artifacts: when: always reports: junit: build/reports/*.xmlPostgres is declared in the definitions section and then attached to the pipeline as a service container.
definitions: services: postgres: image: "postgres:15-alpine" variables: POSTGRES_DB: postchain POSTGRES_USER: postchain POSTGRES_PASSWORD: postchainpipelines: default: - step: name: Test services: - postgres script: - export CHR_DB_URL=jdbc:postgresql://localhost:5432/postchain - chr test --test-report --test-report-dir build/test-reports artifacts: - build/test-reports/*.xmlThe integration test job first launches a test node in the background, then waits until messaging port 9870 is exposed before continuing. If you write your integration tests in TypeScript, Kotlin, or another language rather than shell, consider a framework such as Testcontainers to run the test node as a sidecar. For a TypeScript setup, see the integration testing guide.
integration-test: stage: test services: - postgres:15-alpine before_script: - chr node start & - while ! nc -z localhost 9870; do sleep 1; done; sleep 1 script: - chr tx --await set_name Alice - $([ "$(chr query hello_world)" = "\"Hello Alice!\"" ]) artifacts: when: on_failure paths: - logs/*.logpipelines: default: - step: name: Integration Test services: - postgres script: - chr node start & - while ! nc -z localhost 9870; do sleep 1; done; sleep 1 - chr tx --await set_name Alice - $([ "$(chr query hello_world)" = "\"Hello Alice!\"" ]) artifacts: - logs/**