From b52ab46be4e4413511c8a312a6b540139238e770 Mon Sep 17 00:00:00 2001 From: Nicolas K Date: Mon, 6 Nov 2023 16:03:42 +0100 Subject: [PATCH] Add resources to build a docker image --- README.md | 4 +++ contrib/docker/Dockerfile | 14 ++++++++++ contrib/docker/build-docker-image.sh | 41 ++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 contrib/docker/Dockerfile create mode 100755 contrib/docker/build-docker-image.sh diff --git a/README.md b/README.md index b1ddfc7..a1d31e5 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,10 @@ $ make install To build ACMEd and tacd inside a temporary Docker container, use the `contrib/docker/build-docker.sh` helper script. It currently supports Debian Buster / Stretch. +You can also build a container image for some k8s deployement, use the `contrib/docker/build-docker-image.sh` script. It supports the same targets as the build-docker.sh script. + +When build succeed, you can start the container with `docker run --rm -v /path/to/conf/dir:/etc/acmed acmed:buster`. + ### Advanced options You can specify a space or comma separated list of features to activate in the `FEATURE` variable. The possible features are: diff --git a/contrib/docker/Dockerfile b/contrib/docker/Dockerfile new file mode 100644 index 0000000..2e90d9e --- /dev/null +++ b/contrib/docker/Dockerfile @@ -0,0 +1,14 @@ +ARG TARGET=buster + +FROM rust:1-$TARGET as builder + +WORKDIR /code +COPY . . +RUN cargo build --release + +FROM debian:$TARGET-slim + +RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/* +COPY --from=builder /code/target/release/acmed /usr/local/bin/acmed +COPY --from=builder /code/target/release/tacd /usr/local/bin/tacd +CMD ["/usr/local/bin/acmed", "-f", "--log-stderr"] \ No newline at end of file diff --git a/contrib/docker/build-docker-image.sh b/contrib/docker/build-docker-image.sh new file mode 100755 index 0000000..2486f64 --- /dev/null +++ b/contrib/docker/build-docker-image.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -euo pipefail + +DIR="$( cd "$( dirname "$0" )/../.." >/dev/null 2>&1 && pwd )" + +# Parse command line args +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + echo "Supported targets: stretch, buster" + exit 1 +fi +if [ "$1" == "buster" ]; then + TARGET=buster +elif [ "$1" == "stretch" ]; then + TARGET=stretch +else + echo "Invalid target: $1" + exit 1 +fi + +# Determine image +IMAGE=rust:1-$TARGET + +function log { + echo -e "\033[32;1m==> ${1}\033[0m" +} + +# This or commit Dockerfile at project root +log "Prepare docker build" +cp $( dirname "$0" )/Dockerfile $DIR + +cd $DIR + +log "Build docker image" +docker build -t acmed:$TARGET --build-arg TARGET=$TARGET . + +log "Successfully built image, Cleanup" + +rm Dockerfile + +log "Done! Find your binaries in the /usr/local/bin directory of image acmed:$TARGET."