From 8139e52fb15e2158e97f740dcf243d0fc42aaaa7 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Wed, 9 Aug 2023 15:18:11 +0100 Subject: [PATCH] CSS-4745 Improve dev environment (debugging + controller setup) (#1023) * Enable debugging for docker-compose container Signed-off-by: Babak K. Shandiz * Apply cloud-init configuration when bootstrapping Signed-off-by: Babak K. Shandiz * Add missing `--local` option Signed-off-by: Babak K. Shandiz * Update local/jimm/setup-controller.sh Co-authored-by: Kian Parvin <46668016+kian99@users.noreply.github.com> --------- Signed-off-by: Babak K. Shandiz Co-authored-by: Kian Parvin <46668016+kian99@users.noreply.github.com> --- .air.toml | 6 +++--- .vscode/launch.json | 33 +++++++++++++++++++++++++++++++++ docker-compose.yaml | 7 +++++++ local/jimm/add-controller.sh | 2 +- local/jimm/setup-controller.sh | 22 +++++++++++++++------- 5 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.air.toml b/.air.toml index 4f652b733..6ebe36567 100644 --- a/.air.toml +++ b/.air.toml @@ -5,14 +5,14 @@ tmp_dir = "tmp" [build] args_bin = [] bin = "./tmp/jimm" - cmd = "go build -buildvcs=false -tags version -o ./tmp/jimm ./cmd/jimmsrv " + cmd = "go build -gcflags='all=-N -l' -buildvcs=false -o ./tmp/jimm ./cmd/jimmsrv" delay = 1000 - exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_dir = [".vscode", "assets", "tmp", "vendor", "testdata"] exclude_file = [] exclude_regex = ["_test.go"] exclude_unchanged = false follow_symlink = false - full_bin = "" + full_bin = "dlv exec --accept-multiclient --log --headless --continue --listen :2345 --api-version 2 ./tmp/jimm" include_dir = [] include_ext = ["go", "tpl", "tmpl", "html"] kill_delay = "0s" diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..8001932c4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${fileDirname}" + }, + { + "name": "Attach to container", + "type": "go", + "request": "attach", + "mode": "remote", + "remotePath": "/jimm/", + "substitutePath": [ + { + "from": "${workspaceFolder}/", + "to": "/jimm/", + }, + ], + "port": 2345, + "host": "127.0.0.1", + "showLog": true, + "apiVersion": 2, + "trace": "verbose" + } + ] +} diff --git a/docker-compose.yaml b/docker-compose.yaml index 4afcaef5d..4f826335e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -31,8 +31,15 @@ services: hostname: jimm.localhost working_dir: /jimm container_name: jimmy + entrypoint: + - bash + - -c + - >- + go install github.com/go-delve/delve/cmd/dlv@latest + && air ports: - 17070:80 + - 2345:2345 environment: JIMM_LOG_LEVEL: "debug" JIMM_UUID: "3217dbc9-8ea9-4381-9e97-01eab0b3f6bb" diff --git a/local/jimm/add-controller.sh b/local/jimm/add-controller.sh index f008c7254..a93be2651 100755 --- a/local/jimm/add-controller.sh +++ b/local/jimm/add-controller.sh @@ -31,7 +31,7 @@ echo "Switching juju controller to $JIMM_CONTROLLER_NAME" juju switch "$JIMM_CONTROLLER_NAME" echo echo "Retrieving controller info for $CONTROLLER_NAME" -./jimmctl controller-info "$CONTROLLER_NAME" "$CONTROLLER_YAML_PATH" +./jimmctl controller-info --local "$CONTROLLER_NAME" "$CONTROLLER_YAML_PATH" if [[ -f "$CONTROLLER_YAML_PATH" ]]; then echo "Controller info retrieved." else diff --git a/local/jimm/setup-controller.sh b/local/jimm/setup-controller.sh index 61e062e7f..7015b4e83 100755 --- a/local/jimm/setup-controller.sh +++ b/local/jimm/setup-controller.sh @@ -6,16 +6,24 @@ set -ux +CLOUDINIT_FILE="cloudinit.temp.yaml" +function finish { + rm "$CLOUDINIT_FILE" +} +trap finish EXIT + CONTROLLER_NAME="${CONTROLLER_NAME:-qa-controller}" +CLOUDINIT_TEMPLATE=$'cloudinit-userdata: | + preruncmd: + - echo "%s candid.localhost" >> /etc/hosts + ca-certs: + trusted: + - |\n%s' + +printf "$CLOUDINIT_TEMPLATE" "$(lxc network get lxdbr0 ipv4.address | cut -f1 -d/)" "$(cat local/traefik/certs/ca.crt | sed -e 's/^/ /')" > "${CLOUDINIT_FILE}" echo "Bootstrapping controller" -juju bootstrap localhost "${CONTROLLER_NAME}" --config allow-model-access=true --config identity-url=https://candid.localhost +juju bootstrap localhost "${CONTROLLER_NAME}" --config allow-model-access=true --config "${CLOUDINIT_FILE}" --config identity-url=https://candid.localhost CONTROLLER_ID=$(juju show-controller --format json | jq --arg name "${CONTROLLER_NAME}" '.[$name]."controller-machines"."0"."instance-id"' | tr -d '"') echo "Adding proxy to LXC instance ${CONTROLLER_ID}" lxc config device add "${CONTROLLER_ID}" myproxy proxy listen=tcp:0.0.0.0:443 connect=tcp:127.0.0.1:443 bind=instance -echo "Pushing local CA" -lxc file push local/traefik/certs/ca.crt "${CONTROLLER_ID}"/usr/local/share/ca-certificates/ -lxc exec "${CONTROLLER_ID}" -- update-ca-certificates -echo "Restarting controller" -lxc stop "${CONTROLLER_ID}" -lxc start "${CONTROLLER_ID}"