@rse/nunjucks-cli 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -0
- package/eslint.yaml +51 -0
- package/nunjucks.d/date.js +38 -0
- package/nunjucks.d/default.js +52 -0
- package/nunjucks.d/eval.js +29 -0
- package/nunjucks.js +175 -0
- package/package.json +35 -0
- package/sample.txt +153 -0
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
nunjucks-cli
|
|
3
|
+
============
|
|
4
|
+
|
|
5
|
+
**Nunjucks Template Rendering Command-Line Interface**
|
|
6
|
+
|
|
7
|
+
<p/>
|
|
8
|
+
<img src="https://nodei.co/npm/nunjucks-cli.png?downloads=true&stars=true" alt=""/>
|
|
9
|
+
|
|
10
|
+
<p/>
|
|
11
|
+
<img src="https://david-dm.org/rse/nunjucks-cli.png" alt=""/>
|
|
12
|
+
|
|
13
|
+
Abstract
|
|
14
|
+
--------
|
|
15
|
+
|
|
16
|
+
This is a small command-line utility to render templates with the rich
|
|
17
|
+
and powerful templating language [Mozilla Nunjucks](https://mozilla.github.io/nunjucks/).
|
|
18
|
+
This allows you to define your configuration in a YAML file and then render
|
|
19
|
+
an output file based on a template input file where your configuration can be expanded.
|
|
20
|
+
|
|
21
|
+
Installation
|
|
22
|
+
------------
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
$ npm install -g @rse/nunjucks-cli
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Usage
|
|
29
|
+
-----
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
$ nunjucks
|
|
33
|
+
[-h|--help] [-V|--version]
|
|
34
|
+
[-c|--config <config-file>]
|
|
35
|
+
[-d|--defines <context-file>]
|
|
36
|
+
[-D|--define <key>=<value>]
|
|
37
|
+
[-e|--extension <extension-file>]
|
|
38
|
+
[-o|--output <output-file>|-]
|
|
39
|
+
<input-file>|-
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- `-h`|`--help`:<br/>
|
|
43
|
+
show usage help.
|
|
44
|
+
- `-V`|`--version`:<br/>
|
|
45
|
+
show program version information.
|
|
46
|
+
- `-c`|`--config` `<config-file>`:<br/>
|
|
47
|
+
load Nunjucks configuration YAML file
|
|
48
|
+
- `-d`|`--defines` `<context-file>`:<br/>
|
|
49
|
+
load context definition YAML file.
|
|
50
|
+
- `-D`|`--define` `<key>=<value>`:<br/>
|
|
51
|
+
set context definition key/value.
|
|
52
|
+
- `-e`|`--extension` `<extension-file>`:<br/>
|
|
53
|
+
load Nunjucks JavaScript extension file.
|
|
54
|
+
- `-o`|`--output` `<output-file>`|`-`:<br/>
|
|
55
|
+
save output file (or stdout).
|
|
56
|
+
- `<input-file>`|`-`:<br/>
|
|
57
|
+
load input file (or stdin).
|
|
58
|
+
|
|
59
|
+
Example
|
|
60
|
+
-------
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
$ echo "Hello, {{who}}!" | nunjucks -D who=world -
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
License
|
|
67
|
+
-------
|
|
68
|
+
|
|
69
|
+
Copyright (c) 2019-2023 Dr. Ralf S. Engelschall (http://engelschall.com/)
|
|
70
|
+
|
|
71
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
72
|
+
a copy of this software and associated documentation files (the
|
|
73
|
+
"Software"), to deal in the Software without restriction, including
|
|
74
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
75
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
76
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
77
|
+
the following conditions:
|
|
78
|
+
|
|
79
|
+
The above copyright notice and this permission notice shall be included
|
|
80
|
+
in all copies or substantial portions of the Software.
|
|
81
|
+
|
|
82
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
83
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
84
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
85
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
86
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
87
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
88
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
89
|
+
|
package/eslint.yaml
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
##
|
|
2
|
+
## nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
3
|
+
## Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
4
|
+
## Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
5
|
+
##
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
extends:
|
|
10
|
+
- eslint:recommended
|
|
11
|
+
- eslint-config-standard
|
|
12
|
+
|
|
13
|
+
parserOptions:
|
|
14
|
+
ecmaVersion: 8
|
|
15
|
+
sourceType: module
|
|
16
|
+
ecmaFeatures:
|
|
17
|
+
jsx: false
|
|
18
|
+
|
|
19
|
+
env:
|
|
20
|
+
browser: false
|
|
21
|
+
node: true
|
|
22
|
+
mocha: false
|
|
23
|
+
commonjs: true
|
|
24
|
+
worker: false
|
|
25
|
+
serviceworker: false
|
|
26
|
+
|
|
27
|
+
globals:
|
|
28
|
+
process: true
|
|
29
|
+
|
|
30
|
+
rules:
|
|
31
|
+
# modified rules
|
|
32
|
+
indent: [ "error", 4, { "SwitchCase": 1 } ]
|
|
33
|
+
linebreak-style: [ "error", "unix" ]
|
|
34
|
+
semi: [ "error", "never" ]
|
|
35
|
+
operator-linebreak: [ "error", "after", { "overrides": { "&&": "before", "||": "before", ":": "after" } } ]
|
|
36
|
+
brace-style: [ "error", "stroustrup", { "allowSingleLine": true } ]
|
|
37
|
+
quotes: [ "error", "double" ]
|
|
38
|
+
|
|
39
|
+
# disabled rules
|
|
40
|
+
no-multi-spaces: off
|
|
41
|
+
no-multiple-empty-lines: off
|
|
42
|
+
key-spacing: off
|
|
43
|
+
object-property-newline: off
|
|
44
|
+
curly: off
|
|
45
|
+
space-in-parens: off
|
|
46
|
+
array-bracket-spacing: off
|
|
47
|
+
require-atomic-updates: off
|
|
48
|
+
dot-notation: off
|
|
49
|
+
no-whitespace-before-property: off
|
|
50
|
+
lines-between-class-members: off
|
|
51
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
3
|
+
** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
4
|
+
** Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const moment = require("moment")
|
|
8
|
+
const nlib = require("nunjucks/src/lib")
|
|
9
|
+
|
|
10
|
+
module.exports = (env) => {
|
|
11
|
+
/* add a "date" formatting filter */
|
|
12
|
+
env.addFilter("date", (date, format, ...args) => {
|
|
13
|
+
let result
|
|
14
|
+
const errs = []
|
|
15
|
+
let obj
|
|
16
|
+
try {
|
|
17
|
+
obj = moment(date)
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
errs.push(err)
|
|
21
|
+
}
|
|
22
|
+
if (obj) {
|
|
23
|
+
try {
|
|
24
|
+
if (obj[format] && nlib.isFunction(obj[format]))
|
|
25
|
+
result = obj[format](obj, ...args.slice(2))
|
|
26
|
+
else
|
|
27
|
+
result = obj.format(format)
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
errs.push(err)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (errs.length)
|
|
34
|
+
return errs.join("\n")
|
|
35
|
+
return result
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
3
|
+
** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
4
|
+
** Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
module.exports = (env) => {
|
|
8
|
+
const globals = {
|
|
9
|
+
bool: (val) => {
|
|
10
|
+
if (typeof val === "undefined") return false
|
|
11
|
+
else if (typeof val === "boolean") return val
|
|
12
|
+
else if (typeof val === "number") return !isNaN(val) && val !== 0
|
|
13
|
+
else if (typeof val === "string") return val.match(/^(?:true|yes)$/i) !== null
|
|
14
|
+
else return !!val
|
|
15
|
+
},
|
|
16
|
+
int: (val) => {
|
|
17
|
+
if (typeof val === "undefined") return NaN
|
|
18
|
+
else if (typeof val === "boolean") return val ? 1 : 0
|
|
19
|
+
else if (typeof val === "number") return val
|
|
20
|
+
else if (typeof val === "string") return parseInt(val, 10)
|
|
21
|
+
else return 0
|
|
22
|
+
},
|
|
23
|
+
float: (val) => {
|
|
24
|
+
if (typeof val === "undefined") return NaN
|
|
25
|
+
else if (typeof val === "boolean") return val ? 1.0 : 0.0
|
|
26
|
+
else if (typeof val === "number") return val
|
|
27
|
+
else if (typeof val === "string") return parseFloat(val)
|
|
28
|
+
else return 0.0
|
|
29
|
+
},
|
|
30
|
+
string: (val) => {
|
|
31
|
+
if (typeof val === "undefined") return "undefined"
|
|
32
|
+
else if (typeof val === "boolean") return val.toString()
|
|
33
|
+
else if (typeof val === "number") return val.toString()
|
|
34
|
+
else if (typeof val === "string") return val
|
|
35
|
+
else return val.toString()
|
|
36
|
+
},
|
|
37
|
+
default: (val, def, type) => {
|
|
38
|
+
if (val === undefined)
|
|
39
|
+
val = def
|
|
40
|
+
if (type === "bool") val = globals.bool(val)
|
|
41
|
+
else if (type === "int") val = globals.int(val)
|
|
42
|
+
else if (type === "float") val = globals.float(val)
|
|
43
|
+
else if (type === "string") val = globals.string(val)
|
|
44
|
+
else throw new Error(`invalid coercion type "${type}"`)
|
|
45
|
+
return val
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
Object.keys(globals).forEach((name) => {
|
|
49
|
+
env.addGlobal(name, globals[name])
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
3
|
+
** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
4
|
+
** Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
module.exports = (env) => {
|
|
8
|
+
/* add a "set"-like "eval" extension */
|
|
9
|
+
class EvalExtension {
|
|
10
|
+
constructor () {
|
|
11
|
+
this.tags = [ "eval" ]
|
|
12
|
+
}
|
|
13
|
+
parse (parser, nodes, lexer) {
|
|
14
|
+
const tok = parser.nextToken()
|
|
15
|
+
const args = parser.parseSignature(null, true)
|
|
16
|
+
parser.advanceAfterBlockEnd(tok.value)
|
|
17
|
+
return new nodes.CallExtension(this, "run", args)
|
|
18
|
+
}
|
|
19
|
+
run (context, args) {
|
|
20
|
+
for (const arg in args) {
|
|
21
|
+
if (arg !== "__keywords")
|
|
22
|
+
/* eslint no-eval: off */
|
|
23
|
+
context.ctx[arg] = eval(args[arg])
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
env.addExtension("EvalExtension", new EvalExtension())
|
|
28
|
+
}
|
|
29
|
+
|
package/nunjucks.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
** nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
4
|
+
** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
5
|
+
** Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* own information */
|
|
9
|
+
const my = require("./package.json")
|
|
10
|
+
|
|
11
|
+
/* internal requirements */
|
|
12
|
+
const fs = require("node:fs")
|
|
13
|
+
const path = require("node:path")
|
|
14
|
+
|
|
15
|
+
/* external requirements */
|
|
16
|
+
const yargs = require("yargs")
|
|
17
|
+
const chalk = require("chalk")
|
|
18
|
+
const jsYAML = require("js-yaml")
|
|
19
|
+
const nunjucks = require("nunjucks")
|
|
20
|
+
|
|
21
|
+
/* parse command-line arguments */
|
|
22
|
+
const argv = yargs
|
|
23
|
+
.usage("Usage: nunjucks " +
|
|
24
|
+
"[-h|--help] " +
|
|
25
|
+
"[-V|--version] " +
|
|
26
|
+
"[-c|--config <config-file>] " +
|
|
27
|
+
"[-d|--defines <context-file>] " +
|
|
28
|
+
"[-D|--define <key>=<value>] " +
|
|
29
|
+
"[-e|--extension <extension-file>] " +
|
|
30
|
+
"[-o|--output <output-file>|-] " +
|
|
31
|
+
"<input-file>|-")
|
|
32
|
+
.version(false)
|
|
33
|
+
.help("h").alias("h", "help").default("h", false).describe("h", "show usage help")
|
|
34
|
+
.boolean("V").alias("V", "version").describe("V", "show program version information")
|
|
35
|
+
.string("c").nargs("c", 1).alias("c", "config").describe("c", "load Nunjucks configuration YAML file")
|
|
36
|
+
.string("d").nargs("d", 1).alias("d", "defines").describe("d", "load context definition YAML file")
|
|
37
|
+
.string("D").nargs("D", 1).alias("D", "define").describe("D", "set context definition key/value")
|
|
38
|
+
.array("e").nargs("e", 1).alias("e", "extension").describe("e", "load Nunjucks JavaScript extension file")
|
|
39
|
+
.string("o").nargs("o", 1).alias("o", "output").default("o", "-").describe("o", "save output file")
|
|
40
|
+
.strict()
|
|
41
|
+
.showHelpOnFail(true)
|
|
42
|
+
.demand(0)
|
|
43
|
+
.parse(process.argv.slice(2))
|
|
44
|
+
|
|
45
|
+
/* handle special version request */
|
|
46
|
+
if (argv.version) {
|
|
47
|
+
console.log(`${my.name} ${my.version} (Node.js ${process.versions.node}, Nunjucks: ${my.dependencies.nunjucks})`)
|
|
48
|
+
console.log(`${my.description}`)
|
|
49
|
+
console.log(`Copyright (c) 2019-2023 ${my.author.name} <${my.author.url}>`)
|
|
50
|
+
console.log(`Licensed under ${my.license} <http://spdx.org/licenses/${my.license}.html>`)
|
|
51
|
+
process.exit(0)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* read input file */
|
|
55
|
+
let input = ""
|
|
56
|
+
if (argv._.length !== 1) {
|
|
57
|
+
console.error(chalk.red("nunjucks: ERROR: missing input file"))
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
let inputFile = argv._[0]
|
|
61
|
+
if (inputFile === "-") {
|
|
62
|
+
inputFile = "<stdin>"
|
|
63
|
+
process.stdin.setEncoding("utf-8")
|
|
64
|
+
const BUFSIZE = 256
|
|
65
|
+
const buf = Buffer.alloc(BUFSIZE)
|
|
66
|
+
while (true) {
|
|
67
|
+
let bytesRead = 0
|
|
68
|
+
try {
|
|
69
|
+
bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE)
|
|
70
|
+
}
|
|
71
|
+
catch (ex) {
|
|
72
|
+
if (ex.code === "EAGAIN") continue
|
|
73
|
+
else if (ex.code === "EOF") break
|
|
74
|
+
else throw ex
|
|
75
|
+
}
|
|
76
|
+
if (bytesRead === 0)
|
|
77
|
+
break
|
|
78
|
+
input += buf.toString("utf8", 0, bytesRead)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (!fs.existsSync(inputFile)) {
|
|
83
|
+
console.error(chalk.red(`nunjucks: ERROR: failed to find input file: ${inputFile}`))
|
|
84
|
+
process.exit(1)
|
|
85
|
+
}
|
|
86
|
+
input = fs.readFileSync(inputFile, { encoding: "utf8" })
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* provide context variables for template */
|
|
90
|
+
let context = {}
|
|
91
|
+
if (argv.defines) {
|
|
92
|
+
try {
|
|
93
|
+
context = jsYAML.safeLoad(fs.readFileSync(argv.defines, { encoding: "utf8" }))
|
|
94
|
+
}
|
|
95
|
+
catch (ex) {
|
|
96
|
+
console.error(chalk.red(`nunjucks: ERROR: failed to load context YAML file: ${ex.toString()}`))
|
|
97
|
+
process.exit(1)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* expose environment variables to template */
|
|
102
|
+
context.env = process.env
|
|
103
|
+
|
|
104
|
+
/* add context defines */
|
|
105
|
+
if (argv.define) {
|
|
106
|
+
if (typeof argv.define === "string")
|
|
107
|
+
argv.define = [ argv.define ]
|
|
108
|
+
argv.define.forEach((define) => {
|
|
109
|
+
let [ , key, val ] = define.match(/^([^=]+)(?:=(.*))?$/)
|
|
110
|
+
if (val === undefined)
|
|
111
|
+
val = true
|
|
112
|
+
context[key] = val
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* determine Nunjucks options */
|
|
117
|
+
let options = {}
|
|
118
|
+
if (argv.config) {
|
|
119
|
+
try {
|
|
120
|
+
options = jsYAML.safeLoad(fs.readFileSync(argv.config, { encoding: "utf8" }))
|
|
121
|
+
}
|
|
122
|
+
catch (ex) {
|
|
123
|
+
console.error(chalk.red(`nunjucks: ERROR: failed to load options YAML file: ${ex.toString()}`))
|
|
124
|
+
process.exit(1)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
options = Object.assign({}, {
|
|
128
|
+
autoescape: true,
|
|
129
|
+
throwOnUndefined: false,
|
|
130
|
+
trimBlocks: true,
|
|
131
|
+
lstripBlocks: true,
|
|
132
|
+
watch: false,
|
|
133
|
+
noCache: true
|
|
134
|
+
}, options)
|
|
135
|
+
|
|
136
|
+
/* configure environment */
|
|
137
|
+
const env = nunjucks.configure(inputFile, options)
|
|
138
|
+
|
|
139
|
+
/* load external extension files */
|
|
140
|
+
if (typeof argv.extension === "object" && argv.extension instanceof Array) {
|
|
141
|
+
for (let extension of argv.extension) {
|
|
142
|
+
if (fs.existsSync(path.join(__dirname, "nunjucks.d", `${extension}.js`)))
|
|
143
|
+
extension = path.join(__dirname, "nunjucks.d", `${extension}.js`)
|
|
144
|
+
else if (!fs.existsSync(extension)) {
|
|
145
|
+
console.error(chalk.red(`nunjucks: ERROR: failed to find extension file: ${extension}`))
|
|
146
|
+
process.exit(1)
|
|
147
|
+
}
|
|
148
|
+
const ext = require(path.resolve(extension))
|
|
149
|
+
if (!(ext !== null && typeof ext === "function")) {
|
|
150
|
+
console.error(chalk.red(`nunjucks: ERROR: failed to call extension file: ${extension}`))
|
|
151
|
+
process.exit(1)
|
|
152
|
+
}
|
|
153
|
+
ext(env)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* render Nunjucks template */
|
|
158
|
+
let output
|
|
159
|
+
try {
|
|
160
|
+
output = env.renderString(input, context)
|
|
161
|
+
}
|
|
162
|
+
catch (ex) {
|
|
163
|
+
console.error(chalk.red(`nunjucks: ERROR: failed to render template: ${ex.toString()}`))
|
|
164
|
+
process.exit(1)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* write output */
|
|
168
|
+
if (argv.output === "-")
|
|
169
|
+
process.stdout.write(output)
|
|
170
|
+
else
|
|
171
|
+
fs.writeFileSync(argv.output, output, { encoding: "utf8" })
|
|
172
|
+
|
|
173
|
+
/* die gracefully */
|
|
174
|
+
process.exit(0)
|
|
175
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rse/nunjucks-cli",
|
|
3
|
+
"publishConfig": { "access": "public" },
|
|
4
|
+
"version": "0.9.5",
|
|
5
|
+
"description": "Nunjucks Template Rendering Command-Line Interface",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Dr. Ralf S. Engelschall",
|
|
8
|
+
"email": "rse@engelschall.com",
|
|
9
|
+
"url": "http://engelschall.com"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"bin": {
|
|
13
|
+
"nunjucks": "nunjucks.js"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"nunjucks": "3.2.4",
|
|
17
|
+
"chalk": "4.1.0",
|
|
18
|
+
"yargs": "17.7.2",
|
|
19
|
+
"moment": "2.29.4",
|
|
20
|
+
"moment-timezone": "0.5.43",
|
|
21
|
+
"js-yaml": "4.1.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"eslint": "8.47.0",
|
|
25
|
+
"eslint-config-standard": "17.1.0",
|
|
26
|
+
"eslint-plugin-promise": "6.1.1",
|
|
27
|
+
"eslint-plugin-import": "2.28.0",
|
|
28
|
+
"eslint-plugin-node": "11.1.0"
|
|
29
|
+
},
|
|
30
|
+
"upd": [ "!chalk" ],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"lint": "eslint --config eslint.yaml nunjucks.js",
|
|
33
|
+
"test": "echo 'Hello, {{who}}!' | node nunjucks.js -D who=world -"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/sample.txt
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
##
|
|
2
|
+
## Composefile -- Docker Compose Configuration
|
|
3
|
+
##
|
|
4
|
+
|
|
5
|
+
{% set WITH_SRV_NAME = default(WITH_SRV_NAME, "ASE-K3S", "string") %}
|
|
6
|
+
{% set WITH_SRV_DESC = default(WITH_SRV_DESC, "K3S Kubernetes Application Server (ASE)", "string") %}
|
|
7
|
+
|
|
8
|
+
{% set WITH_URL_SCHEME = default(WITH_URL_SCHEME, DOCKER_STACK_URL_SCHEME, "string") %}
|
|
9
|
+
{% set WITH_URL_HOST = default(WITH_URL_HOST, DOCKER_STACK_URL_HOST, "string") %}
|
|
10
|
+
{% set WITH_URL_MODE = default(WITH_URL_MODE, DOCKER_STACK_URL_MODE, "string") %}
|
|
11
|
+
{% set WITH_URL_PATH = default(WITH_URL_PATH, DOCKER_STACK_URL_PATH, "string") %}
|
|
12
|
+
|
|
13
|
+
{% set WITH_WORKERS = default(WITH_WORKERS, 3, "int") %}
|
|
14
|
+
{% set WITH_SMI = default(WITH_SMI, "no", "bool") %}
|
|
15
|
+
{% set WITH_FAAS = default(WITH_FAAS, "no", "bool") %}
|
|
16
|
+
|
|
17
|
+
version: "3.7"
|
|
18
|
+
|
|
19
|
+
services:
|
|
20
|
+
|
|
21
|
+
# the K3S Proxy service
|
|
22
|
+
ase-k3s-proxy:
|
|
23
|
+
container_name: ase-k3s-proxy
|
|
24
|
+
image: docker.msg.team/ps/std-nginx:1.19.3-20200930
|
|
25
|
+
init: true
|
|
26
|
+
restart: always
|
|
27
|
+
environment:
|
|
28
|
+
PROXY_SRV_NAME: {{ WITH_SRV_NAME }}
|
|
29
|
+
PROXY_SRV_DESC: {{ WITH_SRV_DESC }}
|
|
30
|
+
PROXY_URL_SCHEME: {{ WITH_URL_SCHEME }}
|
|
31
|
+
PROXY_URL_HOST: {{ WITH_URL_HOST }}
|
|
32
|
+
PROXY_URL_MODE: {{ WITH_URL_MODE }}
|
|
33
|
+
PROXY_URL_PATH: {{ WITH_URL_PATH }}
|
|
34
|
+
PROXY_DST_PATH: {{ WITH_URL_PATH }}
|
|
35
|
+
volumes:
|
|
36
|
+
- ./nginx.conf:/conf/nginx.conf:ro
|
|
37
|
+
networks:
|
|
38
|
+
proxy:
|
|
39
|
+
ase-k3s: { aliases: [ proxy ] }
|
|
40
|
+
depends_on:
|
|
41
|
+
- ase-k3s-server
|
|
42
|
+
|
|
43
|
+
# the K3S Server service
|
|
44
|
+
ase-k3s-server:
|
|
45
|
+
hostname: node0
|
|
46
|
+
container_name: ase-k3s-server
|
|
47
|
+
image: docker.msg.team/ps/ase-k3s:1.22.4-20211130
|
|
48
|
+
init: true
|
|
49
|
+
command: >-
|
|
50
|
+
server
|
|
51
|
+
--bind-address=0.0.0.0
|
|
52
|
+
--https-listen-port=6443
|
|
53
|
+
--kube-apiserver-arg=external-hostname={{ WITH_URL_HOST }}
|
|
54
|
+
--data-dir=/data/k3s
|
|
55
|
+
restart: always
|
|
56
|
+
privileged: true
|
|
57
|
+
environment:
|
|
58
|
+
K3S_PROXY_URL_MODE: {{ WITH_URL_MODE }}
|
|
59
|
+
K3S_CLUSTER_SECRET: "{{ WITH_CLUSTER_SECRET }}"
|
|
60
|
+
K3S_NODE_NAME: node0
|
|
61
|
+
K3S_KUBECONFIG_OUTPUT: /conf/kubeconfig.yaml
|
|
62
|
+
K3S_KUBECONFIG_MODE: 666
|
|
63
|
+
KUBECONFIG_SERVER_URL: "{{ WITH_URL_SCHEME }}://{{ WITH_URL_HOST }}{{ WITH_URL_PATH }}"
|
|
64
|
+
K3S_TOKEN: "foobar"
|
|
65
|
+
ports:
|
|
66
|
+
- 6443:6443
|
|
67
|
+
volumes:
|
|
68
|
+
- ase-k3s-server:/data
|
|
69
|
+
- ./manifest-1-root.yaml:/data/k3s/server/manifests/ase-k3s-1-root.yaml
|
|
70
|
+
{% if WITH_WORKERS > 0 %}
|
|
71
|
+
- ./local-storage.yaml.skip:/data/k3s/server/manifests/local-storage.yaml.skip
|
|
72
|
+
- ./manifest-2-csi.yaml:/data/k3s/server/manifests/ase-k3s-2-csi.yaml
|
|
73
|
+
{% endif %}
|
|
74
|
+
{% if WITH_SMI %}
|
|
75
|
+
- ./manifest-3-smi.yaml:/data/k3s/server/manifests/ase-k3s-3-smi.yaml
|
|
76
|
+
{% endif %}
|
|
77
|
+
{% if WITH_FAAS %}
|
|
78
|
+
- ./manifest-4-faas.yaml:/data/k3s/server/manifests/ase-k3s-4-kubeless.yaml
|
|
79
|
+
{% endif %}
|
|
80
|
+
- ./manifest-5-ui.yaml:/data/k3s/server/manifests/ase-k3s-5-ui.yaml
|
|
81
|
+
- ./ps-kubernetes-dashboard-0.0.0.tgz:/data/k3s/server/static/charts/ps-kubernetes-dashboard-0.0.0.tgz
|
|
82
|
+
networks:
|
|
83
|
+
ase-k3s: { aliases: [ node0, api ] }
|
|
84
|
+
{% if WITH_WORKERS > 0 %}
|
|
85
|
+
depends_on:
|
|
86
|
+
- ase-k3s-storage
|
|
87
|
+
{% endif %}
|
|
88
|
+
|
|
89
|
+
{% if WITH_WORKERS > 0 %}
|
|
90
|
+
|
|
91
|
+
# the K3S Node #1
|
|
92
|
+
{% for i in range(1, WITH_WORKERS + 1) %}
|
|
93
|
+
ase-k3s-node-{{ i }}:
|
|
94
|
+
hostname: node{{ i }}
|
|
95
|
+
container_name: ase-k3s-node-{{ i }}
|
|
96
|
+
image: docker.msg.team/ps/ase-k3s:1.22.4-20211130
|
|
97
|
+
init: true
|
|
98
|
+
command: >-
|
|
99
|
+
agent
|
|
100
|
+
--data-dir=/data/k3s
|
|
101
|
+
restart: always
|
|
102
|
+
privileged: true
|
|
103
|
+
environment:
|
|
104
|
+
K3S_URL: https://api:6443
|
|
105
|
+
K3S_NODE_NAME: node{{ i }}
|
|
106
|
+
K3S_TOKEN_FILE: /data-server/k3s/server/token
|
|
107
|
+
volumes:
|
|
108
|
+
- ase-k3s-node-{{ i }}:/data
|
|
109
|
+
- ase-k3s-server:/data-server
|
|
110
|
+
networks:
|
|
111
|
+
ase-k3s: { aliases: [ node{{ i }} ] }
|
|
112
|
+
depends_on:
|
|
113
|
+
- ase-k3s-server
|
|
114
|
+
- ase-k3s-storage
|
|
115
|
+
{% endfor %}
|
|
116
|
+
|
|
117
|
+
# the NFS storage service
|
|
118
|
+
ase-k3s-storage:
|
|
119
|
+
hostname: nfs
|
|
120
|
+
container_name: ase-k3s-storage
|
|
121
|
+
image: docker.msg.team/ps/std-nfs:12-20200111
|
|
122
|
+
init: true
|
|
123
|
+
restart: always
|
|
124
|
+
privileged: true
|
|
125
|
+
environment:
|
|
126
|
+
SHARED_DIRECTORY: /data/k3s
|
|
127
|
+
volumes:
|
|
128
|
+
- ase-k3s-storage:/data
|
|
129
|
+
networks:
|
|
130
|
+
ase-k3s: { aliases: [ nfs ] }
|
|
131
|
+
|
|
132
|
+
{% endif %}
|
|
133
|
+
|
|
134
|
+
volumes:
|
|
135
|
+
ase-k3s-server:
|
|
136
|
+
name: ase-k3s-server
|
|
137
|
+
{% if WITH_WORKERS > 0 %}
|
|
138
|
+
{% for i in range(1, WITH_WORKERS + 1) %}
|
|
139
|
+
ase-k3s-node-{{ i }}:
|
|
140
|
+
name: ase-k3s-node-{{ i }}
|
|
141
|
+
{% endfor %}
|
|
142
|
+
ase-k3s-storage:
|
|
143
|
+
name: ase-k3s-storage
|
|
144
|
+
{% endif %}
|
|
145
|
+
|
|
146
|
+
networks:
|
|
147
|
+
proxy:
|
|
148
|
+
name: proxy
|
|
149
|
+
external: true
|
|
150
|
+
ase-k3s:
|
|
151
|
+
name: ase-k3s
|
|
152
|
+
driver: bridge
|
|
153
|
+
|