Deploying GraphOS Router on Azure

Deploy router with Azure Container App


Learn how to deploy the router for development on Azure as a Container App.

You will:

  • Build a router image with a Dockerfile.

  • Set up an Azure Container Registry and push your router image to it.

  • Create and deploy an Azure Container App for your router.

Prerequisites

Before you start:

  1. Set up a GraphQL API in GraphOS.

    • Save your APOLLO_KEY and APOLLO_GRAPH_REF. You'll need them when deploying the router.

  2. Install Docker locally.

  3. Login to or create an Azure account.

  4. Install Azure CLI.

  5. Choose a version of the router to deploy (for example, v1.61.0). You'll need it when specifying the router image to deploy.

Build router image

To deploy your own router, start by customizing and building a router image, using a Dockerfile and a router configuration file:

  1. In a local directory, create a router.yaml file and copy-paste the following configuration into the file:

    YAML
    router.yaml
    1supergraph:
    2    listen: 0.0.0.0:4000
    3health_check:
    4    listen: 0.0.0.0:8088

    The router's default HTTP and health check endpoint addresses are localhost, so they wouldn't be reachable when deployed. This configuration enables the router to listen to all addresses.

  2. Create a Dockerfile file and copy-paste the following into the file:

    Text
    # Use the official Apollo Router Core image as the base.
    # Set the image tag to the desired router version (e.g. v1.61.0)
    FROM ghcr.io/apollographql/router:v1.61.0
    
    # Replace the default router config with the local, customized router.yaml
    COPY router.yaml /dist/config/router.yaml

    The Dockerfile sources the base router image from the GitHub container registry, using the version of router you specify. It then copies your customized router.yaml configuration file to overwrite the default router configuration file.

  3. From the same local directory, use docker buildx build to build a new router image for a specific platform. Choose a name and tag for the image, for example router:v1.61.0.

    Bash
    docker buildx build --platform linux/amd64  -t router:v1.61.0 --load .
    • The --load option loads the built image to docker images.

  4. Run docker images and validate that your router image is in the returned list of images.

Push router image to container registry

Create an Azure Container Registry as needed, then push your router image to it.

Create new container registry

If you don't have an existing container registry, create a new one:

  1. Log in to the Azure Portal and go to Container registries.

  2. Click Create container registry.

  3. Fill in the details:

    • Subscription: Select your subscription

    • Resource group: Select existing group or create new

    • Registry name: Enter a unique name for your registry (for example, myapolloregistry)

    • Location: Select an appropriate region

    • Pricing plan: Select an appropriate plan

  4. Click Review + create, then click Create.

  5. Your registry should now be created. Click on your registry to go to its portal page.

Log in to container registry

  1. In a terminal, sign in to Azure CLI:

    Bash
    az login
  2. Log in and authenticate to your registry (for example, myapolloregistry):

    Bash
    az acr login --name myapolloregistry

Tag and push image to registry

  1. Use docker tag to create an alias of the image with the fully qualified path to your registry (for example, myapolloregistry.azurecr.io):

    Bash
    docker tag router:v1.61.0 myapolloregistry.azurecr.io/router:v1.61.0
  2. Push the image to the registry:

    Bash
    docker push myapolloregistry.azurecr.io/router:v1.61.0
  3. Use az acr repository list to verify your image is now in the registry:

    Bash
    az acr repository list --name myapolloregistry
Expected output
Bash
[
  "myapolloregistry"
]

Deploy the router

Create and deploy a container app to run the router in Azure:

  1. Log in to the Azure Portal, then go to Create Container App

  2. Fill in the details for the Basics tab:

    • Subscription: Select your subscription

    • Resource Group: Select existing group or create new

    • Name: Enter a unique name for your web app.

    • Publish: Choose Container

    • Operating System: Choose Linux

    • Region: Select an appropriate region

    • App Service Plan: Select existing plan or create new

  3. Fill in the details for the Container tab:

    • Subscription: Select your subscription

    • Registry: Select your registry

    • Image: Select your router image

    • Image tag: Select your router image's tag

    • Arguments override: Enter --dev, --config, /dist/config/router.yaml

    • Environment variables: Enter APOLLO_GRAPH_REF and APOLLO_KEY with your graph ref and API key, respectively

  4. Fill in the details for the Ingress tab:

    • Ingress: Check Enabled

    • Ingress traffic: Select Accepting traffic from anywhere

    • Ingress type: Select HTTP

    • Target port: Enter 4000 (must match your router's supergraph.listen port)

  5. Click Review + create.

  6. Click Create, then wait for your deployment to complete.

  7. Click Go to resource to open the portal page for your deployed container, then click on the Application Url to verify that your router's Sandbox is running successfully.

Congrats, you've successfully deployed the router!

Feedback

Edit on GitHub

Ask Community