7. 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_srv2

Figure: Diagram after adding `backend_srv2`.#

  1. Create backend_srv2 component inside the DAG with the same component type as the backend_srv 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_srv2 torque.basics.V1HttpService \
  -p path=backend_srv2 \
  -p port=80
  1. Link database to backend_srv2 in the same way we linked backend_srv component.

torque link create db backend_srv2 \
  --type torque.basics.V1PostgresLink \
  -p database=example \
  -p user=test_user

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

torque link create backend_srv2 lb \
  --type torque.basics.V1IngressLink \
  -p path=/backend_srv2 \
  -p host=api2
  1. Again, we need to add the application code as described in the section 5. 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_srv2 && \
  curl -L https://github.com/torquetech/docs-examples/releases/download/docs/backend_srv_v2.tar \
  | tar xzvf - -C backend_srv2
Backend API written in Python#
mkdir backend_srv2 && \
  curl -L https://github.com/torquetech/docs-examples/releases/download/docs/backend_srv2_v2.tar \
  | tar xzvf - -C backend_srv2

After you download and unpack an app, make sure you change the API route URL inside the app code from /backend_srv to /backend_srv2, 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_srv2 running app execute:

curl -H "Host: api2.my-domain.com" http://localhost:8080/backend_srv2

The output should be the current database time.

Database time: 2022-11-17T21:41:19.371349Z%
  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.torquetech.io" https://<IP address>/backend_srv2 -k

The response is the same as on local development

Database time: 2022-11-17T21:41:19.371349Z%

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.