A tool for Docker containers that render config files, extend the environment and run commands

Codeship Codecov Go Report Card

run

run replaces tokens in a config file tempalte by values from the specific data sources, saves a new config file and executes a command.

It was designed to be used in docker containers where a config file should receive values from the data sources before running the container's command.

Data sources

  • Environment variables
  • Local JSON file
  • Remote JSON file
  • AWS SecretManager

Options

--input value, -i value        The config template with the tokens to be replaced [$RUN_INPUT]
--output value, -o value       The output path for the compiled config file [$RUN_OUTPUT]
--delay value, -d value        Number of seconds to wait before running the command (default: 0) [$RUN_DELAY]
--json value, -j value         JSON data to be used by JSONLoader [$RUN_JSON]
--remote-json value, -r value  URL to a JSON file to be used by RemoteJSONLoader [$RUN_REMOTE_JSON]
--json-file value, -f value    Path to a JSON file to be used by JSONFileLoader [$RUN_JSON_FILE]
--aws-secret value             The ARN or name of a secret with a JSON encoded value [$RUN_AWS_SECRET_ARN]
--env-file value               A dotenv file template to be rendered and added to the environment [$RUN_ENV_FILE]
--env-output-var value         Create a environment variable with the contents of the output file [$RUN_ENV_OUTPUT_VAR]
--help, -h                     show help
--version, -v                  print the version

Example

The example below is of a container with a webserver but before starting the server it will compile the config file template using the run command.

Environment variables (.env)

MONGO_URL="mongodb://user:[email protected]/mydb"
JWT_SECRET="my$uper$ecret"
SERVER_BIND="0.0.0.0"
SERVER_PORT="8000"

Local JSON file (/mnt/shared/secrets/vars.json)

{
  "server": {
    "bind": "0.0.0.0"
  }
}

Remote JSON file (http://config-service/app/config.json)

{
  "server": {
    "port": "1234"
  }
}

AWS SecretManager

Secret name: jwtconfig

{
  "jwt": {
    "secret": "myjwtsecret"
  }
}

Config template (config.toml.dist)

[database]
url = "{{MONGO_URL}}"

[jwt]
secret = "{{jwt.secret|JWT_SECRET}}"

[server]
bind = "{{server.bind|SERVER_BIND}}"
port = "{{server.port|SERVER_PORT}}"

Dockerfile

FROM busybox:1.25.1

MAINTAINER Tarcisio Gruppi <[email protected]>

ADD https://github.com/txgruppi/run/releases/download/0.0.1/run_linux_amd64 /app/run
ADD ./config.toml.dist /app/config.toml.dist
ADD ./server /app/server

RUN run \
  -d 2 \
  --json-file /mnt/shared/secrets/vars.json \
  --remote-json http://config-service/app/config.json \
  --aws-secret jwtconfig \
  -i /app/config.toml.dist \
  -o /app/config.toml \
  /app/server -c /app/config.toml

Running the container

docker run -d --restart=always --env-file .env -p 1234 txgruppi/run-sample

Compiled config file (config.toml)

[database]
url = "mongodb://user:[email protected]/mydb"

[jwt]
secret = "myjwtsecret"

[server]
bind = "0.0.0.0"
port = "1234"
Owner
Similar Resources

Render helm values-files from others

helm-plugin-render-values The Helm downloader plugin with rendering templated values files Install Use helm CLI to install this plugin: $ helm plugin

Aug 1, 2022

This repository is where I'm learning to write a CLI using Go, while learning Go, and experimenting with Docker containers and APIs.

CLI Project This repository contains a CLI project that I've been working on for a while. It's a simple project that I've been utilizing to learn Go,

Dec 12, 2021

AWS environment config loader

awsenv AWS environment config loader. awsenv is a small binary that loads AWS environment variables for an AWS profile from ~/.aws/credentials - usefu

Nov 28, 2022

Simple docker tui to list, start and stop your containers

Simple docker tui to list, start and stop your containers

docker-tui Simple docker tui that lets you list, start and stop your containers. Current status Rough, initial prototype. Build with This tool relies

Dec 2, 2022

Go package exposing a simple interface for executing commands, enabling easy mocking and wrapping of executed commands.

go-runner Go package exposing a simple interface for executing commands, enabling easy mocking and wrapping of executed commands. The Runner interface

Oct 18, 2022

Binary program to restart unhealthy Docker containers

DeUnhealth Restart your unhealthy containers safely Features Restart unhealthy containers marked with deunhealth.restart.on.unhealthy=true label Recei

Dec 22, 2022

A super simple demo to document my journey to reasonably sized docker containers.

hello-docker A super simple demo to document my journey to reasonably sized docker containers. Task at Hand Build a docker container as small as possi

Nov 30, 2021

My Homemade ci-cd service made for docker containers

Docker-CI-CD What Is This? The Docker-CI-CD is a tool that helps you to make every commit and push to your github repositories happen seamlessly and a

Jan 24, 2022

Show dependency graph of docker images/containers

Show dependency graph of docker images/containers

docker-graph Show dependency graph of docker images/containers like this: Orange is images and green is containers. Features Collect docker images, co

Feb 7, 2022
Related tags
Tool to convert docker-compose files to set of simple docker commands

docker-decompose Tool to convert docker-compose files to set of simple docker commands. Install Use go get to install the latest version of the librar

Apr 12, 2022
Kubedock is a minimal implementation of the docker api that will orchestrate containers on a Kubernetes cluster, rather than running containers locally.

Kubedock Kubedock is an minimal implementation of the docker api that will orchestrate containers on a kubernetes cluster, rather than running contain

Nov 11, 2022
Build and run Docker containers leveraging NVIDIA GPUs
Build and run Docker containers leveraging NVIDIA GPUs

NVIDIA Container Toolkit Introduction The NVIDIA Container Toolkit allows users to build and run GPU accelerated Docker containers. The toolkit includ

Jan 7, 2023
Frep - Generate file using template from environment, arguments, json/yaml/toml config files

frep Generate file using template from environment, arguments, json/yaml/toml config files. NAME: frep - Generate file using template USAGE: fr

Nov 30, 2022
Dotnet-appsettings-env - Convert .NET appsettings.json file to Kubernetes, Docker and Docker-Compose environment variables

dotnet-appsettings-env Convert .NET appsettings.json file to Kubernetes, Docker

Dec 30, 2022
Dotnet-appsettings-env - Convert .NET appsettings.json file to Kubernetes, Docker and Docker-Compose environment variables

dotnet-appsettings-env Convert .NET appsettings.json file to Kubernetes, Docker

Feb 16, 2022
ecsk is a CLI tool to interactively use frequently used functions of docker command in Amazon ECS. (docker run, exec, cp, logs, stop)
ecsk is a CLI tool to interactively use frequently used functions of docker command in Amazon ECS. (docker run, exec, cp, logs, stop)

English / 日本語 ecsk ECS + Task = ecsk ?? ecsk is a CLI tool to interactively use frequently used functions of docker command in Amazon ECS. (docker run

Dec 13, 2022
A tool to build, deploy, and release any environment using System Containers.
A tool to build, deploy, and release any environment using System Containers.

Bravetools Bravetools is an end-to-end System Container management utility. Bravetools makes it easy to configure, build, and deploy reproducible envi

Dec 14, 2022
Testcontainers is a Golang library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.

When I was working on a Zipkin PR I discovered a nice Java library called Testcontainers. It provides an easy and clean API over the go docker sdk to

Jan 7, 2023
Open Source runtime scanner for Linux containers (LXD), It performs security audit checks based on CIS Linux containers Benchmark specification
Open Source runtime scanner for Linux containers (LXD), It performs security audit checks based on CIS Linux containers  Benchmark specification

lxd-probe Scan your Linux container runtime !! Lxd-Probe is an open source audit scanner who perform audit check on a linux container manager and outp

Dec 26, 2022