Skip to content

Regenerating context every time its sourced #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ switch:
switcht:
@ scripts/dev/switch_context_by_test.sh $(test)

regenerate-context:
@ scripts/dev/regenerate_context.sh

# builds the Operator binary file and docker image and pushes it to the remote registry if using a remote registry. Deploys it to
# k8s cluster
operator: configure-operator build-and-push-operator-image
Expand Down
1 change: 1 addition & 0 deletions scripts/dev/contexts/root-context
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ script_dir=$(dirname "${script_name}")
source "${script_dir}/private-context"

export PROJECT_DIR="${PWD}"
export PYTHON_PATH="${PROJECT_DIR}"
export IMAGE_TYPE=ubi
export UBI_IMAGE_WITHOUT_SUFFIX=true
export WATCH_NAMESPACE=${WATCH_NAMESPACE:-${NAMESPACE}}
Expand Down
22 changes: 22 additions & 0 deletions scripts/dev/regenerate_context.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -Eeou pipefail

source scripts/funcs/errors

script_name=$(readlink -f "${BASH_SOURCE[0]}")
script_dir=$(dirname "${script_name}")

generated_context_dir="${script_dir}/../../.generated"
mkdir -p "${generated_context_dir}" >/dev/null
generated_context_dir="$(realpath "${generated_context_dir}")"

current_context_file="${generated_context_dir}/.current_context"
if [[ -f "${current_context_file}" ]]; then
current_context=$(cat "${current_context_file}")
else
echo "Current context is not set in ${current_context_file}. Using root-context."
current_context="root-context"
fi

scripts/dev/switch_context.sh "${current_context}"
12 changes: 8 additions & 4 deletions scripts/dev/set_env_context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ source scripts/funcs/errors

script_name=$(readlink -f "${BASH_SOURCE[0]}")
script_dir=$(dirname "${script_name}")
context_file="$(realpath "${script_dir}/../../.generated/context.export.env")"

if [[ ! -f ${context_file} ]]; then
fatal "File ${context_file} not found! Make sure to follow this guide to get started: https://wiki.corp.mongodb.com/display/MMS/Setting+up+local+development+and+E2E+testing#SettinguplocaldevelopmentandE2Etesting-GettingStartedGuide(VariantSwitching)"
tmpfile="$(mktemp)"
if ! scripts/dev/regenerate_context.sh >"${tmpfile}" 2>&1; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this line of code does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It dumps the output of the make switch performed under the hood to the file. Currently switch is a bit verbose (about 6lines of output). But we don't want to be silent if there is any problem in switching the context

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work as well?

result=$(scripts/dev/regenerate_context.sh 2>&1)
exit=$?
if exit; then
echo result
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes, even better!

cat "${tmpfile}"
rm "${tmpfile}"
exit 1
fi

context_file="$(realpath "${script_dir}/../../.generated/context.export.env")"
current_context="$(cat "$(dirname "${context_file}")/.current_context")"
echo "Using context ${current_context} (${context_file})" >&2
# shellcheck disable=SC1090
source "${context_file}"

Expand Down