This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/docs/learn/1011-package-manager.md
Tihomir Jovicic a6a6037d01 rename dagger.mod.cue to dagger.mod and remove the need for module name
Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com>
2021-08-24 10:16:29 +02:00

2.3 KiB

slug
/1011/package-manager/

Manage packages using the package manager

This tutorial illustrates how to install and upgrade packages using Dagger package manager.

Installing a package

Initializing workspace

Create an empty directory for your new Dagger workspace:

mkdir workspace
cd workspace

As described in the previous tutorials, initialize your Dagger workspace:

dagger init
dagger new test

That will create 2 directories: .dagger and cue.mod where our package will reside:

.
├── cue.mod
│   ├── module.cue
│   ├── pkg
│   └── usr
├── .dagger
│   └── env
│       └── test

Install

In our example we will use gcpcloudrun module from github Let's first add it to our source.cue file:

package main

import (
  "github.com/tjovicic/dagger-modules/gcpcloudrun"
)

run: gcpcloudrun.#Run

To install it just run

dagger mod get github.com/tjovicic/dagger-modules/gcpcloudrun@v0.1

It should pull the v0.1 version from Github, leave a copy in cue.mod/pkg and reflect the change in cue.mod/dagger.mod.cue file:

cue.mod/pkg/github.com/
└── tjovicic
    └── dagger-modules
        └── gcpcloudrun
            ├── cue.mod
            ├── README.md
            └── source.cue
github.com/tjovicic/dagger-modules/gcpcloudrun v0.1

Querying the current setup with dagger query should return a valid result:

{
  "run": {
    "creds": {
      "username": "oauth2accesstoken"
    },
    "deploy": {
      "platform": "managed",
      "port": "80"
    },
    "push": {
      "auth": {
        "username": "oauth2accesstoken"
      },
      "push": {}
    }
  }
}

Upgrading

Now that you've successfully installed a package, let's try to upgrade it.

dagger mod get github.com/tjovicic/dagger-modules/gcpcloudrun@v0.2

You should see similar output:

12:25PM INF system | downloading github.com/tjovicic/dagger-modules:v0.2

And cue.mod/dagger.mod.cue should reflect the new version:

github.com/tjovicic/dagger-modules/gcpcloudrun v0.2