Created
July 9, 2025 18:24
-
-
Save boina-n/caa368693f8dd2f566a335f4ebf8819a to your computer and use it in GitHub Desktop.
docker_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
#!/bin/bash | |
# ------------------------------------------------------------------------------ | |
# docker_env.sh | |
# | |
# This script securely loads environment variables from Google Secret Manager, | |
# exports them to the local shell, and generates a .env file from a .env.dist | |
# template using envsubst. | |
# | |
# - Secrets are never printed to the console. | |
# - .env is created safely with only non-empty, non-commented variables. | |
# - File permissions on .env are restricted (chmod 600). | |
# | |
# Usage: | |
# ./docker_env.sh | |
# | |
# Requirements: | |
# - gcloud CLI authenticated with access to the secret | |
# - .env.dist file present in the current directory | |
# ------------------------------------------------------------------------------ | |
set -e | |
export $(gcloud secrets versions access latest --secret=service-production |grep -v "^#\|^$" | xargs) | |
cat .env.dist | envsubst > .env |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment