Skip to main content

6. Evolving the DAG

In this guide, you have used all core Torque Framework objects, and you have created deployments for the development environment (Docker Compose) and DigitalOcean. Now that you experienced the entire workflow, let's see how you can use concepts that you have learned to add one more component to the architecture DAG. Let's expand your DAG with another backend service that is connected to the PostgreSQL database.

Diagram after adding backend-service2:

Diagram

  1. Create backend-service2 component inside the DAG with the same component type as the backend-service component. Notice that we do not need to install a new code package. We already have it installed in the workspace.
torque component create backend-service2 torque.basics.V1HttpService \
-p path=backend-service2 \
-p port=80 \
--no-suffix
  1. Link database to backend-service2 in the same way we linked backend-service component.
torque link create db backend-service2 \
--type torque.postgres.V1EnvironmentLink \
-p database=example \
-p user=test_user

And similarly to backend-service, expose it to the internet by creating a link to the load balancer (ingress).

torque link create backend-service2 lb \
--type torque.basics.V1IngressLink \
-p path=/backend-service2 \
-p host=api2
  1. Since we added the new component and links, we'll update deployment configurations, both for local and prod deployments.
  torque deployment update local && \
torque deployment update prod
  1. We can take a look at how the workspace's DAG evolved by running the deployment dot command introduced in the section Running on Localhost:
torque deployment dot local | dot -Tpng -o graph.png

Graph

  1. Again, we need to add the application code as described in the section Adding Application Code. The URLs for example apps are

To download and unpack any of these apps inside your workspace, run:

Backend API written in Golang:

mkdir backend-service2 && \
curl -L https://github.com/torquetech/docs-examples/releases/download/docs/backend-service-go-v3.tar.gz \
| tar xzvf - -C backend-service2

Backend API written in Python:

mkdir backend-service2 && \
curl -L https://github.com/torquetech/docs-examples/releases/download/docs/backend-service-python-v3.tar.gz \
| tar xzvf - -C backend-service2

After you download and unpack an app, make sure you change the API route URL inside the app code from /backend-service to /backend-service2, so the rest of the commands in this chapter can succeed.

Do note that you can use any technology of your choice. It will work as long as there is a Dockerfile present in the app root.

  1. We are ready to build and apply deployment. Let's first test our DAG changes locally.
torque deployment build local
torque deployment apply local

To check the backend-service2 running app execute:

curl -H "Host: api2.example.com" http://localhost:8080/backend-service2

The output should be the current database time:

Database time: 2023-01-09T10:49:30.536818Z% 
  1. And now we'll deploy the DAG to DigitalOcean. Make sure you have DO_TOKEN available as environment variable.
export DO_TOKEN=dop_v1_replace_with_your_personal_access_token

Then run:

torque deployment build prod
torque deployment apply prod

Test the deployment with the following curl:

curl -H "Host: api2.example.com" https://<IP address>/backend-service2 -k

The response is the same as on local development:

Database time: 2023-01-09T10:49:30.536818Z% 

Notice that we did not change anything about local or prod deployments. The code packages with required providers are already installed in the workspaces. And the deployments already have listed the correct providers to be used for these deployments.