Skip to content

Commit 5f7c961

Browse files
committed
move utilities to lib folder
1 parent ea65896 commit 5f7c961

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

scaletest/terraform/coder_init.sh renamed to scaletest/lib/coder_init.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ fi
1111
[[ -n ${VERBOSE:-} ]] && set -x
1212

1313
CODER_URL=$1
14-
CONFIG_DIR="${PWD}/.coderv2"
14+
DRY_RUN="${DRY_RUN:-0}"
15+
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
16+
# shellcheck source=scripts/lib.sh
17+
source "${PROJECT_ROOT}/scripts/lib.sh"
18+
CONFIG_DIR="${PROJECT_ROOT}/scaletest/.coderv2"
1519
ARCH="$(arch)"
1620
if [[ "$ARCH" == "x86_64" ]]; then
1721
ARCH="amd64"
@@ -24,10 +28,10 @@ if [[ -f "${CONFIG_DIR}/coder.env" ]]; then
2428
exit 0
2529
fi
2630

27-
mkdir -p "${CONFIG_DIR}"
31+
maybedryrun "$DRY_RUN" mkdir -p "${CONFIG_DIR}"
2832
echo "Fetching Coder CLI for first-time setup!"
29-
curl -fsSLk "${CODER_URL}/bin/coder-${PLATFORM}-${ARCH}" -o "${CONFIG_DIR}/coder"
30-
chmod +x "${CONFIG_DIR}/coder"
33+
maybedryrun "$DRY_RUN" curl -fsSLk "${CODER_URL}/bin/coder-${PLATFORM}-${ARCH}" -o "${CONFIG_DIR}/coder"
34+
maybedryrun "$DRY_RUN" chmod +x "${CONFIG_DIR}/coder"
3135

3236
set +o pipefail
3337
RANDOM_ADMIN_PASSWORD=$(tr </dev/urandom -dc _A-Z-a-z-0-9 | head -c16)
@@ -37,21 +41,23 @@ CODER_FIRST_USER_USERNAME="coder"
3741
CODER_FIRST_USER_PASSWORD="${RANDOM_ADMIN_PASSWORD}"
3842
CODER_FIRST_USER_TRIAL="false"
3943
echo "Running login command!"
40-
"${CONFIG_DIR}/coder" login "${CODER_URL}" \
44+
DRY_RUN="$DRY_RUN" "${PROJECT_ROOT}/scaletest/lib/coder_shim.sh" login "${CODER_URL}" \
4145
--global-config="${CONFIG_DIR}" \
4246
--first-user-username="${CODER_FIRST_USER_USERNAME}" \
4347
--first-user-email="${CODER_FIRST_USER_EMAIL}" \
4448
--first-user-password="${CODER_FIRST_USER_PASSWORD}" \
4549
--first-user-trial=false
4650

4751
echo "Writing credentials to ${CONFIG_DIR}/coder.env"
48-
cat <<EOF >"${CONFIG_DIR}/coder.env"
52+
maybedryrun "$DRY_RUN" cat <<EOF >"${CONFIG_DIR}/coder.env"
4953
CODER_FIRST_USER_EMAIL=admin@coder.com
5054
CODER_FIRST_USER_USERNAME=coder
5155
CODER_FIRST_USER_PASSWORD="${RANDOM_ADMIN_PASSWORD}"
5256
CODER_FIRST_USER_TRIAL="${CODER_FIRST_USER_TRIAL}"
5357
EOF
5458

5559
echo "Importing kubernetes template"
56-
"${CONFIG_DIR}/coder" templates create --global-config="${CONFIG_DIR}" \
57-
--directory "${CONFIG_DIR}/templates/kubernetes" --yes kubernetes
60+
DRY_RUN="$DRY_RUN" "$PROJECT_ROOT/scaletest/lib/coder_shim.sh" templates create \
61+
--global-config="${CONFIG_DIR}" \
62+
--directory "${CONFIG_DIR}/templates/kubernetes" \
63+
--yes kubernetes

scaletest/lib/coder_shim.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a shim for easily executing Coder commands against a loadtest cluster
4+
# without having to overwrite your own session/URL
5+
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
6+
# shellcheck source=scripts/lib.sh
7+
source "${PROJECT_ROOT}/scripts/lib.sh"
8+
CONFIG_DIR="${PROJECT_ROOT}/scaletest/.coderv2"
9+
CODER_BIN="${CONFIG_DIR}/coder"
10+
DRY_RUN="${DRY_RUN:-0}"
11+
maybedryrun "$DRY_RUN" exec "${CODER_BIN}" --global-config "${CONFIG_DIR}" "$@"

scaletest/terraform/coder_workspacetraffic.sh renamed to scaletest/lib/coder_workspacetraffic.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ fi
1111
[[ -n ${VERBOSE:-} ]] && set -x
1212

1313
LOADTEST_NAME="$1"
14-
CODER_TOKEN=$(./coder_shim.sh tokens create)
14+
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
15+
CODER_TOKEN=$("${PROJECT_ROOT}/scaletest/lib/coder_shim.sh" tokens create)
1516
CODER_URL="http://coder.coder-${LOADTEST_NAME}.svc.cluster.local"
16-
export KUBECONFIG="${PWD}/.coderv2/${LOADTEST_NAME}-cluster.kubeconfig"
17+
export KUBECONFIG="${PROJECT_ROOT}/scaletest/.coderv2/${LOADTEST_NAME}-cluster.kubeconfig"
1718

1819
# Clean up any pre-existing pods
1920
kubectl -n "coder-${LOADTEST_NAME}" delete pod coder-scaletest-workspace-traffic --force || true

scaletest/terraform/coder_shim.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)