An example app in Rust for CircleCI's Dynamic Config demo

Overview

circleci-dynamic-config-example

An example app in Rust for CircleCI's dynamic config demo.

Dynamic config allows you to dynamically generate CircleCI's config depending on dynamic conditions.

This is useful especially for monorepos because you don't want to trigger all CircleCI workflows on every push.

About the example app

This is a client-server application in Rust.

The client code is also written in Rust and it generates WebAssembly files.

Here is the code structure:

Screen Shot 2022-10-05 at 14 30 11

Both client and server directories depends on the Rust library in shared directory.

Therefore we want to trigger CircleCI wofkflows under the following conditions:

  • Trigger client job when a new commit is pushed in client directory
  • Trigger server job when a new commit is pushed in server directory
  • Trigger all jobs when a new commit is pushed in shared directory

Setup

First of all, you need to enable dynamic config in CircleCI's project setting.

Go to [Project Settings] > [Advanced] and turn on Enable dynamic config using setup workflows.

Screen Shot 2022-10-05 at 14 34 02

You have to use CircleCI version 2.1 at the top of your .circleci/config.yml file.

version: 2.1

Also you need to add following lines in .circleci/config.yml to use dynamic config for the workflow.

setup: true

Configuration

For the monorepo use case, we have a path-filtering orb already available.

In order to use the orb, add the orbs stanza below your version.

orbs:
  path-filtering: circleci/[email protected]

Then you can map the updated files and directory to pipeline parameters

workflows:
  always-run:
    jobs:
      - path-filtering/filter:
          name: check-updated-files
          mapping: |
            client/.* run-build-client-job true
            server/.* run-build-server-job true
            shared/.* run-build-shared-job true
          base-revision: main
          config-path: .circleci/continue_config.yml

Note that the file specified in config-path is the dynamic config conditionally triggered. Then you can create .circleci/continue_config.yml and map the parameters like below

parameters:
  run-build-client-job:
    type: boolean
    default: false
  run-build-server-job:
    type: boolean
    default: false
  run-build-shared-job:
    type: boolean
    default: false

Finally you can declare workflows based on the conditions of the parameters.

workflows:
  client:
    when:
      or:
        [
          << pipeline.parameters.run-build-client-job >>,
          << pipeline.parameters.run-build-shared-job >>,
        ]
    jobs:
      - rust/lint-test-build:
          with_cache: false
          release: true
          version: 1.64.0
          working_directory: client
  server:
    when:
      or:
        [
          << pipeline.parameters.run-build-server-job >>,
          << pipeline.parameters.run-build-shared-job >>,
        ]
    jobs:
      - rust/lint-test-build:
          with_cache: false
          release: true
          version: 1.64.0
          working_directory: server
  shared:
    when: << pipeline.parameters.run-build-shared-job >>
    jobs:
      - rust/lint-test-build:
          with_cache: false
          release: true
          version: 1.64.0
          working_directory: shared

See .circleci directory for the complete example.

Trigger pipelines

You can add a file under server and push the commit.

$ cd server
$ touch test
$ git add test
$ git commit -m "feat: add test file to server"
$ git push

You can see only the server workflow is triggered.

Screen Shot 2022-10-05 at 14 48 27

You can also try adding a file under shared and push the commit.

$ cd shared
$ touch test
$ git add test
$ git commit -m "feat: add test file to shared"
$ git push

This time you can see all server, client and shared workflows are triggered.

Screen Shot 2022-10-05 at 14 48 37

Play

All Rust/Cargo command are wrapped by npm so please install npm packages first.

$ npm install

Then you can simply start server.

$ npm start

Open localhost:8080 you can test functions on both Server and Web Assembly

Screen Shot 2022-10-05 at 14 42 39

You might also like...
An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)
An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)

Rocket Tracing Fairing Example This repository aims to give a short example of how you can add a Fairing to your Rocket for tracing and how to use it

The point of this anchor project is to serve as a starter kit or example to compose with mango-v3 using anchor.

