Skip to content

Commit

Permalink
Fix for deployment to handle .env parameters from github secret in ba…
Browse files Browse the repository at this point in the history
…se64 encoded format
  • Loading branch information
sshrihar committed Dec 12, 2024
1 parent b2344c9 commit 0e42ac4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/ecs_deploy_docker_taskdef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ on:
required: false
default: "staging"
type: string
env_file_secret_var:
required: false
default: ""
type: string
description: "Variable name containing b64 encoded data for .env file"
secrets:
build_params_gh_secret_keys:
required: false
description: "Pass github secrets in json format for supporting docker build"



jobs:
deploy_workflow:
name: Deploy ${{ inputs.app_name }}
Expand Down Expand Up @@ -81,6 +85,13 @@ jobs:
jq -r 'to_entries | .[] | "\(.key)=\(.value)"' secrets.json >> $GITHUB_ENV
fi
- name: Set up secrets from base64 encoded secret to .env file in code directory
run: |
if [[ -n "${{ inputs.env_file_secret_var }}" ]]; then
echo "Fetching and decoding .env file data from secret.${{ inputs.env_file_secret_var }}"
echo "${{ secrets[inputs.env_file_secret_var] }}" | base64 -d > code/.env
fi
- name: Set variables
run: |
if [ "${{ inputs.taskdef_file_script }}" == "local" ]; then
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/npm_build_deploy_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ on:
required: false
default: "staging"
type: string
base64_encoded_env_file_data:
required: false
default: ""
type: string
secrets:
build_params_gh_secret_keys:
required: false
Expand Down Expand Up @@ -61,7 +65,7 @@ jobs:
run: |
if [ -n "${{ secrets.build_params_gh_secret_keys }}" ]; then
echo "${{ secrets.build_params_gh_secret_keys }}" > secrets.json
fi
fi
- name: Parse secrets and set environment variables
run: |
Expand All @@ -70,6 +74,12 @@ jobs:
jq -r 'to_entries | .[] | "\(.key)=\(.value)"' secrets.json >> $GITHUB_ENV
fi
- name: Set up .env from base64 encoded data
run: |
if [ -n "${{ inputs.base64_encoded_env_file_data }}" ]; then
echo "${{ inputs.base64_encoded_env_file_data }}" | base64 -d > .env
fi
- name: INSTALL
run: npm install

Expand Down

0 comments on commit 0e42ac4

Please sign in to comment.