Skip to content
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

Cleanup #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
136 changes: 65 additions & 71 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,66 @@

set -e

# check that unit_test.sh complies w/ best practices
URL="https://github.com/RedHatInsights/cicd-tools/tree/main/examples"
if test -f unit_test.sh; then
if grep 'exit $result' unit_test.sh; then
echo "----------------------------"
echo "ERROR: unit_test.sh is calling 'exit' improperly, refer to examples at $URL"
echo "----------------------------"
exit 1
# Gives access to helper commands such as "oc_wrapper"
add_cicd_bin_to_path() {
if ! command -v oc_wrapper; then
export PATH=$PATH:${CICD_ROOT}/bin
fi
fi
}

check_available_server() {
echo "Checking connectivity to ephemeral cluster ..."
if ! curl -s $OC_LOGIN_SERVER > /dev/null; then
echo "Connectivity check failed"
return 1
fi
}

# Hotswap based on availability
login_to_available_server() {
if check_available_server; then
# log in to ephemeral cluster
oc_wrapper login --token=$OC_LOGIN_TOKEN --server=$OC_LOGIN_SERVER
echo "logging in to Ephemeral cluster"
else
# switch to crcd cluster
oc_wrapper login --token=$OC_LOGIN_TOKEN_DEV --server=$OC_LOGIN_SERVER_DEV
echo "logging in to CRCD cluster"
fi
}

check_unit_test_script() {

# check that unit_test.sh complies w/ best practices
local URL="https://github.com/RedHatInsights/cicd-tools/tree/main/examples"

if test -f unit_test.sh; then
if grep 'exit $result' unit_test.sh; then
echo "----------------------------"
echo "ERROR: unit_test.sh is calling 'exit' improperly, refer to examples at $URL"
echo "----------------------------"
exit 1
fi
fi
}

# TODO: create custom jenkins agent image that has a lot of this stuff pre-installed
export LANG=en_US.utf-8
export LC_ALL=en_US.utf-8
export APP_ROOT=$(pwd)
export WORKSPACE=${WORKSPACE:-$APP_ROOT} # if running in jenkins, use the build's workspace
export BONFIRE_ROOT=${WORKSPACE}/.bonfire
export CICD_ROOT=${BONFIRE_ROOT}
export CICD_ROOT=${WORKSPACE}/.cicd-tools
export IMAGE_TAG=$(git rev-parse --short=7 HEAD)
export BONFIRE_BOT="true"
export BONFIRE_NS_REQUESTER="${JOB_NAME}-${BUILD_NUMBER}"
# which branch to fetch cicd scripts from in bonfire repo
export BONFIRE_REPO_BRANCH="${BONFIRE_REPO_BRANCH:-main}"
export BONFIRE_REPO_ORG="${BONFIRE_REPO_ORG:-RedHatInsights}"

set -x
# Set up docker cfg
# which branch to fetch cicd scripts from in cicd-tools repo
export CICD_REPO_BRANCH="${CICD_REPO_BRANCH:-main}"
export CICD_REPO_ORG="${CICD_REPO_ORG:-RedHatInsights}"
export DOCKER_CONFIG="$WORKSPACE/.docker"
rm -fr $DOCKER_CONFIG
mkdir $DOCKER_CONFIG

# Set up podman cfg
# No longer needed due to podman now using the DOCKER_CONFIG
#AUTH_CONF_DIR="$WORKSPACE/.podman"
#rm -fr $AUTH_CONF_DIR
#mkdir $AUTH_CONF_DIR
#export REGISTRY_AUTH_FILE="$AUTH_CONF_DIR/auth.json"

# Set up kube cfg
export KUBECONFIG_DIR="$WORKSPACE/.kube"
export KUBECONFIG="$KUBECONFIG_DIR/config"
rm -fr $KUBECONFIG_DIR
mkdir $KUBECONFIG_DIR

set +x
export GIT_COMMIT=$(git rev-parse HEAD)
export ARTIFACTS_DIR="$WORKSPACE/artifacts"

# if this is a PR, use a different tag, since PR tags expire
if [ ! -z "$ghprbPullId" ]; then
Expand All @@ -54,57 +72,33 @@ if [ ! -z "$gitlabMergeRequestIid" ]; then
export IMAGE_TAG="pr-${gitlabMergeRequestIid}-${IMAGE_TAG}"
fi

# TODO: decide removal
check_unit_test_script

export GIT_COMMIT=$(git rev-parse HEAD)
export ARTIFACTS_DIR="$WORKSPACE/artifacts"
# Set up docker cfg
rm -fr $DOCKER_CONFIG
mkdir $DOCKER_CONFIG

# Set up kube cfg
rm -fr $KUBECONFIG_DIR
mkdir $KUBECONFIG_DIR

rm -fr $ARTIFACTS_DIR && mkdir -p $ARTIFACTS_DIR

# TODO: create custom jenkins agent image that has a lot of this stuff pre-installed
export LANG=en_US.utf-8
export LC_ALL=en_US.utf-8
# clone repo to download cicd scripts
rm -fr "$CICD_ROOT"
echo "Fetching branch '$CICD_REPO_BRANCH' of https://github.com/${CICD_REPO_ORG}/cicd-tools.git"
git clone --branch "$CICD_REPO_BRANCH" "https://github.com/${CICD_REPO_ORG}/cicd-tools.git" "$CICD_ROOT"

python3 -m venv .bonfire_venv
source .bonfire_venv/bin/activate
python3 -m venv "${CICD_ROOT}/.bonfire_venv"
source "${CICD_ROOT}/.bonfire_venv/bin/activate"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can merge this in yet, there's a few unit_test.sh's that would be impacted by this, for ex:

https://github.com/RedHatInsights/insights-host-inventory/blob/master/unit_test.sh#L26

Copy link
Contributor Author

Choose a reason for hiding this comment

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

argh - that's why we don't want to hardcode config

nice catch - I'll think of a way to handle this


python3 -m pip install --upgrade pip 'setuptools<58' wheel
python3 -m pip install --upgrade 'crc-bonfire>=4.10.4'

# clone repo to download cicd scripts
rm -fr $BONFIRE_ROOT
echo "Fetching branch '$BONFIRE_REPO_BRANCH' of https://github.com/${BONFIRE_REPO_ORG}/cicd-tools.git"
git clone --branch "$BONFIRE_REPO_BRANCH" "https://github.com/${BONFIRE_REPO_ORG}/cicd-tools.git" "$BONFIRE_ROOT"

# Do a docker login to ensure our later 'docker pull' calls have an auth file created
source ${CICD_ROOT}/_common_container_logic.sh
login

# Gives access to helper commands such as "oc_wrapper"
add_cicd_bin_to_path() {
if ! command -v oc_wrapper; then export PATH=$PATH:${CICD_ROOT}/bin; fi
}

check_available_server() {
echo "Checking connectivity to ephemeral cluster ..."
(curl -s $OC_LOGIN_SERVER > /dev/null)
RET_CODE=$?
if [ $RET_CODE -ge 1 ]; then echo "Connectivity check failed"; fi
return $RET_CODE
}

# Hotswap based on availability
login_to_available_server() {
if check_available_server; then
# log in to ephemeral cluster
oc_wrapper login --token=$OC_LOGIN_TOKEN --server=$OC_LOGIN_SERVER
echo "logging in to Ephemeral cluster"
else
# switch to crcd cluster
oc_wrapper login --token=$OC_LOGIN_TOKEN_DEV --server=$OC_LOGIN_SERVER_DEV
echo "logging in to CRCD cluster"
fi
}

add_cicd_bin_to_path

login_to_available_server