Daggerverse
Dagger.io recently annouced the release of a new feature, Dagger Function. I was curious and since this site uses dagger to build and publish via the dagger GO SDK, its time to update.
Background
I use hugo to create and generate content for this site. Dagger is used to automate the build and publish to cloudflare pages. In my first post, I briefly discribe how I migrate from my old setup from AWS to Cloudflare, if you are interested.
Options
There are few options to migrate to the new dagger function. First Daggerize my repository and do one of the below,
- install modules developed by the community, or
- develop your own modules, or
- a mixture of both
Use modules from daggerverse
I found these modules from daggerverse, hugo and
and cloudflare-pipeline module which
would fit my requirement. After tinkering with the hugo module, I did not find it fits my need. E.g. there was no
hugo server
command available. Secondly, it offers a sass
function, which I personally think its much better as a seperate module.
Develop local module
Since the hugo
module did not fit my requirement, I decide to convert my current pipeline code into a
dagger function. The conversion was quite straightforward, since the GO SDK did not change much. I’d just
use the dagger init --sdk go .
to bootstrap my repo with a dagger module and start moving my code into it.
This was my origin pipeline code
const HUGO_IMAGE string = "klakegg/hugo"
func Build(client *dagger.Client, dir *dagger.Directory) *dagger.Container {
return client.Container().
From(HUGO_IMAGE).
WithDirectory("/src", dir, dagger.ContainerWithDirectoryOpts{
Exclude: []string{"node_modules/", "ci/", ".git/"},
}).
WithWorkdir("/src").
WithExec([]string{})
}
and the new dagger function
const HUGO_IMAGE string = "klakegg/hugo"
func (m *Hugo) Build(dir *Directory, target string) *Directory {
return dag.Container().
From(HUGO_IMAGE).
WithDirectory("/src", dir).
WithWorkdir("/src").
WithExec([]string{}).
Directory(target)
}
And the command to build, from
dagger run go run ci/main.go
to
dagger call build --dir . --target ./public export --path ./public
At this point, I have a local module to run hugo command to generate the site content. Next,
I need to deploy the content into Cloudflare pages and I thought I would give the cloudflare-pipeline
module a go.
Install the module with the following command
dagger install github.com/fluent-ci-templates/cloudflare-pipeline@1531aa58a317ff183d775a221491be76382ec76e
and simply run
dagger -m cloudflare call pages-deploy --src . --api-token <cloudflare_api_token> \
--account-id <cloudflare_account_id> --directory ./public --project-name blog
Closing
Modules available on daggerverse makes it easy to search and use module that
fits your requirement but I think the one downside with my limited knowledge with this new approach is that
the module may be bloated or missing features that you might need. In my case, it was missing the server
command from hugo.
Note this post is build and publish with this new approach. In near future, I may seperate the local hugo module as a seperate repository in github which would allow me to reuse in our projects.