Dagger & Bun
Now that we are familiar with Dagger and have done an initial test, let’s try it with a Bun project!
Initialization
First, I’ll use this project, which is a small Node.js library:
Here’s the project link: https://github.com/Killian-Aidalinfo/lib-acl-json
Now, let’s initialize Dagger just like in the previous chapter:
Once the Dagger files are initialized, we’ll modify the package.json
file for Dagger.
Here’s my package.json
:
Remove the packageManager
section and add the runtime
field, specifying Bun.
For more details, refer to the official documentation: Dagger Bun Documentation.
We don’t need to specify a packageManager
since Bun uses its own package manager.
First Pipeline
Let’s start with a simple pipeline: install dependencies and run Bun’s unit tests.
The buildEnv
function installs the dependencies with bun install
, and the test
function uses this setup to execute the tests.
Let’s call the test
function:
Perfect! Everything worked smoothly. 😎
NPM Publish
Now, let’s see how to use an environment variable to publish our package to NPM.
First, generate a token on npmjs.com.
Add the token as an environment variable:
Now, modify the pipeline to publish the package:
Run the publish
function with the environment variable:
Result:
Check on NPM:
Great! Our package is successfully published to NPM. 🎉
As you can see, the publish
function calls build
to create the package, retrieves the output directory, generates an .npmrc
file with the token, and publishes the package with the specified version.
To use environment variables, use the syntax env:VARIABLE
. You can also use a file. For more information, check the official documentation: Use Secret Variables.
Conclusion
Now that we’ve seen how to integrate Bun, you can create pipelines with Dagger and Bun. 🚀
Next step: build and push a Docker image to a private registry!