runtime-env

command module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2022 License: MIT Imports: 11 Imported by: 0

README

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

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.

Documentation

Overview

Copyright © 2022 Simon Hessel

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL