Auto deployment packages(dar files) to Ledger Daml Hub

How to automate deploy packages(dar files) to existing project/ledger using API or another tools? Is it possible?

1 Like

Deploying a package is always an API call, so it is by definition amenable to automation.

Perhaps if you tell us a little bit more about your use-case we’ll be able to provide more guidance on exactly how to achieve that.

@Gary_Verhaegen
I created project and ledger inside project. And want to upload dar files to Deployments section for this ledger.


And after uploading files, I need also Deploy Instance.

How I can do it using API for my automation? Maybe you have guides or examples? It would be great help for me. Thanks.

Hi @Maksym_Zhovanyk,

Apologies, I missed the fact that you were asking about Hub. The story there is unfortunately a little bit more complicated at the moment, and I’m not entirely familiar with the details. I’ll leave it to a Hub team member to provide more explanations.

@Maksym_Zhovanyk

Hi, we have an early access alpha CLI tool for Daml Hub that may help here. Given its alpha status, we don’t make strong stability or maintenance guarantees at this point in time, and its interface (or the underlying APIs it uses) may be subject to change.

I realized the docs on the package homepage are rather sparse, so here is a guide particular to deploying a DAR package:

Installation

This is a NodeJS package, so installation is as simple as npm install -g damlhub-cli. This should create a damlhub executable in your PATH.

Authentication

To authenticate the CLI, you need an account token. To retrieve an account token, log into Daml Hub, navigate to your Account Settings (under your profile menu), and click on “Copy Account JWT”.

With the JWT in your clipboard, go back to a terminal and run damlhub token $PASTE_JWT_HERE.

One thing to note: the token is only valid for a 24 hour duration. Upon expiry, you will need to repeat the authentication process.

Usage

The CLI writes to stdout in JSON format, so commands can be piped to jq to pull information from response payloads.

Deploying a package to a ledger consists of multiple steps:

FILENAME="my-dar-0.0.1.dar"
LEDGER_ID="abcxyz"

# 1. Upload the file from disk to the Daml Hub Workspace
damlhub -j workspace upload $FILENAME

# 2. Install the file from the Workspace to a ledger with a specific ledger ID 
#    This makes the artifact available for deployment, and extracts the artifact hash
ARTIFACT_HASH=$(damlhub -j workspace install $FILENAME $LEDGER_ID | jq -r .artifact_hash)

# 3. Deploy the file onto the ledger via its `artifact_hash`
damlhub -j ledger deployDar $LEDGER_ID $ARTIFACT_HASH

Note also that DARs can not be removed from ledgers after they are deployed.

1 Like

@Alex_Matson
Thank you very much for help!))

Can we use this cli for deletion ledger/project for example? Use case: we have ledger → inside ledger we have deployment with dar file version 1 → can we update this deployment with dar file version 2? or we need create new deployment/instance and can not update existing?

Depends. If you are just developing, then I’d recommend deleting the ledger and starting over. This is also automatable via the CLI,

See

  • damlhub ledger --help
  • damlhub project --help

For the syntax

@Alex_Matson
thanks a lot. It is amazing tool for me!)

1 Like

Hi @Maksym_Zhovanyk welcome to the community :wave:t2: