Stack Template: Go

Building and running Web apps written in Go 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 flavour 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.  If you are using Docker or Kubernetes you can check specific instructions for these at the bottom of this page.

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, it doesn’t use a database.

    dockerimage: ubuntu:14.04
      - apt-get update && apt-get install -y libssl-dev \
        libpq-dev git \
        python python-dev python-pip python-virtualenv
      - pip install setuptools pip
      - pip install ~/code
      - cd ~/code/mysite
      - python runserver
  • A Squash YAML needs to start with “deployments:”
  • “MyWebApp”: you can change this and use the name of your application. If you have multiple apps in one repo you can define multiple Apps using this same format.
  • dockerimage: this is where you define the base OS image.
  • build_steps: install any required packages here. In the example above we are using “apt” to download and install packages. This is because the base OS image is Ubuntu. You would use different package managers depending on the OS image of your choice.
  • launch_steps: This is where you run any required services and your app. For this specific example the app is listening on port 80, which is the default port used by Squash for routing, so no additional routing information is needed.

Example #2: app + database + port_forwarding

Example #3: using npm and run_options

Here is a more complete example of a build process to run the Open Source project Wagtail:

    dockerimage: python:3.7.4-stretch
      - apt-get update && apt-get install -y libssl-dev libpq-dev git build-essential libfontconfig1 libfontconfig1-dev curl
      - RUN bash -c "curl -sL | bash -"
      - apt install -y nodejs
      - pip install setuptools pip --upgrade --force-reinstall
      - cd /code
      - npm install --no-save --no-audit --progress=false
      - npm run dist
      - pip install /code
      - mkdir /myproject
      - cd /myproject
      - wagtail start mysite
      - cd /myproject/mysite
      - python migrate
      - echo "<br><h1>Wagtail test instance</h1><p>Log into <a href='/admin/'>/admin/</a> with 'admin' / 'changeme'.</p>" > home/templates/home/welcome_page.html
      - echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', '', 'changeme')" | python shell    
      - cd /myproject/mysite
      - python runserver
    run_options: -v ~/code:/code

In the example above we are:

  • Installing and building packages with npm. This is done with “post_build_steps” to ensure these steps are always executed regardless of caching.
  • Mapping the app’s code into¬† a “/code” volume with run_options.