Deploying Docker Images Programmatically
Overview
This guide will show you how to deploy a Docker image programmatically using the Zeet GraphQL API. You can use this guide to deploy any Docker image.
Prerequisites
Before making API requests, make sure that you have the Zeet GraphQL API ready and working. You can use the Getting Started guide for reference. Before deploying, you'll want to connect a Kubernetes cluster to Zeet. You will need your Team ID, and your Zeet Cluster ID. You can grab those here:
# using v0 API endpoint:
# https://anchor.zeet.co/graphql
query {
  currentUser {
    teams {
      team {
        name
        user {
          id # This is $YOUR_TEAM_ID
          clusters {
            id # This is $YOUR_CLUSTER_ID
            name
          }
        }
      }
    }
  }
}
Creating a New Project
In order to deploy a Docker image using Zeet, you need to create a project. For this example, we'll use the api v0 endpoint. Ensure you are making requests to the correct GraphQL endpoint!
This is a single request that will create a new project, and deploy it to your cluster:
mutation {
  createResourceAlpha(
    input: {
      userID: $YOUR_TEAM_ID
      name: "docker-project"
      projectName: "api-docs" # Group
      environmentName: "example" # Sub-group
      blueprintID: "3fed9509-abdb-4237-bd5f-fa3811b2ae34" # Official Container Image Blueprint
      source: { 
        containerRegistry: {
          repository: "postgres",
          tag: "latest"
        }
      }
      build: { build: {} }
      kubernetes: {
        deployTarget: {
          deployTarget: KUBERNETES
          clusterID: $YOUR_CLUSTER_ID
        }
        app: {
          deployService: true
          volumes: []
          envs: [{ name: "POSTGRES_PASSWORD", value: "secret-password" }]
          ports: [{ port: "5432", protocol: tcp, public: true, https: false }]
          resources: { cpu: 1, memory: 1, spot: false }
        }
      }
      enabled: true
    }
  ) {
    id
  }
}
If successful, you'll get a response like:
{
  "data": {
    "createResourceAlpha": {
      "id": "d32a73b4-5e1c-4478-947f-6f65b6852bc6" // This is $YOUR_PROJECT_ID
    }
  },
  "extensions": {
    "requestId": "9f212c26-feaf-418b-914e-079b5f721c55"
  }
}
You can check the status of your deployment by querying the project:
query {
  currentUser {
    repo(id: $YOUR_PROJECT_ID) {
      productionDeployment {
        status
        endpoints
      }
    }
  }
}
Congrats! You've deployed a Docker image using the Zeet GraphQL API.