2.0.2 • Published 1 year ago

aws-multi-env v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

🚩 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

CommandDescription
configOutput loaded configuration
prepareRename and remove files on source folders to match environment
revertUndo changes on source folders

Options

ArgumentDescriptionType
--envEnvironment 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
--envsAcceptable environments, optionally mapped to branches. Example: --envs.prod --envs.staging=betastring
--sourceArray of glob folders to find files.arraydefault: "./.ebextensions/**","./.platform/**"]
--envMatcherRegex to match if file is environment specific.stringdefault: ".+.+..+$"]
--envMatcherSeparatorThe environment separator on file namesstring
--dryRunRun without making any actual changesboolean

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!