Skip to content

Commit

Permalink
feat: add dockerfile (#8)
Browse files Browse the repository at this point in the history
* Define 'release' profile
* Dockerfile to build `tera-cli` image
* Document how to build `tera cli` container
* Update markdown README file
  • Loading branch information
tandiljuan authored Sep 7, 2021
1 parent 592f365 commit a9f5ddd
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything
*
# With the exception of
!src/**
!Cargo*
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ license-file = ["LICENSE", "0"]
maintainer = "Wilfried Kopp aka. Chevdor <chevdor@gmail.com>"
priority = "optional"
section = "utility"

[profile.release]
codegen-units = 1
lto = true
opt-level = "z"
panic = "abort"
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions README_src.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a9f5ddd

Please sign in to comment.