Stack Template: TypeScript

If you are using Docker or Kubernetes you can check specific instructions for these at the bottom of this page.


Building and running TypeScript based apps is quite straightforward in Squash. There are basically three elements to accomplish this:

  • Pick the base OS image from Docker Hub, this is usually a flavor of a major distribution (Ubuntu, CentOS, etc) or a basic image tailored for your specific programming language. You may also use an image from your own private registry.
  • Install & build the necessary libraries/packages to run your app.
  • Run your app and services used by your app (database, caching, etc).

This is all done in a Squash YAML file.

Example #1: basic app, no database

This is a basic .squash.yml file for a Django application that doesn't require installing any additional services:

deployments:
  MyApp:
    dockerimage: ubuntu:16.04
    build_steps:
      - >
        DEBIAN_FRONTEND=noninteractive apt-get update &&
        DEBIAN_FRONTEND=noninteractive apt-get -y install 
        curl git sudo 
      - curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
      - >
        DEBIAN_FRONTEND=noninteractive apt-get update &&
        DEBIAN_FRONTEND=noninteractive apt-get -y install nodejs
      - cd ~/code
      - npm install
    launch_steps:
      - cd ~/code
      - npm start

Example #2: app + database + port_forwarding

Here we are installing the necessary packages to build the database service (MongoDB). Then the database service is launched inside of "launch_steps". Need to load test data into this database? please check: how to import data into a database.

And since the web app doesn't listen on port 80 we are using the port_forwarding field to tell Squash where to check for a success response.

deployments:
  MyApp:
    dockerimage: ubuntu:16.04
    build_steps:
      - >
        DEBIAN_FRONTEND=noninteractive apt-get update &&
        DEBIAN_FRONTEND=noninteractive apt-get -y install 
        curl git sudo build-essential mongodb
      - curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
      - >
        DEBIAN_FRONTEND=noninteractive apt-get update &&
        DEBIAN_FRONTEND=noninteractive apt-get -y install nodejs
      - cd ~/code
      - npm install
    launch_steps:
      - service mongodb start
      - cd ~/code
      - npm start
    port_forwarding: 80:8000

Example #3: using a separate VM for the database

Certain projects can benefit from having a separate VM/host for the database service. This is easy to achieve by using the Non-HTTP based deployments and the deployment dependencies feature.

In the example below we first define the database service itself, note that it has its own separate app at the top, named "DatabaseService". Then we define the web app (InventoryApp), note the depends_on field. This will tell Squash to make sure the Database service is available before starting the web app.

This feature allows you to also share the same database VM with multiple feature branches as needed. You can either tell Squash to always spin up a new database VM for each feature branch or just use a shared model. For more information please check the deployment dependencies page.

deployments:
  DatabaseService:
    dockerimage:
      ubuntu:16.04
    build_steps:
      - DEBIAN_FRONTEND=noninteractive apt-get update
      - DEBIAN_FRONTEND=noninteractive apt-get install -y 
      software-properties-common
      - DEBIAN_FRONTEND=noninteractive apt-get install -y 
        locales gcc postgresql postgresql-contrib 
        sudo supervisor
    launch_steps:
      - service postgresql start
    check_service_ports: 5432
    port_forwarding: 5432:5432

  InventoryApp:
    dockerimage: ubuntu:16.04
    build_steps:
      - >
        DEBIAN_FRONTEND=noninteractive apt-get update &&
        DEBIAN_FRONTEND=noninteractive apt-get -y install 
        curl git sudo
      - curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
      - >
        DEBIAN_FRONTEND=noninteractive apt-get update &&
        DEBIAN_FRONTEND=noninteractive apt-get -y install nodejs
      - cd ~/code
      - npm install
    launch_steps:
      - cd ~/code
      - npm start
    depends_on:
      - DATABASE_SERVICE:
          app: myrepo/master:DatabaseService

Miscellaneous