From 14df7227faf20cf0a76cf1e2abc51a00d1eb2a82 Mon Sep 17 00:00:00 2001 From: Juan Manuel Lopez Date: Tue, 31 Aug 2021 20:30:28 -0300 Subject: [PATCH 1/4] Define 'release' profile --- Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index d2562f7..b1d1931 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,9 @@ license-file = ["LICENSE", "0"] maintainer = "Wilfried Kopp aka. Chevdor " priority = "optional" section = "utility" + +[profile.release] +codegen-units = 1 +lto = true +opt-level = "z" +panic = "abort" From 5bf316dfbd9d87a9d15ce66ac2379fa48476b473 Mon Sep 17 00:00:00 2001 From: Juan Manuel Lopez Date: Tue, 31 Aug 2021 20:11:16 -0300 Subject: [PATCH 2/4] Dockerfile to build `tera-cli` image --- .dockerignore | 5 +++++ Dockerfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6f89c1b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# Ignore everything +* +# With the exception of +!src/** +!Cargo* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e8c36e8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM rust:1.54.0-slim-buster as builder + +ARG DEBIAN_FRONTEND=noninteractive + +# ****************************************************************************** +# Install dependencies +# ****************************************************************************** +RUN set -eux \ + && apt-get update \ + && apt-get install --no-install-recommends --no-install-suggests --yes \ + upx-ucl \ + && apt-get autoremove --purge \ + && apt-get autoclean \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && echo ">>> FINISHED DEPENDENCIES INSTALL" + +# ****************************************************************************** +# Copy source code into container +# ****************************************************************************** +COPY . /opt/ + +# ****************************************************************************** +# Compile tera cli application from source +# ****************************************************************************** +RUN set -eux \ + && cd /opt/ \ + && rustup target add x86_64-unknown-linux-musl \ + && cargo build --release --target x86_64-unknown-linux-musl \ + && upx --best --lzma target/x86_64-unknown-linux-musl/release/tera \ + && mv target/x86_64-unknown-linux-musl/release/tera /usr/bin/ \ + && tera --version \ + && rm -rf target \ + && echo ">>> FINISHED COMPILING 'tera-cli'" + +# ------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ + +FROM alpine + +# ****************************************************************************** +# Install compiled tera cli +# ****************************************************************************** +COPY --from=builder /usr/bin/tera /usr/bin/tera + +USER guest + +WORKDIR /opt + +ENTRYPOINT ["/usr/bin/tera"] From b2f1235b05fdb3f5e106cf62f6a2b2c484ccd14d Mon Sep 17 00:00:00 2001 From: Juan Manuel Lopez Date: Thu, 2 Sep 2021 23:15:39 -0300 Subject: [PATCH 3/4] Document how to build `tera cli` container --- README_src.adoc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README_src.adoc b/README_src.adoc index b940fce..e9d423b 100644 --- a/README_src.adoc +++ b/README_src.adoc @@ -56,6 +56,25 @@ The **tera** engine allows way more than the simple replacements shown above. Yo cargo install --git https://github.com/chevdor/tera-cli +== Execute as Docker container + +=== Build container image + + docker build --tag 'tera-cli' . + +=== Execute `tera` from the Docker container + +Check tera help + + docker run -it --rm tera-cli --help + +Parse a template + + docker run -it --rm \ + --volume="$(pwd):/opt" \ + --env=FOO=BAR \ + tera-cli --template templates/env-debug.txt --env-only --env-key env + == What can I do with that anyway ? Well... if you have **data** and you want to format them, this tool will likely be a great companion. From 3695e89289dc3881ef5c7059d3e487ccdb6fadc2 Mon Sep 17 00:00:00 2001 From: Juan Manuel Lopez Date: Sun, 5 Sep 2021 10:02:26 -0300 Subject: [PATCH 4/4] Update markdown README file --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index fb0caea..fdd35d9 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,25 @@ The **tera** engine allows way more than the simple replacements shown above. Yo cargo install --git https://github.com/chevdor/tera-cli +## Execute as Docker container + +### Build container image + + docker build --tag 'tera-cli' . + +### Execute `tera` from the Docker container + +Check tera help + + docker run -it --rm tera-cli --help + +Parse a template + + docker run -it --rm \ + --volume="$(pwd):/opt" \ + --env=FOO=BAR \ + tera-cli --template templates/env-debug.txt --env-only --env-key env + ## What can I do with that anyway ? Well…​ if you have **data** and you want to format them, this tool will likely be a great companion.