4. Running on Localhost#

After you modified the code in the previous step, you are ready to create your first deployment and run your workspace in your development environment. To be more precise, you will use the deployment create command to create a new deployment object. Then you will use deployment build and deployment apply commands to build a Docker image and spin up Docker containers using Docker Compose in your development environment, and your apps and services will be up and running.

Prerequisites#

For the local deployment commands to work properly, ensure you have installed and are running the following tools in your development environment:

  1. Docker

  2. Docker Compose

Important

To install Docker (with Docker Compose) on MacOS visit https://www.docker.com/get-started/ website and follow the instructions. And make sure Docker is up & running by checking a visible Docker image on the MacOS status bar.

Install Docker Compose package#

You will now add a code package that enables deployment of components on Docker Compose. For that, you need Docker Compose providers. Providers are code that convert components and links from the DAG into specific deployments.

For a detailed description of Torque Framework entities and their relations, check the Torque Framework section.

torque package install git+https://github.com/torquetech/torque-docker-compose-basics-provider.git && \
torque package install git+https://github.com/torquetech/torque-docker-compose-postgres-provider.git && \
torque package install git+https://github.com/torquetech/torque-docker-compose-hlb-provider.git && \
torque package install git+https://github.com/torquetech/torque-docker-compose-provider.git

Creating Deployment#

You want to create a local deployment for running the workspace locally inside the Docker Compose environment. For now, you have to list all providers that you need explicitly during deployment creation.

torque deployment create local \
  torque.docker_compose.V1Provider torque.docker_compose_postgres.V1Provider torque.docker_compose_hlb.V1Provider torque.docker_compose_basics.V1Provider \
  --extra-config dc.yaml

Notice that we referred to an additional configuration file dc.yaml, and this file should be in your root directory. You can create dc.yaml.

touch dc.yaml

And add the following content into it:

providers:
  torque.docker_compose.V1Provider:
    configuration:
      overrides:
        services:
          lb:
            ports:
            - 8080:80

Or you can download it from dc.yaml.

curl -L https://github.com/torquetech/docs-examples/releases/download/docs/dc.yaml > dc.yaml

Note

This is one of multiple ways you can add custom configurations to customize the functionality of components, links, and providers. There will be many more details soon on how configuration and customization in Torque works in a dedicated chapter.

This prepares your deployment for running the workspace locally. To list all deployments run:

torque deployment list
Command output#
Deployment(local, context_type=torque.defaults.V1LocalContext, providers=['torque.docker_compose.V1Provider', 'torque.docker_compose_postgres.V1Provider', 'torque.docker_compose_hlb.V1Provider', 'torque.docker_compose_basics.V1Provider'], components=None)

Running Locally#

Now that you have a local deployment created and configured, you can run all components locally using Docker Compose. And in fact, Torque will handle Docker Compose for you without your intervention.

Important

For the following commands to work, you need to have Docker installed and running on your laptop.

torque deployment build local
torque deployment apply local

The apply command for local deployment executes the docker compose command for the Docker images built during the build command. This created and started Docker containers.

To check the running app execute:

curl -H "Host: api.my-domain.com" http://localhost:8080/backend_srv

The output should be the current database time.

Database time: 2022-11-17T18:50:11.403468Z%