From 1c562fe2126612c0c933cf5cf3c6f67b87577291 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Fri, 9 Aug 2024 05:26:03 +0200 Subject: [PATCH] Add Notifier --- .github/workflows/build.yml | 3 +- LICENSE | 21 ++++++++ Makefile | 2 +- README.md | 11 +--- go.mod | 3 -- src/Dockerfile | 27 ++++------ src/scripts/backup.sh | 102 ------------------------------------ src/scripts/s3-mount.sh | 95 --------------------------------- 8 files changed, 36 insertions(+), 228 deletions(-) create mode 100644 LICENSE delete mode 100644 go.mod delete mode 100644 src/scripts/backup.sh delete mode 100644 src/scripts/s3-mount.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ebefc73..f2c4ab6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,7 @@ on: type: string env: BUILDKIT_IMAGE: jkaninda/toolkit + TAG: "0.3" jobs: docker: runs-on: ubuntu-latest @@ -35,5 +36,5 @@ jobs: file: "./src/Dockerfile" platforms: linux/amd64,linux/arm64 tags: | - "${{env.BUILDKIT_IMAGE}}:0.2" + "${{env.BUILDKIT_IMAGE}}:${{env.TAG}}" "${{env.BUILDKIT_IMAGE}}:latest" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ac320f2 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/Makefile b/Makefile index 3386315..88011f1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ IMAGE_NAME=jkaninda/toolkit build: - docker build -f src/Dockerfile -t ${IMAGE_NAME}:latest . + docker buildx build --platform=linux/amd64 -f src/Dockerfile -t ${IMAGE_NAME}:latest . run: docker compose up -d --force-recreate \ No newline at end of file diff --git a/README.md b/README.md index 81a6a5d..c079dd7 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,9 @@ DevOps Portable toolkit - jq - yq - k6 -- s3fs - pre-commit - cosign ```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 \ No newline at end of file diff --git a/go.mod b/go.mod deleted file mode 100644 index fdd867a..0000000 --- a/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module toolkit - -go 1.20 diff --git a/src/Dockerfile b/src/Dockerfile index a0d145d..5b76e0c 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -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"] \ No newline at end of file +CMD ["/usr/bin/supervisord"] diff --git a/src/scripts/backup.sh b/src/scripts/backup.sh deleted file mode 100644 index 59c9a5a..0000000 --- a/src/scripts/backup.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bash - -# S3 Backup & Restore - -# @author Jonas Kaninda -# @license MIT License -# @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 -} \ No newline at end of file diff --git a/src/scripts/s3-mount.sh b/src/scripts/s3-mount.sh deleted file mode 100644 index 358d43c..0000000 --- a/src/scripts/s3-mount.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env bash - -# S3 Backup & Restore - -# @author Jonas Kaninda -# @license MIT License -# @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 \ No newline at end of file