aws-multi-env
v2.0.2
Published
Rename and remove files to match deployment environment.
Downloads
3
Maintainers
Readme
🚩 Table of Contents
🚀 Introduction
When deploying to AWS you might want to have different configurations files per environment, and this package does just that.
It finds files that match an environment key and renames to proper naming, remove files from other environments and keep the ones without especific env.
🔧 Installation
There's no need to install aws-multi-env, you can use it with npx.
📖 Usage
To run any command the working tree on the source folders must be clean.
npx aws-multi-env [command] <options>
Preparing files for deployment with an application name app-server-prod
:
$ npx aws-multi-env prepare --env app-server-prod
» i Current environment: prod
» i Renaming files from "prod" to correct name, and removing other files
» i Removed: ./.ebextensions/certbot.staging.config
» i Keep: ./.ebextensions/migration.config
» i Removed: ./.ebextensions/ssl.staging.config
» i Removed: ./.platform/nginx/conf.d/https_custom.staging.conf
» √ Environment ready, files were renamed and/or removed
Then, after you build/deploy you can revert the changes to deploy on another environment:
$ npx aws-multi-env revert --env app-server-prod
» i Current environment: prod
» i Renaming files back and restoring removed files
» i Running: git clean ./.ebextensions/** ./.platform/**
» i Running: git checkout ./.ebextensions/** ./.platform/**
» √ Environment restored, files renamed back and/or restored
Use on CI:
- name: Prepare deploy staging
run: |
npx aws-multi-env prepare --env "${{ secrets.AWS_ENVIRONMENT_NAME_STAGING }}"
yarn build && zip -r "$RUNNER_TEMP/deploy-staging.zip" .
npx aws-multi-env revert --env "${{ secrets.AWS_ENVIRONMENT_NAME_STAGING }}"
- name: Prepare deploy prod
run: |
npx aws-multi-env prepare --env "${{ secrets.AWS_ENVIRONMENT_NAME_PROD }}"
yarn build && zip -r "$RUNNER_TEMP/deploy-prod.zip" .
npx aws-multi-env revert --env "${{ secrets.AWS_ENVIRONMENT_NAME_PROD }}"
Commands
| Command | Description | |---------|----------------------------------------------------------------| | config | Output loaded configuration | | prepare | Rename and remove files on source folders to match environment | | revert | Undo changes on source folders |
Options
| Argument | Description | Type |
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| --env | Environment name to deploy and match files to, it will match the last portion of the name: app-server-prod
will match prod
. If no environment was matched, will match from branches. | [string] |
| --envs | Acceptable environments, optionally mapped to branches. Example: --envs.prod --envs.staging=beta | [string] [required] |
| --source | Array of glob folders to find files. | [array] [default: ["./.ebextensions/**","./.platform/**"]] |
| --envMatcher | Regex to match if file is environment specific. | [string] [default: ".+[.][a-z]+..+$"] |
| --envMatcherSeparator | The environment separator on file names | [string] [default: "."] |
| --dryRun | Run without making any actual changes | [boolean] [default: false] |
Using config file
We use cosmiconfig to load the config file, checkout some examples:
.aws-multi-envrc.json
{
"envs": {
"prod": ["main"],
"staging": ["beta"]
},
"source": ["./.ebextensions/**"]
}
.aws-multi-envrc.yml
envs:
prod:
- main
staging:
- beta
source:
- ./.ebextensions/**
- ./.platform/**
💬 Contributing
Would like to help make this package better? Please take a look at the contributing guidelines for a detailed explanation on how you can contribute.
❤️ Acknowledgments
I'd like thank my daily coffee!