Using extension fields in your Swarm YAML to emulate the compose env_file feature

Replicated does not currently support the Docker Compose feature env_file which makes it possible to extract your common environment variables and clean up your spec.

Docker added extension fields as of Compose version 3.4. This makes it possible to re-use configuration fragments in your Compose YAML. We can make use of YAML anchors and aliases to achieve something similar to the env_file feature.

---
# kind: scheduler-swarm

version: '3.4'

x-custom:
  shared_env: &shared_env
    RELEASE_CHANNEL: unstable
    VERSION: 2.21.0

services:
  replicated:
    environment:
      <<: *shared_env
      PROJECT_NAME: replicated
  replicated-ui:
    environment:
      <<: *shared_env
      PROJECT_NAME: replicated-ui
  replicated-operator:
    environment:
      <<: *shared_env
      PROJECT_NAME: replicated-operator
1 Like

thank you that was really helpfull.
i have thoght one qusetion, can i reset the value in the extension fields
ie:
x-custom:
shared_env: &shared_env
DB_DONE: 0
services:
postgis-db:
environment:
<<: *shared_env
and in the build script after every thing is done
DB_DONE=1
it worked just for the current conatiner