Skip to main content

Quickstart

Daggerize a project

So far, you've learned the basics of calling Dagger Functions. The next step is to use them in the context of your software project.

Here are the basic steps to Daggerizing an existing project:

  1. Initialize a new Dagger module with dagger init
  2. Install other useful Dagger modules from the Daggerverse as dependencies with dagger install
  3. Call useful Dagger Functions with dagger call
  4. Add useful dagger call commands to existing scripts and CI configuration

Try these steps by Daggerizing an example project - a simple "Hello world" application from the official Go example repository.

Fetch the project repository

Fetch a copy of the project repository:

git clone https://github.com/golang/example
cd example

Initialize a Dagger module

Initialize a Dagger module at the root of the repository:

dagger init

You should see a new file at the root of your repository, named dagger.json. View its contents:

cat dagger.json

You should see the following:

{
"name": "example",
"engineVersion": "v0.11.1"
}
note

By default, the module name is derived from the name of the directory in which it is initialized. To use a different name, add the --name argument to the dagger init call - for example, dagger init --name=my-module.

Finally, commit the file to your repository:

git add dagger.json
git commit -m 'dagger init'

Install a dependency

Now that your project has a Dagger module, you can install other modules into it, as dependencies. A dependency is just a Dagger module installed into another. Since the project is a Go project, install the Go builder module from earlier as a dependency:

dagger install github.com/kpenfound/dagger-modules/golang@v0.1.8

Once the command completes, look at the dagger.json file again. You should see that a new dependency has been added, similar to that shown below:

{
"name": "example",
"dependencies": [
{
"name": "golang",
"source": "github.com/kpenfound/dagger-modules/golang@8d662e001caf8c16253226d0d456f2f0f374f009"
}
],
"engineVersion": "v0.11.1"
}
note

The exact Git commit for the module version is recorded in dagger.json. Dagger enforces "version pinning", which guarantees that the module version you install is the one you'll be using.

Go ahead and commit this change as well:

git add dagger.json
git commit -m 'Added Go builder module'

Then, call the BuildContainer() function from the Go builder module to build the project and publish a container image with the built binary:

dagger -m golang call \
build-container --source=. --args="-C","./hello" \
publish --address=ttl.sh/my-hello-container-$RANDOM

Once the container image is built, you should see the address at which it was published, as in the example below:

ttl.sh/my-hello-container-20124@sha256:15eb8379e1ab6f6746ccbcbf531aef23882381c29a8d09a8682fafa7b1adf467

Test the published container image using the command below (remember to update the image name based on the function output):

docker run \
--name ctr \
--rm \
-it ttl.sh/my-hello-container-20124 /usr/local/bin/hello

You should see the following output:

Hello, world!

Your project is slowly becoming more and more Daggerized...you're now able to build it, containerize it and publish it, all with a single Dagger Function call. If you like, you can integrate this call into your existing shell scripts, or perhaps a Makefile. Or, you can create a custom Dagger module, which enables you to connect one or more Dagger Functions together in portable, expressive workflows with all the benefits of a native programming language.