Skip to content

Instantly share code, notes, and snippets.

@davidshare
Last active December 24, 2021 04:15
Show Gist options
  • Save davidshare/12897d0a64ca9c4c8ed14dcc13ca8b00 to your computer and use it in GitHub Desktop.
Save davidshare/12897d0a64ca9c4c8ed14dcc13ca8b00 to your computer and use it in GitHub Desktop.
A simple bash script that takes a .env file with key and value separated by "=". It base64 encodes the value and produces a key value pair separated by a colon
#!/bin/bash
input="env_file_path"
secret_name="my-secret_name"
rm ./deployment_env.yaml ./secret_pair.txt
while IFS='=' read -r key value
do
if [[ ! -z "$key" && ! -z "$value" && "$key" != "#"* ]]
then
encoded=$(echo -n "$value" | base64 -w0)
echo "$key: $encoded" >> secret_pair.txt
var_block="
- name: $key
valueFrom:
secretKeyRef:
name: $secret_name
key: $key"
echo "$var_block">> deployment_env.yaml
fi
done < "$input"
@davidshare
Copy link
Author

davidshare commented May 6, 2021

The format for the .env file should be:

KEY=value

@davidshare
Copy link
Author

New modification to the scripts allows you to define the env blocks for the deployments too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment