large overhaul of docker run script
This commit is contained in:
parent
7d4eaa11e7
commit
9bc53e45cd
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"LibationFiles": "/config"
|
"LibationFiles": "/config-internal"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,50 +1,124 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Rewire echo to print date time
|
error() {
|
||||||
echo() {
|
log "ERROR" "$1"
|
||||||
if [[ -n $1 ]]; then
|
}
|
||||||
printf "$(date '+%F %T'): %s\n" "$1"
|
|
||||||
|
warn() {
|
||||||
|
log "WARNING" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
log "info" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
debug() {
|
||||||
|
log "debug" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
LEVEL=$1
|
||||||
|
MESSAGE=$2
|
||||||
|
printf "$(date '+%F %T') %s: %s\n" "${LEVEL}" "${MESSAGE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
init_config_file() {
|
||||||
|
FILE=$1
|
||||||
|
FULLPATH=${LIBATION_CONFIG_DIR}/${FILE}
|
||||||
|
if [ -f ${FULLPATH} ]; then
|
||||||
|
info "loading ${FILE}"
|
||||||
|
cp ${FULLPATH} ${LIBATION_CONFIG_INTERNAL}/
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
warn "${FULLPATH} not found, using defaults"
|
||||||
|
echo "{}" > ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ################################
|
update_settings() {
|
||||||
# Setup
|
FILE=$1
|
||||||
# ################################
|
KEY=$2
|
||||||
echo "Starting"
|
VALUE=$3
|
||||||
if [[ -z "${SLEEP_TIME}" ]]; then
|
info "setting ${KEY} to ${VALUE}"
|
||||||
echo "No sleep time passed in. Will run once and exit."
|
echo $(jq --arg k "${KEY}" --arg v "${VALUE}" '.[$k] = $v' ${LIBATION_CONFIG_INTERNAL}/${FILE}) > ${LIBATION_CONFIG_INTERNAL}/${FILE}.tmp
|
||||||
|
mv ${LIBATION_CONFIG_INTERNAL}/${FILE}.tmp ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
||||||
|
}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
info "scanning accounts"
|
||||||
|
/libation/LibationCli scan
|
||||||
|
info "liberating books"
|
||||||
|
/libation/LibationCli liberate
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
# TERM isn't set by default in docker images
|
||||||
|
if [[ -z ${TERM} || ${TERM} = "dumb" ]]; then
|
||||||
|
TERM=xterm-256color
|
||||||
|
fi
|
||||||
|
|
||||||
|
info ${TERM}
|
||||||
|
|
||||||
|
info "initializing libation"
|
||||||
|
init_config_file AccountsSettings.json
|
||||||
|
init_config_file Settings.json
|
||||||
|
|
||||||
|
info "loading settings"
|
||||||
|
update_settings Settings.json Books /data
|
||||||
|
update_settings Settings.json InProgress /tmp
|
||||||
|
|
||||||
|
# If user provides a separate database use that
|
||||||
|
info "loading database"
|
||||||
|
FILE=LibationContext.db
|
||||||
|
if [ -f "${LIBATION_DB_DIR}/${FILE}" ]; then
|
||||||
|
info "database found in ${LIBATION_DB_DIR}"
|
||||||
|
ln -s /${LIBATION_DB_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
||||||
|
# If user provides database in config use that
|
||||||
|
elif [ -f "${LIBATION_CONFIG_DIR}/${FILE}" ]; then
|
||||||
|
info "database found in ${LIBATION_CONFIG_DIR}"
|
||||||
|
ln -s /${LIBATION_CONFIG_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
||||||
|
# We didn't get a database
|
||||||
else
|
else
|
||||||
echo "Sleep time is set to ${SLEEP_TIME}"
|
warn "no database found, creating one in ${LIBATION_CONFIG_DIR}"
|
||||||
|
if ! touch ${LIBATION_CONFIG_DIR}/${FILE}; then
|
||||||
|
error "unable to create database, check permissions on host"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
ln -s ${LIBATION_CONFIG_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
# Try to warn if books dir wasn't mounted in
|
||||||
|
if [ -z "$(mount | grep ${LIBATION_BOOKS_DIR})" ]
|
||||||
# If user passes in db from a /db/ folder and a db does not already exist / is not already linked
|
then
|
||||||
FILE=/db/LibationContext.db
|
warn "${LIBATION_BOOKS_DIR} does not appear to be mounted, books will not be saved"
|
||||||
if [ -f "${FILE}" ] && [ ! -f "/config/LibationContext.db" ]; then
|
|
||||||
echo "Linking passed in Libation database from /db/ to the Libation config directory"
|
|
||||||
ln -s $FILE /config/LibationContext.db
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ################################
|
# Let the user know what the run type will be
|
||||||
# Loop and liberate
|
if [[ -z "${SLEEP_TIME}" ]]; then
|
||||||
# ################################
|
SLEEP_TIME=-1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${SLEEP_TIME}" = -1 ]; then
|
||||||
|
info "running once"
|
||||||
|
else
|
||||||
|
info "running every ${SLEEP_TIME}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# loop
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
echo ""
|
run
|
||||||
echo "Scanning accounts"
|
|
||||||
/libation/LibationCli scan
|
|
||||||
echo "Liberating books"
|
|
||||||
/libation/LibationCli liberate
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Liberate only once if SLEEP_TIME was set to -1
|
# Liberate only once if SLEEP_TIME was set to -1
|
||||||
if [ "${SLEEP_TIME}" = -1 ]; then
|
if [ "${SLEEP_TIME}" = -1 ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Sleeping for ${SLEEP_TIME}"
|
|
||||||
sleep "${SLEEP_TIME}"
|
sleep "${SLEEP_TIME}"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Exiting"
|
info "exiting"
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
|
|||||||
21
Dockerfile
21
Dockerfile
@ -3,25 +3,28 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
|
|||||||
|
|
||||||
COPY Source /Source
|
COPY Source /Source
|
||||||
RUN dotnet publish -c Release -o /Source/bin/Publish/Linux-chardonnay /Source/LibationCli/LibationCli.csproj -p:PublishProfile=/Source/LibationCli/Properties/PublishProfiles/LinuxProfile.pubxml
|
RUN dotnet publish -c Release -o /Source/bin/Publish/Linux-chardonnay /Source/LibationCli/LibationCli.csproj -p:PublishProfile=/Source/LibationCli/Properties/PublishProfiles/LinuxProfile.pubxml
|
||||||
COPY Docker/liberate.sh /Source/bin/Publish/Linux-chardonnay
|
|
||||||
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/runtime:8.0
|
FROM mcr.microsoft.com/dotnet/runtime:8.0
|
||||||
ARG USER_UID=1001
|
ARG USER_UID=1001
|
||||||
|
ARG USER_GID=1001
|
||||||
|
|
||||||
ENV SLEEP_TIME=30m
|
|
||||||
|
|
||||||
# Set the character set that will be used for folder and filenames when liberating
|
# Set the character set that will be used for folder and filenames when liberating
|
||||||
ENV LANG=C.UTF-8
|
ENV LANG=C.UTF-8
|
||||||
ENV LC_ALL=C.UTF-8
|
ENV LC_ALL=C.UTF-8
|
||||||
|
|
||||||
|
ENV SLEEP_TIME=-1
|
||||||
|
ENV LIBATION_CONFIG_INTERNAL=/config-internal
|
||||||
|
ENV LIBATION_CONFIG_DIR=/config
|
||||||
|
ENV LIBATION_DB_DIR=/db
|
||||||
|
ENV LIBATION_BOOKS_DIR=/data
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y upgrade && \
|
RUN apt-get update && apt-get -y upgrade && \
|
||||||
mkdir /db /config /data
|
apt-get install -y jq && \
|
||||||
|
mkdir -m777 ${LIBATION_CONFIG_INTERNAL} ${LIBATION_BOOKS_DIR}
|
||||||
|
|
||||||
COPY --from=build-env /Source/bin/Publish/Linux-chardonnay /libation
|
COPY --from=build-env /Source/bin/Publish/Linux-chardonnay /libation
|
||||||
COPY Docker/appsettings.json /libation/
|
COPY Docker/* /libation
|
||||||
|
|
||||||
USER ${USER_UID}
|
USER ${USER_UID}:${USER_GID}
|
||||||
|
|
||||||
CMD ["./libation/liberate.sh"]
|
CMD ["/libation/liberate.sh"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user