Created
March 15, 2023 09:37
-
-
Save ikondrat/2cf87eda8eb41d3da55d18e7e967e14f to your computer and use it in GitHub Desktop.
fill-local-env.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Script to fetch env variables required to have a build locally | |
| # it is used in setup-dev.sh | |
| set -e | |
| ENV_FILE=${1:-'apps/web/.env.local'} | |
| SPEC_FILE=${2:-'apps/web/env.local.yml'} | |
| eval $(assume-role -r tools-developer) | |
| # store static vars | |
| echo "# Static variables" > $ENV_FILE | |
| cat $SPEC_FILE | yq '.env.variables' | sed -e "s/[\'\ ]//g" -e "s/\:/\=/" >> $ENV_FILE | |
| echo >> $ENV_FILE | |
| echo "# Aws SSM variables" >> $ENV_FILE | |
| PARAMS=$(cat $SPEC_FILE | yq '.env.parameter-store' | sed "s/[\ \']//g") | |
| for i in $PARAMS | |
| do | |
| # set -- $i # convert the "tuple" into the param args $1 $2.. | |
| ssmKey=$(echo "$i" | cut -d ":" -f 1) | |
| ssmPath=$(echo "$i" | cut -d ":" -f 2) | |
| ssmValue=$(aws ssm get-parameter --with-decryption --name "$ssmPath" | jq -r '.Parameter.Value') | |
| echo "$ssmKey=$ssmValue" >> $ENV_FILE | |
| done | |
| echo "Fill $ENV_FILE with SSM variables by $SPEC_FILE" | |
| echo >> $ENV_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment