Skip to content

Instantly share code, notes, and snippets.

@abdennour
Created June 27, 2020 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdennour/93b805209092e27b0adf970022664f4a to your computer and use it in GitHub Desktop.
Save abdennour/93b805209092e27b0adf970022664f4a to your computer and use it in GitHub Desktop.
Encrypt tar gz file in Dockerfile

build it

docker build --build-arg KEY=myKey -t encrypted 

Run it

instance=$(docker run -v $(pwd):/code -e DEST=/code -e KEY=myKey -w /code -d encrypted)
docker exec -it $instance ls /code
FROM alpine:3.12
RUN apk add --update --no-cache openssl
WORKDIR /src
COPY . .
WORKDIR /dest
ARG KEY
ENV KEY=${KEY}
# compress them &&
RUN tar -C /src -cvzf clear.tgz . &&\
openssl enc -aes-256-cbc -in clear.tgz -out notclear.tgz.enc -pass env:KEY && \
rm -rf /src && unset KEY && rm -rf clear.tgz
COPY entrypoint /bin/entrypoint
ENTRYPOINT ["sh", "/bin/entrypoint"]
#!/bin/sh
if [ -d "${DEST}" ]; then
openssl enc -aes-256-cbc -d -in /dest/notclear.tgz.enc -out /dest/notclear.tgz -pass env:PROT
tar -C ${DEST} -xzvf /dest/notclear.tgz
fi
if [ $# -eq 0 ]; then
echo "CMD is empty ${@}"
exec tail -f /dev/null
else
echo "CMD is considered ${@}"
exec $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment