Examples
Examples
This section contains examples of how to use the Pipelines SDK.
Build the documentation site
This example shows how to build the documentation site for the Nosana SDK. Let's quickly go through it.
At the top the nosana.yml
file, we have the nosana
section. This is used to configure the pipeline itself. The description
is used to identify the pipeline in the Nosana network. The storage
is used to configure the backend storage service that will be used to store the data that is generated by the pipeline. For now only IPFS is supported.
In the global
section we have the image
that will be used to run the pipeline. For this pipeline we are using the node:16
image. Take notice that the whole URI is required, not just the image name. This pipeline will be triggered on the following branches: main
and develop
.
The jobs
section is used to configure the individual jobs that will be executed in the pipeline. The image
used for these jobs is already defined in the global
section, so there is no need to define it again. For this example there are two jobs, install
and generate
. The basic gist of it is that the install
job will install the dependencies, and the generate
job will generate the documentation site.
For illustration purposes the resources
🡪 artifact
pattern is shown to show how to use artifacts between jobs. This is not required for this pipeline, but it is a good example of how to use artifacts.
Last but not least, the artifacts
generated by the pipeline called dist
will be stored in storage to be used later for you purposes
# .nosana-ci.yml
nosana:
description: Build Nosana Documentation
storage: IPFS
global:
image: registry.hub.docker.com/library/node:16
# Git, trigger on these branches
trigger:
branch:
- main
- develop
# Environment variables
environment:
APP_ENV: production # comment here about this var
# Allow pipeline to stop if one job fails
allow_failure: true # default: false
jobs:
# Install dependencies
- name: install
commands:
- npm ci
artifacts: # artifact for the next job
- name: node_modules
path: ./node_modules/
# Lint and generate docs.
- name: generate
commands:
- npm run eslint
- npm run prettier
- npm run generate
resources: # artifact from previous job
- name: node_modules
path: ./node_modules/
artifacts: # artifact for deployment
- name: dist
path: ./dist/
Build Nosana Contract
This example shows how to build and test the Nosana contracts. We will be using the projectserum
image to run the pipeline.
Another example .nosana-ci.yml
file. In this case, it is used to build and test the Nosana contracts.
The nosana
section is used to configure the pipeline itself. The description
is used to identify the pipeline in the Nosana network. The storage
is used to configure the backend storage service that will be used to store the data that is generated by the pipeline. For now, only IPFS is supported.
In the global
section, we have the image
that will be used to run the pipeline. For this pipeline the projectserum/build:v0.25.0
image is used. Note that the whole URI is required, not just the image name. This pipeline will only be triggered on the main
branch. The allow_failure
option is set to true
to allow the pipeline to continue if one of the jobs fails. It's more important to have the pipeline run through all of the tests than to stop at the first failure.
The jobs
section is used to configure the individual jobs that will be executed in the pipeline. For this example, four jobs will be executed in the pipeline. There is an installation and build step, and a linting step and the rest of the jobs are used to test the contracts.
Here it is important to note that the resources
🡪 artifact
pattern is shown to show how to use artifacts between jobs. Here it is good to see how artifacts are available for different jobs.
For this pipeline it is not important to store an artifact, we are only interested in the test results.
# .nosana-ci.yml
nosana:
description: Build and Test Nosana Contracts
backend: IPFS
global:
image: registry.hub.docker.com/projectserum/build:v0.25.0
# Trigger pipeline on these branches:
trigger:
branch:
- main
# Allow pipeline to stop if one job fails
allow_failure: true # default: false
jobs:
- name: install_build
commands:
- npm ci
- anchor build
artifacts:
- name: anchor_target
path: ./target/
- name: node_modules
path: ./node_modules/
- name: npm_tests
commands:
- npm run eslint
- npm run prettier
- npm run check-types
resources:
- name: node_modules
path: ./node_modules/
- name: anchor_test
commands:
- solana-keygen new --no-bip39-passphrase
- anchor test --skip-build
resources:
- name: node_modules
path: ./node_modules/
- name: anchor_target
path: ./target/
- name: cargo_test
commands:
- cargo check --resources
- cargo test --release
- cargo clippy --release
resources:
- name: node_modules
path: ./node_modules/
- name: anchor_target
path: ./target/