diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..322af5c --- /dev/null +++ b/.flake8 @@ -0,0 +1,10 @@ +[flake8] +max-line-length = 120 +statistics = True +import-order-style = edited +# allow long test names and long strings +extend-ignore = + # line breaks before binary operators + W503 + # whitespace before : + E203 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..fefe01a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ + +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +default_language_version: + python: python3 + +repos: + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + args: ["--diff"] + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["--diff"] + additional_dependencies: [toml] + files: \.py$ + - repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + args: [--allow-multiple-documents] + # - id: check-shebang-scripts-are-executable + - id: check-executables-have-shebangs + - id: check-merge-conflict + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.2 + hooks: + - id: shellcheck diff --git a/deploy.sh b/deploy.sh old mode 100644 new mode 100755 index e6405de..41b4e80 --- a/deploy.sh +++ b/deploy.sh @@ -1,9 +1,9 @@ -#!/bin/bash +#!/usr/bin/env bash + set -o errexit set -o nounset set -o pipefail - help() { cat < @@ -13,46 +13,43 @@ help() { EOH } - check_environment() { # verify that the proper environment is passed local environment="${1?No environment passed}" if [[ ! -d "deploy/$environment" || "$environment" =~ ^(base|README)$ ]]; then echo "Unknown environment $environment, use one of:" - ls deploy/ | egrep -v '^(base|README)' + find deploy -maxdepth 1 -mindepth 1 -type d ! -regex 'deploy/base.*' -exec basename {} \; exit 1 fi } - deploy_generic() { local environment="${1?No environment passed}" if [[ "$environment" == "devel" ]]; then - sed "s/{{HARBOR_IP}}/${HARBOR_IP}/"\ - deploy/devel/auth-patch.yaml.template > deploy/devel/auth-patch.yaml + sed "s/{{HARBOR_IP}}/${HARBOR_IP}/" \ + deploy/devel/auth-patch.yaml.template >deploy/devel/auth-patch.yaml fi if command -v minikube >/dev/null; then - kubectl="minikube kubectl --" + kubectl="minikube kubectl --" else kubectl="kubectl" fi - + $kubectl apply -k "deploy/base-tekton" $kubectl apply -k "deploy/$environment" } - -main () { +main() { while getopts "hv" option; do case "${option}" in h) help exit 0 ;; - v) set -x;; + v) set -x ;; *) echo "Wrong option $option" help @@ -60,8 +57,8 @@ main () { ;; esac done - shift $((OPTIND-1)) - + shift $((OPTIND - 1)) + # default to prod, avoid deploying dev in prod if there's any issue local environment="tools" if [[ "${1:-}" == "" ]]; then @@ -76,5 +73,4 @@ main () { deploy_generic "$environment" } - main "$@" diff --git a/utils/get_harbor.sh b/utils/get_harbor.sh index d0be74a..8811063 100755 --- a/utils/get_harbor.sh +++ b/utils/get_harbor.sh @@ -1,4 +1,8 @@ -#!/bin/bash -eu +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail CURDIR=$PWD HARBOR_DIR=".harbor" @@ -9,11 +13,11 @@ export HARBOR_HOSTNAME="${HARBOR_IP?"HARBOR_IP variable is not set"}" [[ -e $HARBOR_DIR ]] || mkdir -p "$HARBOR_DIR" cd "$HARBOR_DIR" wget \ - https://github.com/goharbor/harbor/releases/download/${HARBOR_VERSION}/harbor-online-installer-${HARBOR_VERSION}.tgz \ - -O harbor-${HARBOR_VERSION}.tgz -tar xvzf harbor-${HARBOR_VERSION}.tgz + https://github.com/goharbor/harbor/releases/download/"${HARBOR_VERSION}"/harbor-online-installer-"${HARBOR_VERSION}".tgz \ + -O harbor-"${HARBOR_VERSION}".tgz +tar xvzf harbor-"${HARBOR_VERSION}".tgz cd harbor -$CURDIR/utils/parse_harbor_config.py . +"$CURDIR"/utils/parse_harbor_config.py . ./prepare # the above runs a docker container and changes permissions for the data dirs, # so the containers have the correct ones, but that forces us to use sudo when