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

CSS-4745 Improve local dev env with cloud-init commands #1013

Merged
merged 6 commits into from
Jul 28, 2023
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ local/vault/roleid.txt
*.csr
/jimmctl
qa-controller

/cloudinit.temp.yaml
10 changes: 5 additions & 5 deletions local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ The `request name` represents the literal WS endpoint, i.e., `API = /api`.
Note that you can export an environment variable `CONTROLLER_NAME` and re-run steps 3. and 4. below to create multiple Juju
controllers that will be controlled by JIMM.

1. `juju unregister jimm-dev` - Unregister any other local JIMM you have.
2. `juju login jimm.localhost -c jimm-dev` - Login to local JIMM. (If you name the controller jimm-dev, the script will pick it up!)
3. `./local/jimm/setup-controller.sh` - Performs controller setup.
4. `./local/jimm/add-controller.sh` - A local script to do many of the manual steps for us. See script for more details.
5. `juju add-model test` - Adds a model to qa-controller via JIMM.
1. `juju unregister jimm-dev` - Unregister any other local JIMM you have.
2. `juju login jimm.localhost -c jimm-dev` - Login to local JIMM with `jimm:jimm`. (If you name the controller jimm-dev, the script will pick it up!)
3. `./local/jimm/setup-controller.sh` - Performs controller setup.
4. `./local/jimm/add-controller.sh` - A local script to do many of the manual steps for us. See script for more details.
5. `juju add-model test` - Adds a model to qa-controller via JIMM.

# Helpful tidbits!
> Note: For any secure step to work, ensure you've run the local traefik certs script!
Expand Down
2 changes: 1 addition & 1 deletion local/jimm/add-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 15 additions & 9 deletions local/jimm/setup-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@

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 jimm.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 login-token-refresh-url=https://jimm.localhost
juju bootstrap localhost "${CONTROLLER_NAME}" --config allow-model-access=true --config "${CLOUDINIT_FILE}" --config login-token-refresh-url=https://jimm.localhost/.well-known/jwks.json
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}"