Add Notifier
This commit is contained in:
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -11,6 +11,7 @@ on:
|
|||||||
type: string
|
type: string
|
||||||
env:
|
env:
|
||||||
BUILDKIT_IMAGE: jkaninda/toolkit
|
BUILDKIT_IMAGE: jkaninda/toolkit
|
||||||
|
TAG: "0.3"
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -35,5 +36,5 @@ jobs:
|
|||||||
file: "./src/Dockerfile"
|
file: "./src/Dockerfile"
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
tags: |
|
||||||
"${{env.BUILDKIT_IMAGE}}:0.2"
|
"${{env.BUILDKIT_IMAGE}}:${{env.TAG}}"
|
||||||
"${{env.BUILDKIT_IMAGE}}:latest"
|
"${{env.BUILDKIT_IMAGE}}:latest"
|
||||||
|
|||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 Jonas Kaninda
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
2
Makefile
2
Makefile
@@ -1,7 +1,7 @@
|
|||||||
IMAGE_NAME=jkaninda/toolkit
|
IMAGE_NAME=jkaninda/toolkit
|
||||||
|
|
||||||
build:
|
build:
|
||||||
docker build -f src/Dockerfile -t ${IMAGE_NAME}:latest .
|
docker buildx build --platform=linux/amd64 -f src/Dockerfile -t ${IMAGE_NAME}:latest .
|
||||||
|
|
||||||
run:
|
run:
|
||||||
docker compose up -d --force-recreate
|
docker compose up -d --force-recreate
|
||||||
11
README.md
11
README.md
@@ -14,18 +14,9 @@ DevOps Portable toolkit
|
|||||||
- jq
|
- jq
|
||||||
- yq
|
- yq
|
||||||
- k6
|
- k6
|
||||||
- s3fs
|
|
||||||
- pre-commit
|
- pre-commit
|
||||||
- cosign
|
- cosign
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
version: '3.7'
|
|
||||||
services:
|
|
||||||
toolkit:
|
|
||||||
image: jkaninda/toolkit:latest
|
|
||||||
container_name: toolkit
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
- ~/.kube:/root/.kube
|
|
||||||
- ~/.ssh:/root/.ssh # If you use private CVS
|
|
||||||
```
|
```
|
||||||
|
curl -L
|
||||||
@@ -1,21 +1,18 @@
|
|||||||
FROM gcr.io/projectsigstore/cosign:v2.2.4 as cosign-bin
|
FROM gcr.io/projectsigstore/cosign:v2.2.4 as cosign-bin
|
||||||
|
|
||||||
FROM ubuntu:22.04
|
FROM ubuntu:22.04
|
||||||
ENV BUCKETNAME=""
|
|
||||||
ENV ACCESS_KEY=""
|
|
||||||
ENV SECRET_KEY=""
|
|
||||||
ENV S3_ENDPOINT=https://s3.amazonaws.com
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
ENV VERSION="0.2"
|
ENV VERSION="0.3.0"
|
||||||
ARG TEMP_DIR=/temp
|
ARG TEMP_DIR=/temp
|
||||||
LABEL auth="Jonas Kaninda"
|
LABEL auth="Jonas Kaninda"
|
||||||
LABEL github="https://github.com/jkaninda/toolkit"
|
LABEL github="https://github.com/jkaninda/toolkit"
|
||||||
RUN apt-get update -qq \
|
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 -
|
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
|
||||||
WORKDIR /temp
|
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 &&\
|
RUN wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\
|
||||||
chmod +x /usr/bin/yq
|
chmod +x /usr/bin/yq
|
||||||
|
|
||||||
@@ -48,14 +45,12 @@ RUN mkdir -p $TEMP_DIR && \
|
|||||||
chmod 777 $TEMP_DIR && \
|
chmod 777 $TEMP_DIR && \
|
||||||
mkdir -p $TEMP_DIR/s3cache && \
|
mkdir -p $TEMP_DIR/s3cache && \
|
||||||
chmod 777 $TEMP_DIR/s3cache
|
chmod 777 $TEMP_DIR/s3cache
|
||||||
## Copy scripts
|
|
||||||
COPY src/scripts/backup.sh /usr/local/bin/
|
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 chmod +x /usr/local/bin/backup.sh
|
RUN tar -xzf notifier-0.1.0-linux-amd64.tar.gz && rm notifier-0.1.0-linux-amd64.tar.gz
|
||||||
COPY src/scripts/s3-mount.sh /usr/local/bin/
|
|
||||||
RUN chmod +x /usr/local/bin/s3-mount.sh
|
RUN mv notifier /usr/local/bin/notifier && \
|
||||||
## Create link
|
chmod +x /usr/local/bin/notifier
|
||||||
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
|
|
||||||
|
|
||||||
ADD src/supervisord.conf /etc/supervisor/supervisord.conf
|
ADD src/supervisord.conf /etc/supervisor/supervisord.conf
|
||||||
CMD ["/usr/bin/supervisord"]
|
CMD ["/usr/bin/supervisord"]
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user