Managing Helm chart configurations across different environments requires propagating image updates and new environment variables between values files. Manual synchronization is error-prone and time-consuming.
The update-values.js script synchronizes Docker images and environment variables between Helm values files while preserving existing configurations and comments.
The Script
update-values.js - Cross-Environment Values Sync
-
Function: Synchronizes images and environment variables between any two values files
-
Compatibility: Handles both Alpha Application and Workflow Studio YAML structures automatically
-
Preservation: Maintains existing comments, formatting, and non-matching configurations
Key Features
Structure Detection
Detects whether files use the traditional image.repository/image.tag format (Workflow Studio) or the newer container.image format (Alpha Application) by examining directory names and content structure.
Service Matching
-
Direct name matching between services
-
Fuzzy matching for similar service names (e.g.,
alpha-backendmatchesbackend-service) -
Handles common prefix/suffix variations
Image Updates
-
Full image replacement: Updates both repository and tag
-
Tag-only updates: Preserves existing repository, updates only the tag using
--only-tagflag -
Maintains proper YAML structure for each format
Environment Variable Sync
-
Identifies new environment variables in source file that don’t exist in target
-
Adds missing variables with empty values and TODO comments
-
Preserves existing environment variables in target file
How to Use
Prerequisites
- Node.js 16+
Basic Usage
Sync complete images and environment variables:
./scripts/update-values.js alpha-application/values-uat.yaml alpha-application/values-prod.yaml
Update only tags (preserve repositories):
./scripts/update-values.js alpha-application/values-uat.yaml alpha-application/values-prod.yaml --only-tag
Example Output
Reading from file: alpha-application/values-uat.yaml
Reading to file: alpha-application/values-prod.yaml
From structure: alpha-application
To structure: alpha-application
Found 3 matching services:
alpha-backend -> alpha-backend
frontend-ui -> frontend-ui
notification-service -> notification-service
Updated image for alpha-backend: myregistry.azurecr.io/alpha-backend:v2.1.0
Updated image for frontend-ui: myregistry.azurecr.io/frontend-ui:v1.8.2
Added new env var to notification-service: SMTP_HOST with inline comment (original: smtp.company.com)
=== Update Summary ===
Updated 3 services with new images
Added 3 new environment variables with TODO comments
Output written to: alpha-application/values-dev.yaml
Use Cases
Dev to Prod Sync
Propagate Dev image versions to Prod environments while preserving prod-specific configurations.
Environment Variable Management
When new environment variables are added to Dev configurations, identify and add them to other environments with placeholder values and TODO comments.
Tag-Only Updates
Update only image tags when repositories remain the same but versions change.
Technical Details
YAML Structure Handling
Workflow Studio Format:
service-name:
image:
repository: myregistry.azurecr.io/service
tag: v1.0.0
env:
- name: DATABASE_URL
value: "postgres://..."
Alpha Application Format:
service-name:
container:
image: "myregistry.azurecr.io/service:v1.0.0"
secret:
environment:
DATABASE_URL: "postgres://..."
Environment Variable Comments
New environment variables are added with TODO comments:
NEW_CONFIG_VAR: "" # TODO: example value - (original-value-from-source)
Integration
CI/CD Pipeline Integration
- name: Sync UAT Images to Prod
run: |
./scripts/update-values.js values-uat.yaml values-prod.yaml --only-tag
git add values-prod.yaml
git commit -m "sync: update prod environment with uat image tags"
Release Management
Use tag-only updates during release cycles to maintain repository consistency while updating versions across environments.