1.3.0 • Published 1 year ago

runtime-env v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Runtime-env

Runtime-env is cli written in go to parse environment variables & generate a javascript file which adds these to the browsers window object.

Release Software License Build status

Powered By: GoReleaser

Install

Script install

curl -sfL https://shkreios.github.io/runtime-env/install.sh | sh

NPM install

NPM

npm install --dev-save runtime-env

YARN

yarn add -D runtime-env

Usage

NAME:
   runtime-env - runtime envs for SPAs

USAGE:
   runtime-env [global options]

VERSION:
   v1.3.0

AUTHOR:
   Simon Hessel <simon.hessel@kreios.lu>

GLOBAL OPTIONS:
   --env-file value, -f value                   The .env file to be parsed
   --schema-file value, --schema value          A .env file which contains a list of envs to be parsed
   --prefix value, -p value                     The env prefix to matched
   --output value, -o value                     Output file path (default: "./env.js")
   --type-declarations-file value, --dts value  Output file path for the typescript declaration file
   --global-key value, --key value              Customize the key on which the envs will be set on window object (default: "__RUNTIME_CONFIG__")
   --remove-prefix                              Remove the prefix from the env (default: false)
   --no-envs                                    Only read envs from file not from environment variables (default: false)
   --disable-logs, --no-logs                    Disable logging output (default: false)
   --watch, -w                                  Watch .env file (default: false)
   --help, -h                                   show help (default: false)
   --version, -v                                print the version (default: false)

COPYRIGHT:
   Copyright © 2022 Simon Hessel

Input

# .env input file
TEST=Test

Command

$ runtime-env -f .env --no-envs

Output

window.__RUNTIME_CONFIG__ = { TEST: "Test" };

Code

console.log(window.__RUNTIME_CONFIG__.TEST);

Docker

#!/bin/sh

...

# any other entrypoint operations here
....
runtime-env # your runtime-env flags here

# any other entrypoint operations here
...

# call CMD
exec $@
...

# install runtime-env via install.sh script
RUN wget -O - https://shkreios.github.io/runtime-env/install.sh | sh

# important to be set after install.sh as otherwise binary will placed under /app/bin/runtime-env
WORKDIR /app/

# Copy your entrypoint script
COPY entrypoint.sh entrypoint.sh

...

#
ENTRYPOINT ["./entrypoint.sh"]

# optionaly set command
# CMD ["nginx"]

...

In CI/CD

# use either wget, curl or whatevery you ci env supports

curl -sfL https://shkreios.github.io/runtime-env/install.sh | sh

# wget -O - https://shkreios.github.io/runtime-env/install.sh | sh

runtime-env # your runtime-env flags here

Github Action

Read from secrets

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: shkreios/runtime-env-action@v1
        with:
          version: v1.1.0
          prefix: RUN_ENV_
          output: ./public/env.js
          removePrefix: "true"
        env:
          RUN_ENV_EXAMPLE: ${{ secrets.EXAMPLE }}
// resulting env.js in public folder
window.__RUNTIME_CONFIG__ = { EXAMPLE: "SECRET_VALUE" };

Why go / Why should i use this package?

There many solutions similar to this package react-env, runtime-env-cra or sh scripts to name a few. They all fall in one of 2 categories:

  1. they are either dependent on a runtime/interpreter to be preinstalled like nodejs or python or
  2. they are not platform-agnostic

Go supports building binaries for multiple platforms and arches, and the binary itself includes everything to be executed. Therefore, no matter if development with npm or in docker CI/CD you can expect it to be easily installed and as light as it can be.

Why have a npm wrapper/placeholder script?

As this tool will mostly be used in npm codebases where you expect everything, including a tool that generates runtime-envs, to be installed via npm/yarn it's the best option.

1.3.0

1 year ago

1.2.2

2 years ago

1.2.0

3 years ago

1.2.1

2 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago