Commit Graph

52 Commits

Author SHA1 Message Date
Michael Fitz-Payne e0ff889553 1.1.1: bump new version to include bugfix. 2021-06-17 11:16:21 +10:00
Michael Fitz-Payne 3f02d19ad1
FIX: Remove quotes from escaped strings. (#27)
When strings have been escaped and contain a space, we don't want to
quote them because the escape character is then treated as a literal.

For example:
```
$ export var1="hello there"
$ export var2="hello\ there"
$ export var3=hello\ there
$ printf "$var1\n$var2\n$var3\n"
hello there
hello\ there
hello there
```
2021-06-17 10:43:44 +10:00
Michael Fitz-Payne 9a9514810e 1.1.0: bump new version 2021-06-16 13:29:00 +10:00
Michael Fitz-Payne 193242003d
FEATURE: Support generating docker cli arguments. (#22)
The --gen-docker-env-args argument makes pups process any template
environment variables and generate the command line arguments suitable
for the docker run command. The intention is to expand support for
configuring container runtime into pups such that configuration
templates can be more generally useful.

Bash special characters are safely escaped. This prevents issues where
variables contain special characters that are parsed by the calling shell.
A script which uses the pups output may have unexpected side effects
without escaping the special characters.

Note that only `env`, `label`, and `volume` config variables are escaped
as these are the most likely to contain special chacters. No attempt is
made to validate config variables against the allowed characters by
docker itself.

Other changes:
- Change some exit calls to return to prevent the tests prematurely
exiting.
2021-06-15 16:14:21 +10:00
Michael Fitz-Payne ebe1069395 Add --ignore option for specific config elements. (#26)
There are use cases where we may want pups to ignore particular
configuration elements at runtime. For example, we may want to skip over
hooks in certain circumstances or define environment variables via the
process at runtime that are already defined in a template.

The follow example demonstrates the usage (note the last log line):

```
$ cat /tmp/test.yml
env:
  MY_VAR: a_word
run:
  - exec: 'echo repeating $MY_VAR'

$ bin/pups --ignore env /tmp/test.yml
I, [2021-06-09T12:03:46.864770 #30369]  INFO -- : Reading from /tmp/test.yml
I, [2021-06-09T12:03:46.865009 #30369]  INFO -- : > echo repeating $MY_VAR
I, [2021-06-09T12:03:46.865824 #30369]  INFO -- : repeating

$ bin/pups /tmp/test.yml
I, [2021-06-09T12:03:50.694739 #30380]  INFO -- : Reading from /tmp/test.yml
I, [2021-06-09T12:03:50.694980 #30380]  INFO -- : > echo repeating $MY_VAR
I, [2021-06-09T12:03:50.695730 #30380]  INFO -- : repeating a_word
```

This will become more useful once the docker run argument generation
functionality is implemented. For example, options like `expose` may
want to be ignored if pups is being used to generate runtime arguments
for more the one container on the same machine (as published port numbers
cannot overlap between containers). Without the `--ignore` lever, all
runtime arguments will be produced all the time which limits use cases.
2021-06-10 09:02:49 +10:00
Michael Fitz-Payne 44198d7704
Add --quiet option to silence logs. (#25)
This prevents any output from pups being printed. Exceptions will still
be output when they occur.

Slightly restructured the cli class so that the options are able to be
parsed separately to the run method so we can print the usage message in
the event of invalid input.
2021-06-09 10:12:18 +10:00
Michael Fitz-Payne 2069d66f39
Add lint step to CI, fix all lint issues. (#24)
The fixes were performend rubocop -A functionality for autocorrecting.
The linting is enforced according to the rubocop-discourse rules.
2021-06-03 12:22:29 +10:00
Michael Fitz-Payne 17f04ecde5
Add support for templating environment variables. (#20)
Templated variables can be used to parameterise container creation. This
will ensure any ENV variables are templated during config initialisation
prior to any use.

There are situations where we want to provide and config template at
runtime rather than ahead-of-time. This adds support for specifying such
a variable via the process environment, prefixed with
env_template_<name>=value.
2021-05-20 13:09:39 +10:00
Michael Fitz-Payne f9af90d645
cli: update option parsing to OptionParser. (#21)
Change to proper argument handling in preparation of adding
new command-line arguments to the pups CLI.

Tests added arguments parsing and also for when a file is
specified (not stdin).
2021-05-20 08:46:21 +10:00
Sam Saffron d1db0303d0
cut a new version 2021-04-09 09:25:31 +10:00
David Taylor 05db637f26
Revert "FIX: coerce env to strings" (#19)
This reverts commit 262d7eb4f8 and 8f353a3778

discourse_docker's launcher, and potentially other systems, manipulate environment variables before applying them to a `docker run` command. At the moment, those tools do not necessarily apply those same manipulations to the YAML file passed to pups.

Specifically, in discourse_docker's launcher, the string `{{config}}` in container labels or environment variables is substituted with the filename of the YAML file. Launcher does not perform this replacement on the file passed to pups. Previously, that was not an issue, because pups didn't use the `env` or `labels` from the file. Now, it causes pups to run its setup using incorrect environment variables.

Reverting this until:
  - We update discourse_docker's launcher so that it performs the replacement on the YAML file passed to pups
  - We come up with a way to avoid breaking old discourse_docker installs (right now they use the latest `master` version of discourse/pups on every build)
2021-04-08 13:42:52 +01:00
Sam Saffron 262d7eb4f8
FIX: coerce env to strings
env only ever accepts strings
2021-04-08 18:06:09 +10:00
Michael Fitz-Payne 8f353a3778 Add 'env' property support to configuration.
Variables specified under the `env` property in the root of the yaml
configuration file will now be set in the pups environment during the
initialization process. Any existing environment variables are
overwritten by matching variables specified in the config `env` property.

The integration test was updated to exercise the params and env
codepath as this covers the new functionality.
2021-04-08 16:32:00 +10:00
Andrew Schleifer 4cfff79a83 feature: new `file` parameter to chown 2019-07-31 09:37:57 +08:00
Sam d1cdc3fdf1 bump version, don't leak exception 2018-06-20 10:30:27 +10:00
Jay Pfaffman 2142c6f212 Raise error rather than exit 2016-09-12 11:37:00 -07:00
Jay Pfaffman 5d6a44e317 Print an error and exit if input cannot be parsed 2016-09-12 10:32:01 -07:00
Sam 2b8776d7e7 we need the exitstatus 2016-05-26 16:56:44 +10:00
Sam ed68e3c436 correct exit codes 2016-05-26 16:52:39 +10:00
Sam 2027ec19ef correct location of error 2016-05-26 16:40:32 +10:00
Sam b95c910271 correct namespace 2016-05-26 16:30:44 +10:00
Sam a863a053a9 support passing a correct exit code 2016-05-26 16:29:36 +10:00
Sam 25a7243cb9 bump 2016-05-26 16:11:49 +10:00
Sam 670f301523 version 1.0.0 2014-10-09 13:00:18 +11:00
Sam b4942617ec FIX: more robust termination of spawned processes
FEATURE: optional stop_signal
FEATURE: more logging for termination process
2014-10-09 12:59:52 +11:00
Sam 59aa6450fc improve error messaging. 2014-08-25 16:33:39 +10:00
Michael Brown f2c3218e42 Don't clobber existing data with nil when merging 2014-08-02 23:01:17 -04:00
Sam cf4008b951 support for global replace 2014-03-25 16:56:53 +11:00
Sam 5a4454cd00 Allow for substitutions in replace, suck in ENV and add to params 2014-03-18 17:46:20 +11:00
Sam Saffron 9543dedb8e strip env helpers, they are not that useful 2013-12-11 17:35:47 -08:00
Sam Saffron 5a15e10022 better error reporting 2013-12-05 17:16:42 -08:00
Sam Saffron 7713200fe2 missed a spot 2013-12-05 16:16:38 -08:00
Sam Saffron b0c6d096fa allow for params in path 2013-12-05 16:14:26 -08:00
Sam Saffron 8036a83dcd add logging 2013-11-28 16:14:46 -08:00
Sam Saffron d889dd80fe wow, how did I not catch this 2013-11-27 19:14:51 -08:00
Sam Saffron 526de622a2 oops 2013-11-27 16:06:54 -08:00
Sam Saffron 4f4f2cf9db better handling of hooks, allow skipping missing hooks 2013-11-27 15:33:36 -08:00
Sam Saffron 5da93c8900 need defined? here 2013-11-27 15:23:57 -08:00
Sam Saffron bb7100c1c1 ensure termination
correct the deep merge algorithm to allow array merging
2013-11-26 22:29:23 -08:00
Sam Saffron 57108ddb3e reverse sub 2013-11-03 23:16:44 -08:00
Sam Saffron 4cdc866c93 added hook support 2013-11-03 21:09:15 -08:00
Sam Saffron bba4593208 allow multiple inputs via stdin 2013-11-03 19:58:41 -08:00
Sam Saffron 5c589546e1 added file command and removed runit specific stuff 2013-11-03 16:18:10 -08:00
Sam Saffron df85a26b05 terminate async jobs on exit 2013-11-01 03:00:12 -07:00
Sam Saffron cba7b40ed1 new features, pass stdin in raise_on_fail 2013-10-31 21:23:47 -07:00
Sam Saffron 23cb227240 fix fail cases 2013-10-31 17:12:37 -07:00
Sam Saffron b8bb889184 typo ... 2013-10-31 03:23:53 -07:00
Sam Saffron 12e80e9ae8 work in progress 2013-10-30 23:11:25 -07:00
Sam Saffron 6b83a8e74e runit configurator works 2013-10-30 22:17:32 -07:00
Sam aa68eab205 work in progress runit services 2013-10-31 13:43:32 +11:00