Add Notifier

This commit is contained in:
2024-08-09 05:26:03 +02:00
parent b7be7fc693
commit 1c562fe212
8 changed files with 36 additions and 228 deletions

View File

@@ -1,21 +1,18 @@
FROM gcr.io/projectsigstore/cosign:v2.2.4 as cosign-bin
FROM ubuntu:22.04
ENV BUCKETNAME=""
ENV ACCESS_KEY=""
ENV SECRET_KEY=""
ENV S3_ENDPOINT=https://s3.amazonaws.com
ARG DEBIAN_FRONTEND=noninteractive
ENV VERSION="0.2"
ENV VERSION="0.3.0"
ARG TEMP_DIR=/temp
LABEL auth="Jonas Kaninda"
LABEL github="https://github.com/jkaninda/toolkit"
RUN apt-get update -qq \
&& apt-get install -qqy curl gnupg2 jq git wget supervisor s3fs python3 python3-pip -y
&& apt-get install -qqy curl gnupg2 jq tar supervisor git wget python3 python3-pip -y
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
WORKDIR /temp
RUN curl https://get.docker.com/ > dockerinstall && chmod 777 dockerinstall && ./dockerinstall
RUN curl https://get.docker.com/ > dockerinstall
#RUN chmod 777 dockerinstall && ./dockerinstall
RUN wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\
chmod +x /usr/bin/yq
@@ -48,14 +45,12 @@ RUN mkdir -p $TEMP_DIR && \
chmod 777 $TEMP_DIR && \
mkdir -p $TEMP_DIR/s3cache && \
chmod 777 $TEMP_DIR/s3cache
## Copy scripts
COPY src/scripts/backup.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/backup.sh
COPY src/scripts/s3-mount.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/s3-mount.sh
## Create link
RUN ln -s /usr/local/bin/s3-mount.sh /usr/local/bin/s3-mount
RUN ln -s /usr/local/bin/backup.sh /usr/local/bin/backup
RUN curl -L -o notifier-0.1.0-linux-amd64.tar.gz https://github.com/jkaninda/notifier/releases/download/0.1.0/notifier-0.1.0-linux-amd64.tar.gz
RUN tar -xzf notifier-0.1.0-linux-amd64.tar.gz && rm notifier-0.1.0-linux-amd64.tar.gz
RUN mv notifier /usr/local/bin/notifier && \
chmod +x /usr/local/bin/notifier
ADD src/supervisord.conf /etc/supervisor/supervisord.conf
CMD ["/usr/bin/supervisord"]
CMD ["/usr/bin/supervisord"]

View File

@@ -1,102 +0,0 @@
#!/usr/bin/env bash
# S3 Backup & Restore
# @author Jonas Kaninda
# @license MIT License <https://opensource.org/licenses/MIT>
# @link https://github.com/jkaninda/toolkit
#
set -e
TIME=$(date +%Y%m%d_%H%M%S)
arg0=$(basename "$0" .sh)
blnk=$(echo "$arg0" | sed 's/./ /g')
export OPERATION=backup
export S3_PATH=/mysql-bkup
export TIMEOUT=60
export EXECUTION_MODE="default"
export SCHEDULE_PERIOD="0 1 * * *"
export FILE_COMPRESION=true
usage_info()
{
echo "Usage: \\"
}
version_info()
{
echo "Version: $VERSION"
exit 0
}
usage()
{
exec 1>2 # Send standard output to standard error
usage_info
exit 0
}
error()
{
echo "$arg0: $*" >&2
exit 0
}
info() {
{ set +x; } 2> /dev/null
echo 'toolkit:' '[INFO] ' "$@"
#set -x
}
warning() {
{ set +x; } 2> /dev/null
echo 'toolkit:' '[WARNING] ' "$@"
}
fatal() {
{ set +x; } 2> /dev/null
echo 'toolkit:' '[ERROR] ' "$@" >&2
exit 1
}
help()
{
echo
echo " -o |--operation -- Set operation (default: backup)"
echo " |--path -- Set s3 path, without file name"
echo " -t |--timeout -- Set timeout (default: 120s)"
echo " -h |--help -- Print this help message and exit"
echo " -V |--version -- Print version information and exit"
exit 0
}
flags()
{
while test $# -gt 0
do
case "$1" in
(-o|--operation)
shift
[ $# = 0 ] && error "No operation specified - restore or backup"
export OPERATION="$1"
shift;;
(--enable-compresion)
shift
[ $# = 0 ] && error "No enable-compresion specified "
export FILE_COMPRESION="$1"
shift;;
(-m|--mode)
shift
[ $# = 0 ] && error "No execution mode specified"
export EXECUTION_MODE="$1"
shift;;
(-t|--timeout)
shift
[ $# = 0 ] && error "No timeout specified"
export TIMEOUT="$1"
shift;;
(-h|--help)
help;;
(-V|--version)
version_info;;
(--)
help;;
(*) usage;;
esac
done
}

View File

@@ -1,95 +0,0 @@
#!/usr/bin/env bash
# S3 Backup & Restore
# @author Jonas Kaninda
# @license MIT License <https://opensource.org/licenses/MIT>
# @link https://github.com/jkaninda/toolkit
#
set -e
usage_info()
{
echo "Usage: \\"
}
version_info()
{
echo "Version: $VERSION"
exit 0
}
usage()
{
exec 1>2 # Send standard output to standard error
usage_info
exit 0
}
error()
{
echo "$arg0: $*" >&2
exit 0
}
info() {
{ set +x; } 2> /dev/null
echo 'toolkit:' '[INFO] ' "$@"
#set -x
}
warning() {
{ set +x; } 2> /dev/null
echo 'toolkit:' '[WARNING] ' "$@"
}
fatal() {
{ set +x; } 2> /dev/null
echo 'toolkit:' '[ERROR] ' "$@" >&2
exit 1
}
help()
{
echo
echo " -h |--help -- Print this help message and exit"
echo " -V |--version -- Print version information and exit"
exit 0
}
flags()
{
while test $# -gt 0
do
case "$1" in
(-t|--timeout)
shift
[ $# = 0 ] && error "No timeout specified"
export TIMEOUT="$1"
shift;;
(-h|--help)
help;;
(-V|--version)
version_info;;
(--)
help;;
(*) usage;;
esac
done
}
mount_s3()
{
if [[ -z $ACCESS_KEY ]] || [[ -z $SECRET_KEY ]]; then
info "Please make sure all environment variables are set "
else
echo "$ACCESS_KEY:$SECRET_KEY" | tee /etc/passwd-s3fs
chmod 600 /etc/passwd-s3fs
info "Mounting Object storage in /s3mnt .... "
if [ -z "$(ls -A /s3mnt)" ]; then
s3fs $BUCKETNAME /s3mnt -o passwd_file=/etc/passwd-s3fs -o use_cache=/tmp/s3cache -o allow_other -o url=$S3_ENDPOINT -o use_path_request_style
if [ ! -d "/s3mnt" ]; then
mkdir -p /s3mnt
fi
else
info "Object storage already mounted in /s3mnt"
fi
fi
}
flags "$@"
mount_s3