Adding and removing services

How to add or remove services based on templates or for particular environments

The services stanza in either the default environment configuration or the environment-specific configuration defines the services that will be deployed for your application. However you may want different services per template or by environment, for example, if you use RDS for staging and production and Postgres for your ephemeral environments. Let's take a look at two ways to add or remove services.

Remove service from template

If the service postgres is included in your default environment configuration and you want to remove it from your permanent template, find the environment_templates section and include remove: true, as shown in the code sample below. If you do not use the remove directive, the parser will assume you just want to override parts of the service instead.

environment_templates:
- name: ephemeral
  datasets:
  - name: release-prod
- name: permanent
  services:
  - name: 'postgres'
    remove: true
  auto_deploy: false
  hostnames:
  - frontend: frontend-staging-${domain}
  - docs: docs-staging-${domain}
  - backend: backend-staging-${domain}
  tracking_branch: maste

Add service to template

Alternatively, you can choose not to include postgres in your default services, and only create the service in the ephemeral section of the template using the syntax add: true, as illustrated in the sample below. If you don't include the add directive, the parser will assume you are trying to override an aspect of an existing service and give you an error, since the service name postgres won't exist.

environment_templates:
- name: ephemeral
  services:
  - name: postgres
    add: true
    image: postgres:11.4-alpine
    registry: public
    volumes:
    - type: persistent
      name: postgres
      mount_path: "/var/lib/postgresql/data"
    ports:
    - type: container_port
      port: '5432'
    storage:
      size: 100Gi
  datasets:
  - name: release-prod
- name: permanent
  auto_deploy: false
  hostnames:
  - frontend: frontend-staging-${domain}
  - docs: docs-staging-${domain}
  - backend: backend-staging-${domain}
  tracking_branch: master

Manually deleting a service

You can also manually delete a service from the environment-specific configuration. In our Postgres example, the postgres service would appear in your default services section. When you create a permanent environment, you can remove postgres from the configuration and save it before deploying and your new environment will not include the service.

Last updated