Giter Club home page Giter Club logo

ddn-deployment's Introduction

Automate Hasura DDN Deployments

This repository provides everything you need to automate the deployment of a Hasura v3 project onHasura DDN. Using GitHub Actions, it simplifies the process of running DDN CLI commands, allowing you to efficiently deploy connectors and build and deploy your supergraph with ease.

Prerequisites

Hasura Account

A Hasura account is required to use this tool. You can sign up for a free account at Hasura Cloud.

Hasura Personal Access Token (PAT)

A Hasura Personal Access Token (PAT) is required to authenticate with Hasura Cloud. You can create a PAT from the Access Tokens page of Hasura Cloud. You'll then need to add the following secret to your repository:

HASURA_PAT: <your-hasura-pat>

Usage

In any workflow, add the following steps to automate the deployment of your Hasura project to Hasura DDN:

name: Hasura DDN Build

on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Hasura DDN Build
        uses: hasura/[email protected]
        with:
          hasura-pat: ${{ secrets.HASURA_PAT }}

Examples

Automatic Builds on Every Commit on a branch and PRs to main branch

Imagine you have a branch called main that you use to create a DDN build. You can use the following workflow:

on:
  push:
    branches:
      - main
      - release/*
  pull_request:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install and Login to DDN CLI
        uses: hasura/[email protected]
        with:
          hasura-pat: ${{ secrets.HASURA_PAT }}

      - name: Deploy PG connector and update the connector link
        run: ddn connector build create --connector app/connector/mypg/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link mypg --project ${{ secrets.HASURA_PROJECT }}

      - name: Deploy mongodb connector and update the connector link
        run: ddn connector build create --connector app/connector/my_mongo/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link my_mongo --project ${{ secrets.HASURA_PROJECT }}

      - name: Build and deploy TS functions and update the connector link
        run: ddn connector build create --connector app/connector/myts/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link myts --project ${{ secrets.HASURA_PROJECT }}
        
      - name: Build supergraph
        run: ddn supergraph build create --supergraph ./supergraph.cloud.yaml --project ${{ secrets.HASURA_PROJECT }} --description "Build for commit ${{ github.sha }}"

Automatic deployments + comment with build details on the PR

alt text

on:
  pull_request:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install and Login to DDN CLI
        uses: hasura/[email protected]
        with:
          hasura-pat: ${{ secrets.HASURA_PAT }}

      - name: Deploy PG connector and update the connector link
        run: ddn connector build create --connector app/connector/mypg/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link mypg --project ${{ secrets.HASURA_PROJECT }}

      - name: Deploy mongodb connector and update the connector link
        run: ddn connector build create --connector app/connector/my_mongo/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link my_mongo --project ${{ secrets.HASURA_PROJECT }}

      - name: Build and deploy TS functions and update the connector link
        run: ddn connector build create --connector app/connector/myts/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link myts --project ${{ secrets.HASURA_PROJECT }}

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y jq

      - name: Build supergraph
        run: ddn supergraph build create --supergraph ./supergraph.cloud.yaml --project ${{ secrets.HASURA_PROJECT }} --description "Build for commit ${{ github.sha }}" --out=json > build_output.json

      - name: Extract URLs from JSON
        id: extract_urls
        run: |
          BUILD_URL=$(jq -r '.build_url' build_output.json)
          CONSOLE_URL=$(jq -r '.console_url' build_output.json)
          echo "::set-output name=build_url::$BUILD_URL"
          echo "::set-output name=console_url::$CONSOLE_URL"

      - name: Add PR comment with build details
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v6
        with:
          script: |
            const buildUrl = '${{ steps.extract_urls.outputs.build_url }}';
            const consoleUrl = '${{ steps.extract_urls.outputs.console_url }}';
            const prNumber = context.payload.pull_request.number;
            const commitId = context.sha;
            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: prNumber,
              body: `Supergraph build was successful! ๐ŸŽ‰\n\n**Build URL:** [${buildUrl}](${buildUrl})\n**Console URL:** [${consoleUrl}](${consoleUrl})\n**Commit ID:** ${commitId}`
            });
          github-token: ${{ secrets.GITHUB_TOKEN }}

Resources

Check out the deployment guide in our docs ๐Ÿš€

ddn-deployment's People

Contributors

soorajshankar avatar robertjdominguez avatar

Stargazers

 avatar

Watchers

Brandon Martin avatar Rajoshi Ghosh avatar Manas Agarwal avatar Vamshi Surabhi avatar  avatar Yannik Olmo Hake avatar

Forkers

soorajshankar

ddn-deployment's Issues

Update Required: Commands Will Be Out-of-Date Soon

Description

With forecasted DX changes coming to the CLI, the following workflow will need to be updated ๐Ÿ‘‡

Explanation

Right now, this is our sequence:

curl -L https://graphql-engine-cdn.hasura.io/ddn/cli/latest/cli-hasura3-linux-amd64 -o hasura3
        chmod +x hasura3
        sudo mv hasura3 /usr/local/bin
        hasura3 login --pat ${{ inputs.hasura-pat }}
        OUTPUT=$(hasura3 build create --profile ${{ inputs.build_profile }} --description "${{ inputs.build_description }}" --out json)
        BUILD_VERSION=$(echo $OUTPUT | jq -r '.build_version')
        hasura3 build apply --version $BUILD_VERSION

Based upon DX changes, we'll need to specifically modify the final three steps:

        OUTPUT=$(hasura3 build create --profile ${{ inputs.build_profile }} --description "${{ inputs.build_description }}" --out json)
        BUILD_VERSION=$(echo $OUTPUT | jq -r '.build_version')
        hasura3 build apply --version $BUILD_VERSION

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.