depl 2.4.3

Toolkit for a bunch of local and remote CI/CD actions
Documentation
# Content Examples

## `cargo-mold-linker`

This content contains `.cargo/config.toml` with `mold` linker for `x86_64-unknown-linux-gnu` target.

> [!NOTE]
> Usage of this content will rewrite your project's `.cargo/config.toml`!

To install this example to Deployer's content storage, run:

```bash
cd content-examples/cargo-mold-linker
depl add content -c . -p cargo-mold-linker@0.1.0
```

Then you can use it in your Rust projects like:

```bash
cd my-rust-project
depl use -o . cargo-mold-linker@   # `@` used to sync any latest version (by SemVer 2.0 definition)
```

And your Rust project will be linked by `mold` on `cargo build`.

Also, you can use the content by adding this action into your pipeline:

```yaml
info: use-cargo-mold-linker@0.1.0
action:
  type: use_from_storage
  content_info: cargo-mold-linker@latest
```

## `docker-fake-files`

This content contains fake Rust `lib.rs` and `main.rs` for generating Buildx cache while `docker/podman build`.

To install this example to Deployer's content storage, run:

```bash
cd content-examples/docker-fake-files
depl add content -c . -p docker-fake-files@0.1.0
```

So, when you have Rust project with 300-500+ dependencies, rebuilding project in Docker/Podman from scratch looks like hard work for your computer. Well, you can fix that by creating cache strategy:

1. Compile only your dependencies
2. Then compile your project with these dependencies.

And Rust allows you to create almost empty `main.rs`/`lib.rs` to compile dependencies. So, your cache strategy for Deployer will look like:

```yaml
cache_strategies:
  - fake_content: docker-fake-files@latest                # our content
    copy_cmds:
      - COPY .docker-fake-files/rust/lib.rs src/lib.rs    # if you have a library
      - COPY .docker-fake-files/rust/main.rs src/main.rs  # if you have a binary
      - COPY Cargo.toml .                                 # Docker/Podman will rebuild dependencies only on `Cargo.toml` changes
    pre_cache_cmds:
      - DEPL                                              # run pipeline to cache dependencies
  - copy_cmds:
      - COPY src/ src/                                    # then copy actual project sources
    pre_cache_cmds:
      - RUN touch src/lib.rs                              # don't forget to update timestamps on updated files!
      - RUN touch src/main.rs                             # otherwise, Docker/Podman will not notice any changes, and you'll got empty project!
```

This will significantly reduce the time it takes to rebuild the project in the container.

## `get-know-rust-package-version`

This content contains Python script to retrieve your Rust project's package version from `Cargo.toml`.

> [!NOTE]
> Script supports only `package.version` or `workspace.package.version` fields.

To install this example to Deployer's content storage, run:

```bash
cd content-examples/get-know-rust-package-version
depl add content -c . -p get-know-rust-package-version@0.2.0
```

Let assume that you building some kind of shared library or static binary or React component - such an artifact that you have to use in your other projects. So, when you uploading it to the content storage, Deployer should know the version of this artifact.

There's [`impulse-kit`](https://github.com/impulse-sw/impulse-kit) static server example:

```yaml
project_name: impulse-kit
version: 8
ignore_files:
  - .git
cache_files:
  - Cargo.lock
  - target
variables:
  empty:
    value:
      type: plain
      value: ""
  package-static-server:
    value:
      type: plain
      value: impulse-static-server  # name of Rust package inside workspace
  target-x86:
    value:
      type: plain
      value: x86_64-unknown-linux-gnu
actions:
  - info: add-static-server-to-storage@0.1.1
    action:
      type: add_to_storage
      short_name: static-server  # content's short name
      auto_version_rule:
        type: cmd_stdout
        cmd:
          cmd: python .depl/rust_crate_ver.py  # run this to get actual workspace version
          ignore_fails: true
          show_success_output: true
          show_cmd: false
          only_when_fresh: false
      content:
        type: fixed_files  # specifies what files should be added to storage
        placements:
          - from: target/x86_64-unknown-linux-gnu/release/iks  # path of compiled binary
            to: iks
          - from: impulse-static-server/static-server.yaml  # predefined config path
            to: static-server.yaml
  - info: cargo-release@0.2.0
    tags:
      - rust
      - cargo
    requirements:
      - type: in_path
        executable: cargo
        desc: "Install `cargo` via your package manager or with this command: `curl https://sh.rustup.rs -sSf | sh`."
    action:
      type: staged
      stage: build
      cmd: "{flags}cargo build --release --package {package} --target {target}{features}"
      placeholders:
        - "{flags}"
        - "{package}"
        - "{target}"
        - "{features}"
  - info: use-rust-package-version@0.2.0  # sync Python script to `.depl/rust_crate_ver.py`
    action:
      type: use_from_storage
      content_info: get-know-rust-package-version@latest
pipelines:
  - title: build-static-server
    info: impulse-kit-build-static-server@0.1.0
    artifacts:
      - from: target/x86_64-unknown-linux-gnu/release/iks
        to: static-server/iks
      - from: impulse-static-server/static-server.yaml
        to: static-server/static-server.yaml
    actions:
      - title: Sync script to know Rust package version
        used: use-rust-package-version@0.1.0
      - title: Build (release mode)
        used: cargo-release@0.2.0
        with:
          "{features}": empty
          "{flags}": empty
          "{package}": package-static-server
          "{target}": target-x86
      - title: Auto-upload Static Server to Deployer's Storage
        used: add-static-server-to-storage@0.1.0
```

And then you can use `impulse-static-server` like this:

```yaml
info: sync-static-server@0.1.0
action:
  type: use_from_storage
  content_info: static-server@latest
```

Or:

```bash
depl use -o . static-server@  # sync static server `iks` with config `static-server.yaml`
./iks                         # run static serevr
```