Skip to content

Get started with Pulumi Delivery ​

In this guide, you'll write a pipeline that deploys an app through three environments, dev, staging, and prod, and pauses before prod until you tell it to continue. You'll register the pipeline with Pulumi Cloud, push a commit, and watch the release move through each stage. From then on, every push to main starts a new run.

INFO

Pulumi Delivery is in public preview. Behavior, the SDK, and the REST API routes under /api/preview/ can change before general availability.

Before you begin ​

You'll need:

  • A Pulumi Cloud organization on any edition
  • Pulumi CLI v3.277.0 or later.
  • A GitHub repository you can push to, with the GitHub integration installed for your organization and given access to that repository.
  • The toolchain for the language you'll write the pipeline in, such as Node.js for TypeScript

This guide uses a repository named acme/shop on the main branch. Replace acme/shop with your own repository as you go.

Lay out the repository ​

The pipeline program and the project it deploys live side by side in the same repository:

text
app/        the project the pipeline deploys
delivery/   the pipeline program

Create the app stacks ​

Delivery updates existing stacks but doesn't create them, so you'll create one stack for each environment first. To keep the focus on the pipeline, the app project doesn't create any cloud resources. It only returns a URL built from the stack name. Create app/Pulumi.yaml:

yaml
name: shop-app
runtime: yaml
outputs:
  url: https://${pulumi.stack}.shop.example.com

Then create a dev, staging, and prod stack for the project:

bash
cd app
pulumi stack init dev
pulumi stack init staging
pulumi stack init prod
cd ..

Because the project creates no resources, Delivery doesn't need any cloud credentials to deploy it. When you're ready to deploy real infrastructure, see Cloud credentials.

Write the pipeline program ​

The pipeline program is a Pulumi project of its own, written in any Pulumi language. Create it in the delivery directory along with its stack, main:

bash
mkdir delivery && cd delivery
pulumi new typescript --name shop-delivery --stack main --yes
npm install @pulumi/delivery

In a language with an SDK, the install step adds the Delivery SDK to the project's dependency file, such as package.json or requirements.txt. In YAML, pulumi package add delivery writes a packages entry to Pulumi.yaml. Commit that file, because Pulumi Cloud installs the package from it for each run. An HCL program names the provider in its required_providers block.

Now replace the program that pulumi new created with the pipeline. The program declares the repository as a source, three stages in order, and the app stack each stage updates:

In index.ts:

typescript
import * as delivery from "@pulumi/delivery";

const repo = new delivery.GitHubSource("repo", {
    repository: "acme/shop",
    branch: "main",
    trigger: true,
});

const pipeline = new delivery.Pipeline("shop");

const dev = new delivery.Stage("dev", { pipeline });
const staging = new delivery.Stage("staging", { pipeline, from: [dev] });
const prod = new delivery.Stage("prod", {
    pipeline,
    from: [staging],
    when: delivery.manual({ description: "Check staging before you ship to prod." }),
});

for (const [env, stage] of Object.entries({ dev, staging, prod })) {
    new delivery.Stacks(env, {
        stage,
        stacks: {
            app: { stack: `shop-app/${env}`, source: repo, directory: "app" },
        },
    });
}

Here's what each part does:

  • The GitHubSource points at main in your repository. Setting trigger to true starts a run on every push to main.
  • The Pipeline resource declares the pipeline. A pipeline program declares exactly one.
  • The three Stage resources run in order, because each one lists the stage before it in from. The prod stage also has a manual gate in when, so a release waits there until someone continues it.
  • The loop adds a Stacks resource to each stage, which runs pulumi up on that environment's shop-app stack.

Register the pipeline ​

Register the pipeline from the delivery directory:

bash
pulumi delivery register

Registering tells Pulumi Cloud about the pipeline and writes the program's location in your repository to the delivery:source setting in Pulumi.main.yaml. It doesn't start a run, so the output lists each stage as waiting for one. Commit everything, including that config file, and push:

bash
cd ..
git add app delivery
git commit -m "Add the shop delivery pipeline"
git push origin main

The push matches the source's trigger, so it starts your first run.

Watch the release ​

In the Pulumi Cloud console, navigate to Delivery > Pipelines and select shop-delivery/main. Your run is listed under In progress. Select it to open the run page.

The dev stage updates shop-app/dev, and once it succeeds, staging updates shop-app/staging. The run then pauses at the manual gate in front of prod, and its status reads "Waiting for someone to continue at prod".

In the run graph, select the Manual gate before prod. It shows the description you gave it. Select Continue, and Delivery updates shop-app/prod. Once the run finishes, open any of the three shop-app stacks to see the update the pipeline ran and the url output for that environment.

That's your first release. Every push to main from now on starts a new run, pinned to that commit, so the code that passed staging is the code that reaches prod.

Next steps ​

Content from the official Pulumi documentation (github.com/pulumi/docs).