Skip to content

Commit

Permalink
feat(dev): allow .env to be sourced when bringing up/down a cluster
Browse files Browse the repository at this point in the history
Previously, cluster-up.sh and cluster-down.sh both had similar code to
clone the local-dev-cluster repo. This is now moved to a single script.

The scripts also `cd` in local-dev-cluster dir which meant that a .env
file at the root of kepler project will not be honored by the
local-dev-cluster/main.sh. This has been fixed by invoking the
main.sh from the root of kepler project itself

This commit modifies the cluster-up and down targets to
  * clone local-dev-cluster to tmp dir (which is ignored by git)
  * sources .env in project root where settings that needs to
    passed down to local-dev-cluster can be kept. E.g.
    ```sh
     PROMETHEUS_ENABLE=true
     GRAFANA_ENABLE=true
    ```
Signed-off-by: Sunil Thaha <[email protected]>
  • Loading branch information
sthaha committed Oct 17, 2023
1 parent 8c8dab4 commit 711076d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ local-dev-cluster
*.test
*.cache
/tmp
.env
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 0 additions & 36 deletions hack/cluster-down.sh

This file was deleted.

36 changes: 0 additions & 36 deletions hack/cluster-up.sh

This file was deleted.

60 changes: 60 additions & 0 deletions hack/cluster.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 711076d

Please sign in to comment.