# Set up workflow templates

The best way to ask Debusine to do some work for you is to create Workflows. In this tutorial, you will discover how to set up workflow templates on your own instance.

## Prerequisites

This tutorial assumes that you installed your own instance and that you have administrative access it via debusine-admin. You can skip this tutorial if you’re using a managed instance such as debusine.debian.net, since in those cases suitable workflow templates have already been created for you.

If you haven’t done so already, you’ll need to make yourself an owner of the default workspace in order to be allowed to create workflow templates in it.

    $ sudo debusine-admin group create debusine/Admins
    $ sudo debusine-admin workspace grant_role debusine/System owner Admins
    $ sudo debusine-admin group members debusine/Admins --add YOUR-USER-NAME

You will also need to set up the Debusine client.

## Create a build environment

Various worker tasks require build environments, which are created using the update_environments workflow.

Using the Debusine client you set up, start by creating a debian:environments collection:

    $ debusine collection create debian@debian:environments </dev/null

Then create a suitable workflow template and start it running:

    $ debusine workflow-template create \
        update_environments update-debian-environments <<END
    static_parameters:
      vendor: "debian"
      targets:
      - codenames: ["trixie"]
        architectures: ["amd64"]
        backends: ["unshare"]
        mmdebstrap_template:
          bootstrap_options:
            variant: "minbase"
          bootstrap_repositories:
          - mirror: "http://deb.debian.org/debian"
            components: ["main"]
      - codenames: ["trixie"]
        architectures: ["amd64"]
        variants: ["sbuild"]
        backends: ["unshare"]
        mmdebstrap_template:
          bootstrap_options:
            variant: "buildd"
          bootstrap_repositories:
          - mirror: "http://deb.debian.org/debian"
            components: ["main"]
    END

    $ debusine workflow start update-debian-environments <<END
    {}
    END

Once this workflow finishes (which will take a few minutes), you should have a debian:environments collection populated with some useful base tarballs for `trixie/amd64` that can be used with the `unshare` backend: a default variant containing only essential and required packages, and an `sbuild` variant that also contains build-essential packages. These can be looked up by name. If you wish, you can vary the `targets` dictionary to build different environments, or automate this workflow to run regularly.

## Set up the Debian pipeline

The debian_pipeline workflow is a powerful tool that coordinates all the steps typically involved in building and testing an upload to Debian; it also has options to run tests on other packages that depend on your package, and perform the upload for you at the end.

On your client, create a suitable workflow template:

    $ debusine workflow-template create \
        debian_pipeline debian-qa-unshare <<END
    static_parameters:
      autopkgtest_backend: unshare
      lintian_backend: unshare
      piuparts_backend: unshare
      sbuild_backend: unshare
      upload_include_binaries: false
      upload_merge_uploads: false
      vendor: debian
      codename: sid
    runtime_parameters:
      source_artifact: 'any'
      codename: ['sid', 'forky']
      autopkgtest_backend: ['unshare', 'incus-lxc', 'incus-vm']
      lintian_backend: ['unshare', 'incus-lxc', 'incus-vm']
      piuparts_backend: ['unshare', 'incus-lxc', 'incus-vm']
      sbuild_backend: ['unshare', 'incus-lxc', 'incus-vm']
    END

Any workflow parameters specified in `runtime_parameters` may be set to any of the specified values when you create a workflow from the template. The special value `'any'` allows any value to be provided. A global `runtime_parameters: any` allows all workflow parameters to be specified at workflow creation time.

You will then be able to run this workflow for a given source artifact, as shown in Getting started with Debusine.