* update dagger init with package manager downloading stdlib Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * split mod get and update functions Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * write to package checksum to dagger.sum when installing/updating Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * encure checksums are valid when compiling input Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * remove references to github.com/tjovicic in docs 1010 and 1011 Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * refactor mod get command Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * update logic of moving dir when installing packages Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix linting errors Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * revert changes to 1010 docs Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * updating error log line in mod/get Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix ci tests when using vendoring Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * update alpha.dagger.io version to v0.1 Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix mod repo test Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * return error if package already installed Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * remove already installed packages when installing Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix issue when vendoring stdlib Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * update mod command with filelock while installing Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix linting errors Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix path of mod lock file Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> Co-authored-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> Signed-off-by: Sam Alba <sam.alba@gmail.com>
3.2 KiB
slug |
---|
/1010/dev-cue-package/ |
Develop a new CUE package for Dagger
This tutorial illustrates how to create new packages, manually distribute them among your applications and contribute to the Dagger stdlib packages.
Creating your package
Initializing project
Create an empty directory for your new Dagger project:
mkdir project
cd project
As described in the previous tutorials, initialize your Dagger project:
dagger init
That will create two directories: .dagger
and cue.mod
, where our package will reside:
.
├── cue.mod
│ ├── module.cue
│ ├── pkg
│ └── usr
├── .dagger
│ └── env
Writing the package
Now that you've initialized your project, it's time to write a simple package. Package name usually starts with a domain name (as in Go) followed by a descriptive name. In this example, we reuse the Cloud Run example and create a package from it.
mkdir -p cue.mod/pkg/github.com/username/gcpcloudrun
Let's write the package logic. It is basically what we've seen in the 106-cloudrun example:
touch cue.mod/pkg/github.com/username/gcpcloudrun/source.cue
Running the package
Now that you've successfully created a package let's run it in a new environment. Create a new test package using
our reusable gcpcloudrun
:
Run it:
dagger up -e staging
You should see a familiar output:
9:32AM ERR system | required input is missing input=run.src
9:32AM ERR system | required input is missing input=run.imageRef
9:32AM ERR system | required input is missing input=run.gcpConfig.region
9:32AM ERR system | required input is missing input=run.gcpConfig.project
9:32AM ERR system | required input is missing input=run.gcpConfig.serviceKey
9:32AM ERR system | required input is missing input=run.deploy.name
9:32AM FTL system | some required inputs are not set, please re-run with `--force` if you think it's a mistake missing=0s
Manually distributing packages
You've probably guessed this package isn't tied to just your project. You can easily copy/paste it into any number of different projects and use it as we've shown above.
mkdir -p /my-new-workspace/cue.mod/pkg/github.com/username/gcpcloudrun
cp ./cue.mod/pkg/github.com/username/gcpcloudrun/source.cue /new-workspace/cue.mod/pkg/github.com/username/gcpcloudrun
Contributing to Dagger stdlib
Our stdlib has many valuable packages that you can use. You've probably seen it when you've initialized your project:
.
├── cue.mod
│ ├── module.cue
│ ├── pkg
│ │ ├── alpha.dagger.io
│ │ └── .gitignore
│ └── usr
We are still a small community and are constantly looking for new contributors that will work with us to improve this fantastic project. If you feel like we are missing a package or want to improve an existing one, please start with our contributing docs and open a PR.