diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bc48452 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM clojure:openjdk-17-lein as build-env + +ADD . /app +WORKDIR /app + +RUN lein uberjar + +# ----------------------------------------------------------------------------- + +from openjdk:17 + +RUN groupadd -r ymlgen && useradd -r -s /bin/false -g ymlgen ymlgen +RUN mkdir /app +COPY --from=build-env /app/target/uberjar/ymlgen-*-standalone.jar /app/ymlgen.jar + +RUN chown -R ymlgen:ymlgen /app + +user ymlgen + +ENTRYPOINT ["java", "-jar", "/app/ymlgen.jar"] diff --git a/README.md b/README.md index 906d17b..8f564d8 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,18 @@ It supports including parts of definitions into other ones, variables, generatin The tool leverages the [EDN](https://github.com/edn-format/edn) format and the [Aero](https://github.com/juxt/aero) library. Why `ymlgen` ? It's simple, powerful and extensible. +I think neither templating or using YAML to generate more YAML are good solutions to manage Kubernetes resources and that's why I built this tool. ## Install -For Linux (x86-64), download the `ymlgen` binary and put it in your PATH. This binary is built using [GraalVM](https://www.graalvm.org/) so more targets may be added soon (help welcome). +For Linux (x86-64), download the `ymlgen` binary from the [release page](https://github.com/mcorbin/ymlgen/releases) and put it in your PATH. This binary is built using [GraalVM](https://www.graalvm.org/), more targets may be added soon (help welcome). You can alternatively download the `jar` file and then run it with `java -jar ymlgen.jar` (Java 17 needed). +A docker image is also provided. Note that this image uses `java` as well so executing it is a bit slower than the static binary built with GraalVM. + +All example described below can be done using the Docker image by executing in the directory containing your templates `docker run -v $(pwd):/data mcorbin/ymlgen:v0.1.0 `. The files will be availables in `/data`. + ## Quick start ### Simple EDN example @@ -21,6 +26,7 @@ You can alternatively download the `jar` file and then run it with `java -jar ym Once `ymlgen` installed, you are ready to use it. Let's for example generate a yaml file from a simple EDN definition. Put in `pod.edn` this content: ```clojure +;; this is a comment {:apiVersion "v1" :kind "Pod" :metadata {:name "dnsutils" diff --git a/release.sh b/release.sh index 4066072..8a1aa6c 100755 --- a/release.sh +++ b/release.sh @@ -9,8 +9,10 @@ lein test git add . git commit -m "release ${tag}" git tag -a "${tag}" -m "release ${tag}" -lein uberjar +docker build -t mcorbin/ymlgen:${tag} . +docker push mcorbin/ymlgen:${tag} +lein uberjar native-image --report-unsupported-elements-at-runtime \ --initialize-at-build-time \ --no-server \ diff --git a/src/ymlgen/commands/yaml.clj b/src/ymlgen/commands/yaml.clj index af7393c..b25a51c 100644 --- a/src/ymlgen/commands/yaml.clj +++ b/src/ymlgen/commands/yaml.clj @@ -48,4 +48,5 @@ (let [result (gen-yaml config)] (if output-path (spit output-path result) - (println result)))) + (do (print result) + (flush)))))