Skip to main content

Environment Variable Configuration

wukong-deploy supports managing sensitive information and environment-specific settings through environment variables.

Basic Usage

Use environment variables in the configuration file:

// config.mjs
export default {
servers: {
prod: {
host: '127.34.5.53',
username: 'root',
passwordEnv: 'PROD_SERVER_PASSWORD', // .env.wukong PROD_SERVER_PASSWORD="yourpassword"
},
},
};

Environment Variable Files

wukong-deploy loads environment variables from .env.wukong (generated by wukong-deploy init):

# .env.wukong

PROD_SERVER_PASSWORD=your-secure-password

The following files are also supported, in order of precedence (see below):

# .env.dev        — target-specific overrides (e.g. wukong-deploy deploy dev)
# .env.wukong — default file generated by `wukong-deploy init`
# .env — legacy file (still read as a fallback)

Configuration Priority

The loading priority of environment variables (from highest to lowest) is:

  1. Command-line arguments
  2. Environment variables (shell exports)
  3. .env.{target} (e.g. .env.dev, .env.prod) — target-specific overrides
  4. .env.wukong — default file generated by wukong-deploy init
  5. .env — legacy fallback (only used if the above are absent)

Compatibility

Prior to v1.2.42, .env was used. The current version still reads .env as a fallback, but .env.wukong (generated by wukong-deploy init) takes precedence. You can also provide a target-specific .env.{target} (e.g. .env.dev) to override variables for a specific server.

Security Recommendations

  1. Do not commit .env, .env.wukong, or .env.{target} files to version control
  2. Use .env.example (or .env.wukong.example) as a template
  3. Set appropriate file permissions
  4. Regularly update keys and passwords