-
Notifications
You must be signed in to change notification settings - Fork 45
Wpb 17321 enable demo cd #828
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
base: wpb-17321-fixes-ansible-wiab
Are you sure you want to change the base?
Changes from all commits
0160f85
323ab64
b9f65e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| # This playbook is not-up-to-date, requires to be updated to match with current developments | ||
| # A new WIAB (wire in a box) dev solution has been created https://docs.wire.com/latest/how-to/install/demo-wiab.html and can be used until this (wiab-staging) gets updated | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please elaborate the comments, is it relevant to this PR and update?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Earlier we used to have a Wire in a box (staging) environment and we used to use this playbook to deploy it. Now we have another wiab (demo/dev) environment and this comment is to say that, we haven't updated the other wiab(staging) solution yet, so users can use the wiab-demo in the meantime. |
||
| - hosts: all | ||
| become: true | ||
| vars: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| #!/usr/bin/env bash | ||
| # This script is not-up-to-date, requires to be updated to match with current developments | ||
| # A new WIAB (wire in a box) dev solution has been created https://docs.wire.com/latest/how-to/install/demo-wiab.html and can be used until this (wiab-staging) gets updated | ||
|
|
||
| # shellcheck disable=SC2087 | ||
|
|
||
| # This script can be replaced with a simpler solution of wiab-demo installtion | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments? If the script needs to be touched in another PR mention that please. Just comments is a bit confusing here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this PR is trying to remove the confusion between old wiab staging and current wiab-demo one |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Added: enable cd-demo.sh to verify the demo-wiab builds | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it verifying or running an actual deployment?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will verify the changes for wiab-demo via deploying it
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rephrase it as |
||
| Changed: add a note in old demo-staging playbooks and scripts that they aren't up-to-date and to also check demo-wiab | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euxo pipefail | ||
|
|
||
| CD_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| TF_DIR="${CD_DIR}/../terraform/examples/wiab-demo-hetzner" | ||
| # shellcheck disable=SC2034 # May be used in future versions | ||
| BIN_DIR="${CD_DIR}/../bin" | ||
| # shellcheck disable=SC2034 # May be used in future versions | ||
| ARTIFACTS_DIR="${CD_DIR}/demo-build/output" | ||
| ANSIBLE_DIR="${CD_DIR}/../ansible" | ||
| INVENTORY_DIR="${ANSIBLE_DIR}/inventory/demo" | ||
| INVENTORY_FILE="${INVENTORY_DIR}/host.yml" | ||
| TEST_USER="demo" | ||
| COMMIT_HASH="${GITHUB_SHA}" | ||
|
|
||
| function cleanup { | ||
| (cd "$TF_DIR" && terraform destroy -auto-approve) | ||
| echo "done" | ||
| } | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| cd "$TF_DIR" | ||
| terraform init && terraform apply -auto-approve | ||
|
|
||
| host=$(terraform output -raw host) | ||
| ssh_private_key=$(terraform output ssh_private_key) | ||
|
|
||
| rm -f "${INVENTORY_DIR}/ssh_private_key" || true | ||
| echo "$ssh_private_key" > "${INVENTORY_DIR}/ssh_private_key" | ||
| chmod 400 "${INVENTORY_DIR}/ssh_private_key" | ||
|
|
||
| # clean old host verification keys to avoid SSH issues | ||
| ssh-keygen -R "$host" || true | ||
|
|
||
| # create demo user on the remote host | ||
| ssh -v -oStrictHostKeyChecking=accept-new -oConnectionAttempts=10 -i "${INVENTORY_DIR}/ssh_private_key" "root@$host" \ | ||
| "useradd -m -s /bin/bash ${TEST_USER} && \ | ||
| usermod -aG sudo ${TEST_USER} && \ | ||
| mkdir -p /home/${TEST_USER}/.ssh && \ | ||
| cp /root/.ssh/authorized_keys /home/${TEST_USER}/.ssh/ && \ | ||
| chown -R ${TEST_USER}:${TEST_USER} /home/${TEST_USER}/.ssh && \ | ||
| chmod 700 /home/${TEST_USER}/.ssh && \ | ||
| chmod 600 /home/${TEST_USER}/.ssh/authorized_keys && \ | ||
| echo '${TEST_USER} ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/${TEST_USER}" | ||
|
|
||
| # update inventory file with host details | ||
| yq eval -i ".wiab.hosts.deploy_node.ansible_host = \"$host\"" "${INVENTORY_FILE}" | ||
| yq eval -i ".wiab.hosts.deploy_node.ansible_ssh_private_key_file = \"${INVENTORY_DIR}/ssh_private_key\"" "${INVENTORY_FILE}" | ||
| yq eval -i ".wiab.vars.artifact_hash = \"$COMMIT_HASH\"" "${INVENTORY_FILE}" | ||
| yq eval -i ".wiab.hosts.deploy_node.ansible_user = \"$TEST_USER\"" "${INVENTORY_FILE}" | ||
|
|
||
| echo "Running ansible playbook deploy_wiab.yml against node $host" | ||
| # deploying demo-wiab | ||
| ansible-playbook -i "${INVENTORY_FILE}" "${ANSIBLE_DIR}/wiab-demo/deploy_wiab.yml" --skip-tags verify_dns,cert_manager_networking | ||
| # cleaning demo-wiab | ||
| ansible-playbook -i "${INVENTORY_FILE}" "${ANSIBLE_DIR}/wiab-demo/clean_cluster.yml" --tags remove_minikube,remove_artifacts,remove_packages,remove_iptables,remove_ssh | ||
|
|
||
| cleanup |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [[ -f .envrc.local ]] && source_env .envrc.local | ||
| # You can set this in .envrc.local to keep it out of VCS | ||
| export HCLOUD_TOKEN | ||
| source_up | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # WiaB-demo-hetzner | ||
|
|
||
| This environment is set up and destroyed on demand to test our demo-wiab solution. It will be used to provide an Ubuntu system for the demo. | ||
| https://docs.wire.com/latest/how-to/install/demo-wiab.html#installation-guide |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| locals { | ||
| # Server type preferences with fallbacks | ||
| preferred_server_types = { | ||
| size = ["cx53", "cpx62"] } | ||
| } | ||
|
|
||
| # Get available server types in the specified location | ||
| data "hcloud_server_types" "available" { | ||
| } | ||
|
|
||
| # Helper locals to select available server types | ||
| locals { | ||
| available_server_type_names = [for st in data.hcloud_server_types.available.server_types : st.name] | ||
|
|
||
| # Select the first available server type from the preference list | ||
| server_type = [ | ||
| for preferred in local.preferred_server_types.size : | ||
| preferred if contains(local.available_server_type_names, preferred) | ||
| ][0] | ||
| } | ||
|
|
||
| resource "random_pet" "host" { | ||
| } | ||
|
|
||
| resource "tls_private_key" "host" { | ||
| algorithm = "ECDSA" | ||
| ecdsa_curve = "P256" | ||
| } | ||
|
|
||
| resource "hcloud_ssh_key" "host" { | ||
| name = "host-${random_pet.host.id}" | ||
| public_key = tls_private_key.host.public_key_openssh | ||
| } | ||
|
|
||
| resource "hcloud_server" "host" { | ||
| location = "fsn1" | ||
| name = "host-${random_pet.host.id}" | ||
| image = "ubuntu-24.04" | ||
| ssh_keys = [hcloud_ssh_key.host.name] | ||
| server_type = local.server_type | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| output "ssh_private_key" { | ||
| sensitive = true | ||
| value = tls_private_key.host.private_key_pem | ||
| } | ||
|
|
||
| output "selected_server_types" { | ||
| description = "Server types selected after checking availability" | ||
| value = { | ||
| server_type = local.server_type | ||
| } | ||
| } | ||
|
|
||
| output "host" { | ||
| sensitive = true | ||
| value = hcloud_server.host.ipv4_address | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| terraform { | ||
| required_providers { | ||
| hcloud = { | ||
| source = "hetznercloud/hcloud" | ||
| } | ||
| } | ||
| required_version = "~> 1.1" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow has nothing here. Should this file be part of the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is meant to highlight that there was an old solution which is not to be confused with current wiab-demo.