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

Added options to dockerfile to allow for use of commandline options #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ LABEL org.opencontainers.image.authors="Marcin Sztolcman <[email protected]>"

ARG VERSION=2.2.2

USER root
RUN addgroup -S sendria && adduser -S sendria -G sendria
WORKDIR /home/sendria
RUN apk add --no-cache --upgrade bash
RUN apk --update --no-cache --virtual build-dependencies add apache2-utils
USER sendria
WORKDIR /home/sendria
RUN python3 -m pip install --user sendria==$VERSION
ENV PATH="/home/sendria/.local/bin:$PATH"
ENV SENDRIA_DATA_DIR="/home/sendria/data"
ADD tools /home/sendria/tools

EXPOSE 1025 1080

ENTRYPOINT [ "sendria", "--foreground", "--db=./mails.sqlite", "--smtp-ip=0.0.0.0", "--http-ip=0.0.0.0" ]
ENTRYPOINT [ "/home/sendria/tools/docker-entrypoint.sh" ]
86 changes: 86 additions & 0 deletions tools/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

declare -a cmd_opts

# Make the data directory if it doesn't yet exist:
if [[ ! -d $SENDRIA_DATA_DIR ]]; then
mkdir -p $SENDRIA_DATA_DIR
fi

### set any command line options that need setting:

if [[ -n $DB_PATH ]] && [[ $DB_PATH =~ \.sqlite$ ]]; then
# Full path given
cmd_opts+=("--db=${DB_PATH}")
elif [[ -n $DB_PATH ]] && [[ ! $DB_PATH =~ \.sqlite$ ]] && [[ ! $DB_PATH =~ \/$ ]]; then
# No db file and no trailing slash
cmd_opts+=("--db=${DB_PATH}/mail.sqlite")
elif [[ -n $DB_PATH ]] && [[ ! $DB_PATH =~ \.sqlite$ ]] && [[ $DB_PATH =~ \/$ ]]; then
# No db file but with trailing slash
cmd_opts+=("--db=${DB_PATH}mail.sqlite")
else
cmd_opts+=("--db=${SENDRIA_DATA_DIR}/mail.sqlite")
fi

if [[ -n $SMTP_USER ]] && [[ -n $SMTP_PASS ]]; then
# Both username and password given
htpasswd -bBc ${SENDRIA_DATA_DIR}/.smtp.htpasswd $SMTP_USER $SMTP_PASS
# echo "${SMTP_USER}:$(openssl passwd -5 ${SMTP_PASS})" >> ${SENDRIA_DATA_DIR}/.smtp.htpasswd
cmd_opts+=("--smtp-auth=${SENDRIA_DATA_DIR}/.smtp.htpasswd")
elif [[ -z $SMTP_USER ]] && [[ -n $SMTP_PASS ]]; then
# Only password given
# echo "smtp-user:$(openssl passwd -5 ${SMTP_PASS})" >> ${SENDRIA_DATA_DIR}/.smtp.htpasswd
htpasswd -bBc ${SENDRIA_DATA_DIR}/.smtp.htpasswd smtp-user $SMTP_PASS
cmd_opts+=("--smtp-auth=${SENDRIA_DATA_DIR}/.smtp.htpasswd")
elif [[ -n $SMTP_USER ]] && [[ -z $SMTP_PASS ]]; then
# Only username given
echo "smtp-user:" > ${SENDRIA_DATA_DIR}/.smtp.htpasswd
cmd_opts+=("--smtp-auth=${SENDRIA_DATA_DIR}/.smtp.htpasswd")
fi

if [[ -n $HTTP_USER ]] && [[ -n $HTTP_PASS ]]; then
# Both username and password given
# echo "${HTTP_USER}:$(openssl passwd -5 ${HTTP_PASS})" >> ${SENDRIA_DATA_DIR}/.http.htpasswd
htpasswd -bBc ${SENDRIA_DATA_DIR}/.http.htpasswd $HTTP_USER $HTTP_PASS
cmd_opts+=("--http-auth=${SENDRIA_DATA_DIR}/.http.htpasswd")
elif [[ -z $HTTP_USER ]] && [[ -n $HTTP_PASS ]]; then
# Only password given
# echo "admin:$(openssl passwd -5 ${HTTP_PASS})" >> ${SENDRIA_DATA_DIR}/.http.htpasswd
htpasswd -bBc ${SENDRIA_DATA_DIR}/.http.htpasswd admin $HTTP_PASS
cmd_opts+=("--http-auth=${SENDRIA_DATA_DIR}/.http.htpasswd")
elif [[ -n $HTTP_USER ]] && [[ -z $HTTP_PASS ]]; then
# Only username given
echo "admin:" > ${SENDRIA_DATA_DIR}/.http.htpasswd
cmd_opts+=("--http-auth=${SENDRIA_DATA_DIR}/.http.htpasswd")
fi

if [[ $DEBUG =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
cmd_opts+=("-d")
fi

if [[ $NO_QUIT =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
cmd_opts+=("-n")
fi

if [[ $NO_CLEAR =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
cmd_opts+=("-c")
fi

if [[ -n $TEMPLATE_NAME ]]; then
cmd_opts+=("--template-header-name=$TEMPLATE_NAME")
fi

if [[ -n $TEMPLATE_URL ]]; then
cmd_opts+=("--template-header-url=$TEMPLATE_URL")
fi


# Run the command that needs running:
unset SMTP_PASS HTTP_PASS
echo "${cmd_opts[@]}"
if [[ -n $LOG_FILE ]]; then
sendria --foreground --smtp-ip=0.0.0.0 --http-ip=0.0.0.0 "${cmd_opts[@]}" | tee -a $LOG_FILE
else
sendria --foreground --smtp-ip=0.0.0.0 --http-ip=0.0.0.0 "${cmd_opts[@]}"
fi
exit $?