charlretief/build-env
Composer 安装命令:
composer require charlretief/build-env
包简介
Composer plugin to build .env files from .env.example with advanced configuration management
README 文档
README
Build .env files from .env.example with advanced configuration management for different project environments like local, testing, staging, production. Also supports dynamic variables and environment defaults in ENV values.
Installation
Using composer:
composer global require "charlretief/build-env":"^2"
Usage
composer build-env [<environment>] [<defaults>] [--set-defaults] [--setup]
Multi-environment Build Setup
To setup a project for multi-environment builds run:
composer build-env --setup
After running the setup new sections will be added to the .env.example like:
################################################################
# APP_ENV=production
################################################################
#APP_DEBUG=false
#APP_ENV=production
Variables put under these sections will be used when the target build environment matches the name in APP_ENV comment section. Values in this section should be commented, they will get uncommented when the target build environment matches.
Basic Usage
To build a basic .env file for local development just run:
composer build-env
or to specify a different build environment:
composer build-env staging
Advanced Usage #1 - Pinned values
Pinned values allows for local overrides to values that should not be replaced by running build-env. One possible use for this is secrets management like database credentials that you do not want to commit into vcs.
To create local pinned values simply add them to the bottom of any generated .env file below the placeholder.
################################################################
# Local pinned values #
################################################################
DB_USERNAME="root"
DB_PASSWORD="password123"
After adding pinned values run composer build-env again. It will then comment out the same variables in the generated portion of the file to prevent duplicate keys in the file.
Advanced Usage #2 - Defaults file
A defaults file is another "env" file, that allows for overwriting keys in the .env.example with default values.
This is useful for CI/CD processes that need to always set the same hostnames in all .env files. It can also function as an alternative to pinned values for secrets management for things like database credentials that you do not want to commit into vcs.
For example to always overwriting your DB_HOST create a file .env.defaults (can be any filename) with content:
DB_HOST="127.0.0.1"
Then the generated .env file will always have this value for DB_HOST.
composer build-env local .env.defaults
To remember your defaults file for next time you run without the defaults option add the --set-defaults argument:
composer build-env local .env.defaults --set-defaults
Advanced Usage #3 - Placeholder variable substitution
In the .env.example file there can be placeholder variables in double curly braces, like {{myvar}}, that will be replaced with values from a defaults file if they are present in the defaults file.
Example:
CONTACT_EMAIL={{EMAIL}}
APP_URL="http://{{myvar}}.local.dev"
Version 2
build-env version 1 is now deprecated, and with it the experimental .env.json file format. However version 2 will remain fully backwards compatible with reading the .env.json file format.
charlretief/build-env 适用场景与选型建议
charlretief/build-env 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 charlretief/build-env 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 charlretief/build-env 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2019-04-14