Skip to main content

πŸ”Ί Managing Environment Variables

πŸ’» Local Development​

Installing the CLI Tool​

The Infisical CLI is a powerful command-line tool that can be used to retrieve, modify, export, and inject secrets into any process or application as environment variables. You can use it across various environments, whether it’s local development, CI/CD, staging, or production.

Logging in with the CLI​

infisical login
  • Select your hosting option: Self Hosting
  • Domain: https://env.byt.so

Initializing Infisical for Your Project​

# Navigate to your project
cd /path/to/project

# Initialize Infisical
infisical init

Injecting Environment Variables​

Pass environment variables from Infisical into your application.

  • Use the command infisical run to inject environment variables into your application.
  • infisical run --env=dev -- [your application start command] # e.g. npm run dev, npm run start, npm run build, etc
"scripts": {
# Other scripts
"dev": "infisical run --env=dev -- next dev",
# Other scripts
},
  • Update the above command in your application scripts.
  • πŸŽ‰ Start your application with [your application start command] # e.g. npm run dev.
  • Infisical Core Commands

🌍 CI/CD​

Using Machine Identity​

  • Create an Identity.

  • Set CLIENT_ID, CLIENT_SECRET, PROJECTID in GitLab CI/CD variables.

curl -1sLf \
'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.deb.sh' \
| sudo -E bash

sudo apt-get update && sudo apt-get install -y infisical

export INFISICAL_API_URL="https://env.byt.so"
export INFISICAL_TOKEN=$(infisical login --method=universal-auth --client-id=$CLIENT_ID --client-secret=$CLIENT_SECRET --silent --plain)
infisical run --env=dev --projectId=$PROJECTID [application start command]
  • The --plain flag will output only the token, so it can be fed to an environment variable. The --silent flag will disable any update messages.

πŸ“š References​