diff --git a/.gitignore b/.gitignore index 90102a4e4b..505eea6d4b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ local-dev-cluster *.test *.cache /tmp +.env diff --git a/Makefile b/Makefile index 9efaad8db7..30f8882018 100644 --- a/Makefile +++ b/Makefile @@ -340,11 +340,11 @@ cluster-sync: .PHONY: cluster-sync cluster-up: - ./hack/cluster-up.sh + ./hack/cluster.sh up .PHONY: cluster-up cluster-down: - ./hack/cluster-down.sh + ./hack/cluster.sh down .PHONY: cluster-down e2e: diff --git a/hack/cluster-down.sh b/hack/cluster-down.sh deleted file mode 100755 index a5a83445cc..0000000000 --- a/hack/cluster-down.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# This file is part of the Kepler project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2023 The Kepler Contributors -# -set -e -# Supported CLUSTER_PROVIDER are kind,microshift -export CLUSTER_PROVIDER=${CLUSTER_PROVIDER:-kind} - -function main() { - if [ -d local-dev-cluster ] - then - echo "using local local-dev-cluster" - else - echo "downloading local-dev-cluster" - git clone -b v0.0.3 https://github.com/sustainable-computing-io/local-dev-cluster.git --depth=1 - fi - - echo "undeploying ${CLUSTER_PROVIDER} cluster" - cd local-dev-cluster && ./main.sh down -} - -main "$@" diff --git a/hack/cluster-up.sh b/hack/cluster-up.sh deleted file mode 100755 index 3838bcb766..0000000000 --- a/hack/cluster-up.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# This file is part of the Kepler project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2022 The Kepler Contributors -# -set -e -# Supported CLUSTER_PROVIDER are kind,microshift -export CLUSTER_PROVIDER=${CLUSTER_PROVIDER:-kind} - -function main() { - if [ -d local-dev-cluster ] - then - echo "using local local-dev-cluster" - else - echo "downloading local-dev-cluster" - git clone -b v0.0.3 https://github.com/sustainable-computing-io/local-dev-cluster.git --depth=1 - fi - - echo "deploying ${CLUSTER_PROVIDER} cluster" - cd local-dev-cluster && ./main.sh up -} - -main "$@" diff --git a/hack/cluster.sh b/hack/cluster.sh new file mode 100755 index 0000000000..fe949f65f0 --- /dev/null +++ b/hack/cluster.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# +# This file is part of the Kepler project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright 2022 The Kepler Contributors +# +set -eu -o pipefail + +# NOTE: assumes that the project root is one level up +PROJECT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd) +declare -r PROJECT_ROOT + +# NOTE: this allows common settings to be stored as `.env` file +# shellcheck disable=SC1091 +[[ -f "$PROJECT_ROOT/.env" ]] && source "$PROJECT_ROOT/.env" + +# NOTE: these settings can be overridden in the .env file +declare -r LOCAL_DEV_CLUSTER_DIR="${LOCAL_DEV_CLUSTER_DIR:-"$PROJECT_ROOT/local-dev-cluster"}" +declare -r LOCAL_DEV_CLUSTER_VERSION="${LOCAL_DEV_CLUSTER_VERSION:-v0.0.3}" + +# Supported CLUSTER_PROVIDER are kind,microshift +export CLUSTER_PROVIDER=${CLUSTER_PROVIDER:-kind} + +clone_local_dev_cluster() { + if [ -d "$LOCAL_DEV_CLUSTER_DIR" ]; then + echo "using local local-dev-cluster" + return 0 + fi + + echo "downloading local-dev-cluster" + git clone -b "$LOCAL_DEV_CLUSTER_VERSION" \ + https://github.com/sustainable-computing-io/local-dev-cluster.git \ + --depth=1 \ + "$LOCAL_DEV_CLUSTER_DIR" +} + +main() { + local op="$1" + shift + + cd "$PROJECT_ROOT" + + clone_local_dev_cluster + echo "Bringing cluster - $op" + "$LOCAL_DEV_CLUSTER_DIR/main.sh" "$op" +} + +main "$@"