The point of this anchor project is to serve as a starter kit or example to compose with mango-v3 using anchor. It currently provides 2 examples and various inline todos on how to extend this.

A shared document application akin to Google Docs. Example usage of wasm-peers library.

Live Document Proof of concept application showcasing the usability of wasm-peers crate for easy and costless peer-2-peer WebRTC communication. It's a

🦀 Small Tauri SolidJS Example feat. Vite
🦀 Small Tauri SolidJS Example feat. Vite

Tauri Solid Example (2022) Simple Solid(vite) starter running with Tauri. Should hopefully save some time trying to setup Tauri and Solid. Currently c

Tauri and Leptos example.

tauri-leptos-example Tauri Leptos Requires Rust Nightly. See Leptos nightly Note. # Install Tauri CLI cargo install tauri-cli # Build and develop for

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.
Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

How to use libtor in a Rust app

libtor example Uses libtor crate to run a Tor daemon in process. This example spawns the Tor daemon using Tokio's spawn_blocking, and then spawns othe

Reload Rust code without app restarts. For faster feedback cycles.
Reload Rust code without app restarts. For faster feedback cycles.

hot-lib-reloader hot-lib-reloader is a development tool that allows you to reload functions of a running Rust program. This allows to do "live program

A Rust library that implements the main lightning logic of the lipa wallet app.

lipa-lightning-lib (3L) Warning This library is not production ready yet. Build Test Start Nigiri Bitcoin: nigiri start --ln The --ln flag is not stri

Owner
yujiosaka
I'm currently leading international development teams in Appier. I do frontend, backend, mobile development, DevOps and MLOps as well as team management.
yujiosaka
For when you really, really just want to know that your config changed

really-notify This crate is for when you really, really just want to know that your config changed. K8s configmap symlink shenanigans? No problem. Mul

Max Bruce 13 Jun 20, 2023
A dynamic binary tracing tool

Backlight Backlight is a dynamic binary tracing tool. Install $ git clone [email protected]:JoshMcguigan/backlight.git $ cd backlight $ cargo install-b

Josh Mcguigan 42 Dec 3, 2022
A dynamic image generator.

dynimgen A dynamic image generator. How to use step 1: The designers export the design drawing as an svg file <svg> <rect /> <image src="img.png"

null 29 Jun 14, 2023
Demo Terraform Provider in Rust

terraform-provider-helloworld Welcome to a large pile of hacks masquerading as a PoC. This repository proves that it's possible to write a Terraform P

Tom Parker-Shemilt 25 Sep 15, 2022
Demo for Arduboy written in rust

arduboy-hello-rs Install Install Rust with rustup https://www.rust-lang.org/en-US/install.html Install Arduino IDE https://www.arduino.cc/en/Main/Soft

Itoh Shimon 21 Jul 21, 2022
Demo Rust / VueJS+element-plus

rust-vue-demo This project demonstrates the integration of npm/vue into a rust axum web-service. The web-service is self-contained, embedding the webu

Frank Rehberger 11 Dec 26, 2022
This is a small demo to accompany the Tauri + Yew tutorial

Tauri + Yew Demo This is a small demo to accompany the Tauri + Yew tutorial

Steve Pryde 94 Jan 2, 2023
Demo provider, source code for the Provider tutorial.

Fiberplane "Catnip" (tutorial) provider This repository contains the final code of the provider built within the "Create a Provider" tutorial. It reli

Fiberplane 4 Feb 15, 2023
Example of executing ES module exports from Rust

rusty_esm This is an example showcasing a common use case for embedding Deno - calling JS module exports from Rust. The rest is pretty self explainato

Divy Srivastava 9 Dec 13, 2022
A working example of multi targets compilation for Rust using Github Actions.

A working example of multi targets compilation for Rust using Github Actions. Supports Windows, MacOSX, x86_64, ARM and Raspberry PI Linux.

Nicolas Vanhoren 41 Dec 17, 2022