Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: dockerfile #8

Merged
merged 4 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>"
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