Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

dev: Add pre-commit to buildservice repo #16

Merged
merged 2 commits into from Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .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
37 changes: 37 additions & 0 deletions .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
26 changes: 11 additions & 15 deletions deploy.sh 100644 → 100755
@@ -1,9 +1,9 @@
#!/bin/bash
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail


help() {
cat <<EOH
Usage: $0 [OPTIONS] <ENVIRONMENT>
Expand All @@ -13,55 +13,52 @@ 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
exit 1
;;
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
Expand All @@ -76,5 +73,4 @@ main () {
deploy_generic "$environment"
}


main "$@"
14 changes: 9 additions & 5 deletions 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"
Expand All @@ -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
Expand Down