Git Product home page Git Product logo

envvars's Introduction

Envvars

Go Reference License Go Report Card GitHub Tag Build Status Build Status
Docker Hub Docker Image Version Docker Hub Pulls Badge


Give your environment variables the love they deserve.

Overview

Envvars, a command line tool written in Go, provides a way to describe the environment variables of a project and ensures they are defined before testing, building, and deploying. It also generates an env file to be used by other applications such as Docker and Compose.

Installation

# install latest release
$ go install github.com/flemay/envvars@latest

# install from source
$ git clone https://github.com/flemay/envvars
$ cd envvars
$ go install ./...

# or use the tiny docker image (< 5 MB)
# example for version 0.0.8
$ docker run --rm flemay/envvars:0.0.8 --help

Usage

# create a declaration file envvars.yml
# envvars:
#   - name: ECHO
#     example: Hello World
$ envvars init

# validate the declaration file if it contains errors
$ envvars validate

# ensure the environment variables comply with the declaration file. The declaration file is also validated.
$ envvars ensure
# Error: environment variable ECHO is not defined
# set ECHO with empty value
$ export ECHO=""
$ envvars ensure
# Error: environment variable ECHO is empty
# set ECHO with non-empty value
$ export ECHO="helloworld"
$ envvars ensure

# create an env file
$ envvars envfile
$ cat .env
# ECHO

# create an env file with the example value
$ envvars envfile -overwrite -example
$ cat .env
# ECHO=Hello World

# explore
$ envvars --help

Declaration File

The declaration file (written in YAML) is the core of Envvars. It declares all the environment variables used by a project.

Envvars is looking for the declaration file envvars.yml by default. A different file can be passed with the flag -f path/to/declarationfile.yml.

tags:
  - name: deploy
    desc: tag used when deploying

envvars:
  - name: ENV
    desc: Application stage (dev, qa, preprod, prod)
    tags:
      - deploy
    optional: true
    example: dev
Field Type Required Description
tags list no List of tags to be used for targeting a subset of environment variables
tags.name string yes Unique tag name
tags.desc string no Meaningful description of the tag
envvars list yes List of environment variables
envvars.name string yes Unique environment variable name
envvars.desc string no Meaningful description of the environment variable
envvars.tags list of string no List of tags for the environment variable. Each tag must be declared in the "tags" field.
envvars.optional bool no Allows the environment variable to be empty or not defined. It is best to avoid it unless your application accepts an empty value.
envvars.example string no Example value for the environment variable.

Guidelines

Documentation is your best friend

The field desc should be used if the name of the tag or environment variable is not self-explanatory. This helps anyone new to the project, or juggling with many projects at once, to understand every environment variable, and tag.

The 3 Musketeers

Envvars fits nicely with the 3 Musketeers for managing the environment variables used by an application.

Contributing

Contributions are greatly appreciated. Everyone can contribute and here are different ways.

Releases and current state

Envvars is in its early stage and its API is not stable. Envvars will be production ready when it reaches v1.0.0.

See Automation & Configuration for more details.

Stargazers over time

Stargazers over time

License

MIT

envvars's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

envvars's Issues

Print variable description on "envvar ensure" failure

If you're not already familiar with envvars, it's probably not intuitive to go looking in envvars.yml when you get an error about unset variables. The description for the variable will be really useful if you need to set it, so an easy way to surface this information is in the error from envvar ensure.

if example is empty, we still need the equal sign

currently if we don't have an example

envvars:
  - name: AWS_DEFAULT_REGION
    desc: AWS Region to deploy to
    tags:
      - aws

the .env file will be generated like

AWS_DEFAULT_REGION

But i think it should be like

AWS_DEFAULT_REGION=

This can also prevent issue if i use envvars envfile to generate a .env and later invoke docker-compose with it.

i can submit a small pr to get it fixed if you think it makes sense.

Envvar 'Allowed Values' Enum?

I don't know if this is trying to solve a problem in the wrong place, but I have reached a conclusion it might be useful to specify a list of allowed values for env vars when using this tool. A validator of sorts:

Example:

envvars:
  - name: ENV
    desc: Application stage (dev, qa, preprod, prod)
    tags:
      - deploy
    optional: true
    example: dev
    values:
        - dev
        - qa
        - preprod
        - prod

I'd be happy to flex my go muscles and contribute this, just want to get some input before I do :)

List of examples

It would be nice to pass a list of examples instead of being limited to one.

envvars:
  - name: ENV
    description: Application environment
    examples:
      - prod
      - dev
    tags:
      - deploy

non-dockerhub hosting

Given that dockerhub rate limits quite aggressively these days, I'm frequently having to set up private repos to host this image. Any chance we can also get it hosted elsewhere? Public ECR is pretty good.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.