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

Docker entrypoint functions #762

Open
wants to merge 5 commits 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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ WORKDIR /final

# Strip the binary from debug symbols to reduce size
RUN bin=$(find /project/dist-newstyle -name "$APP" -type f -executable) && \
mv "$bin" ./ && \
strip ./"$APP" &&\
mv /project/scripts/docker/entrypoint-"$APP" ./entrypoint
install --strip -t . "$bin" && \
install -m 'a=r' -t . /project/scripts/docker/*.sh && \
install -T /project/scripts/docker/entrypoint-"$APP" ./entrypoint

### Final stage
FROM ubuntu:${TAG}
Expand Down
32 changes: 10 additions & 22 deletions scripts/docker/entrypoint-smp-server
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
confd='/etc/opt/simplex'
logd='/var/opt/simplex/'

# Avoid a search of PATH
_shd="$(dirname "$0")"
: "${_shd:=/usr/local/bin}"
. "${_shd}/functions.sh"
unset -v _shd

# Check if server has been initialized
if [ ! -f "${confd}/smp-server.ini" ]; then
# If not, determine ip or domain
case "${ADDR}" in
'') printf 'Please specify $ADDR environment variable.\n'; exit 1 ;;
*[a-zA-Z]*)
case "${ADDR}" in
*:*) set -- --ip "${ADDR}" ;;
*) set -- -n "${ADDR}" ;;
esac
;;
*) set -- --ip "${ADDR}" ;;
esac
_arg1="$(print_arg_from_env_addr)" || exit 1
set -- "${_arg1}" "${ADDR}"
unset -v _arg1

# Optionally, set password
case "${PASS}" in
Expand All @@ -28,19 +27,8 @@ fi

# Backup store log just in case
#
# Uses the UTC (universal) time zone and this
# format: YYYY-mm-dd'T'HH:MM:SS
# year, month, day, letter T, hour, minute, second
#
# This is the ISO 8601 format without the time zone at the end.
#
_file="${logd}/smp-server-store.log"
if [ -f "${_file}" ]; then
_backup_extension="$(date -u '+%Y-%m-%dT%H:%M:%S')"
cp -v -p "${_file}" "${_file}.${_backup_extension:-date-failed}"
unset -v _backup_extension
fi
unset -v _file
backup_file_iso8601 "${logd}/smp-server-store.log"

# Finally, run smp-sever. Notice that "exec" here is important:
# smp-server replaces our helper script, so that it can catch INT signal
Expand Down
34 changes: 11 additions & 23 deletions scripts/docker/entrypoint-xftp-server
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
confd='/etc/opt/simplex-xftp'
logd='/var/opt/simplex-xftp'

# Avoid a search of PATH
_shd="$(dirname "$0")"
: "${_shd:=/usr/local/bin}"
. "${_shd}/functions.sh"
unset -v _shd

# Check if server has been initialized
if [ ! -f "${confd}/file-server.ini" ]; then
# If not, determine ip or domain
case "${ADDR}" in
'') printf 'Please specify $ADDR environment variable.\n'; exit 1 ;;
*[a-zA-Z]*)
case "${ADDR}" in
*:*) set -- --ip "${ADDR}" ;;
*) set -- -n "${ADDR}" ;;
esac
;;
*) set -- --ip "${ADDR}" ;;
esac
_arg1="$(print_arg_from_env_addr)" || exit 1
set -- "${_arg1}" "${ADDR}"
unset -v _arg1

# Set quota
case "${QUOTA}" in
'') printf 'Please specify $QUOTA environment variable.\n'; exit 1 ;;
'') print_to_stderr 'Please specify $QUOTA environment variable.'; exit 1 ;;
*) set -- "$@" --quota "${QUOTA}" ;;
esac

Expand All @@ -28,19 +27,8 @@ fi

# Backup store log just in case
#
# Uses the UTC (universal) time zone and this
# format: YYYY-mm-dd'T'HH:MM:SS
# year, month, day, letter T, hour, minute, second
#
# This is the ISO 8601 format without the time zone at the end.
#
_file="${logd}/file-server-store.log"
if [ -f "${_file}" ]; then
_backup_extension="$(date -u '+%Y-%m-%dT%H:%M:%S')"
cp -v -p "${_file}" "${_file}.${_backup_extension:-date-failed}"
unset -v _backup_extension
fi
unset -v _file
backup_file_iso8601 "${logd}/file-server-store.log"

# Finally, run xftp-sever. Notice that "exec" here is important:
# smp-server replaces our helper script, so that it can catch INT signal
Expand Down
41 changes: 41 additions & 0 deletions scripts/docker/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env sh

print_to_stderr() {
# Print each argument as a separate line
printf -- '%s\n' "$@" 1>&2
}

print_arg() {
printf -- '%s' "$1"
}

print_arg_from_env_addr() {
# Determine IP or domain name
case "${ADDR}" in
'') print_to_stderr 'Please specify $ADDR environment variable.'; return 1 ;;
*[a-zA-Z]*)
case "${ADDR}" in
*:*) print_arg --ip ;;
*) print_arg -n ;;
esac
;;
*) print_arg --ip ;;
esac
return 0
}

# Uses the UTC (universal) time zone and this
# format: YYYY-mm-dd'T'HH:MM:SS
# year, month, day, letter T, hour, minute, second
#
# This is the ISO 8601 format without the time zone at the end.
backup_file_iso8601() {
for _file in "$@"; do
if [ -f "${_file}" ]; then
_backup_extension="$(date -u '+%Y-%m-%dT%H:%M:%S')"
cp -v -p "${_file}" "${_file}.${_backup_extension:-date-failed}"
unset -v _backup_extension
fi
done
unset -v _file
}