Deployment Automation with GitHub Actions and Nitric

This guide will demonstrate how Nitric can be used, along with GitHub Actions, to create a continuous deployment pipeline. We provide examples for deploying to AWS, Google Cloud, and Microsoft Azure, which you can adapt based on your preferred cloud provider.

Configuration

  1. Prepare Your Nitric Project
    Ensure you have a Nitric project ready to deploy. If you haven’t set up a project yet, refer to our quickstart guide.

  2. Add a GitHub Actions Workflow File
    Create a YAML file in a .github/ folder at the root of your project to configure the deployment automation steps. You can name the file according to your preference; for our examples, we use deploy-aws.yaml, deploy-azure.yaml, and deploy-gcp.yaml.

Here’s example content for each cloud provider:

.github/deploy-aws.yaml
name: Example Nitric AWS Deployment

# Triggers for the workflow
on:
  # Allows manual triggering of the workflow from GitHub
  workflow_dispatch:

  # Triggers the workflow on push to the main branch
  push:
    branches:
      - main

jobs:
  update:
    # The workflow will run on the latest Ubuntu OS
    runs-on: ubuntu-latest

    steps:
      # Check out the code from the repository
      - name: Checkout 🛎️
        uses: actions/checkout@v4

      # Install Pulumi for infrastructure management
      # Learn more about the Pulumi action configuration at https://github.com/pulumi/actions.
      - name: Install and configure Pulumi 📦
        uses: pulumi/actions@v4

      # Apply infrastructure using Nitric
      # Learn more about the Nitric action configuration at https://github.com/nitrictech/actions.
      - name: Applying infrastructure 🚀
        uses: nitrictech/actions@v1
        with:
          # The 'up' command deploys the project
          command: up

          # Replace with your stack name
          stack-name: dev
        env:
          # Configure the environment variables required by Nitric's dependency Pulumi and AWS.
          # In this example, we store the required values in GitHub secrets. Secrets can be found by navigating to:
          # https://github.com/{user}/{project}/settings/secrets/actions

          # Pulumi config passphrase
          # For interaction-free experiences, Pulumi requires a passphrase. Your passphrase generates a unique key that encrypts configuration and state values.
          PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}

          # Pulumi access token
          # You can get a Pulumi access token by logging into Pulumi on the browser and going to your profile settings. Under the 'Access Tokens' tab, click 'Create token.'
          PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}

          # AWS access key ID
          # You can obtain a key ID from the AWS console: https://console.aws.amazon.com/
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

          # AWS secret access key
          # You can obtain an access key from the AWS console: https://console.aws.amazon.com/
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}