Skip to content

Commit a9f5ddd

Browse files
authored
feat: add dockerfile (#8)
* Define 'release' profile * Dockerfile to build `tera-cli` image * Document how to build `tera cli` container * Update markdown README file
1 parent 592f365 commit a9f5ddd

5 files changed

Lines changed: 99 additions & 0 deletions

File tree

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore everything
2+
*
3+
# With the exception of
4+
!src/**
5+
!Cargo*

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ license-file = ["LICENSE", "0"]
3737
maintainer = "Wilfried Kopp aka. Chevdor <chevdor@gmail.com>"
3838
priority = "optional"
3939
section = "utility"
40+
41+
[profile.release]
42+
codegen-units = 1
43+
lto = true
44+
opt-level = "z"
45+
panic = "abort"

Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM rust:1.54.0-slim-buster as builder
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
# ******************************************************************************
6+
# Install dependencies
7+
# ******************************************************************************
8+
RUN set -eux \
9+
&& apt-get update \
10+
&& apt-get install --no-install-recommends --no-install-suggests --yes \
11+
upx-ucl \
12+
&& apt-get autoremove --purge \
13+
&& apt-get autoclean \
14+
&& apt-get clean \
15+
&& rm -rf /var/lib/apt/lists/* \
16+
&& echo ">>> FINISHED DEPENDENCIES INSTALL"
17+
18+
# ******************************************************************************
19+
# Copy source code into container
20+
# ******************************************************************************
21+
COPY . /opt/
22+
23+
# ******************************************************************************
24+
# Compile tera cli application from source
25+
# ******************************************************************************
26+
RUN set -eux \
27+
&& cd /opt/ \
28+
&& rustup target add x86_64-unknown-linux-musl \
29+
&& cargo build --release --target x86_64-unknown-linux-musl \
30+
&& upx --best --lzma target/x86_64-unknown-linux-musl/release/tera \
31+
&& mv target/x86_64-unknown-linux-musl/release/tera /usr/bin/ \
32+
&& tera --version \
33+
&& rm -rf target \
34+
&& echo ">>> FINISHED COMPILING 'tera-cli'"
35+
36+
# ------------------------------------------------------------------------------
37+
# ------------------------------------------------------------------------------
38+
39+
FROM alpine
40+
41+
# ******************************************************************************
42+
# Install compiled tera cli
43+
# ******************************************************************************
44+
COPY --from=builder /usr/bin/tera /usr/bin/tera
45+
46+
USER guest
47+
48+
WORKDIR /opt
49+
50+
ENTRYPOINT ["/usr/bin/tera"]

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ The **tera** engine allows way more than the simple replacements shown above. Yo
7575

7676
cargo install --git https://github.com/chevdor/tera-cli
7777

78+
## Execute as Docker container
79+
80+
### Build container image
81+
82+
docker build --tag 'tera-cli' .
83+
84+
### Execute `tera` from the Docker container
85+
86+
Check tera help
87+
88+
docker run -it --rm tera-cli --help
89+
90+
Parse a template
91+
92+
docker run -it --rm \
93+
--volume="$(pwd):/opt" \
94+
--env=FOO=BAR \
95+
tera-cli --template templates/env-debug.txt --env-only --env-key env
96+
7897
## What can I do with that anyway ?
7998

8099
Well…​ if you have **data** and you want to format them, this tool will likely be a great companion.

README_src.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ The **tera** engine allows way more than the simple replacements shown above. Yo
5656

5757
cargo install --git https://github.com/chevdor/tera-cli
5858

59+
== Execute as Docker container
60+
61+
=== Build container image
62+
63+
docker build --tag 'tera-cli' .
64+
65+
=== Execute `tera` from the Docker container
66+
67+
Check tera help
68+
69+
docker run -it --rm tera-cli --help
70+
71+
Parse a template
72+
73+
docker run -it --rm \
74+
--volume="$(pwd):/opt" \
75+
--env=FOO=BAR \
76+
tera-cli --template templates/env-debug.txt --env-only --env-key env
77+
5978
== What can I do with that anyway ?
6079

6180
Well... if you have **data** and you want to format them, this tool will likely be a great companion.

0 commit comments

Comments
 (0)