Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

droplets: Add a script to do the provisioning.

Alex Vandiverb18b9d25e130
diff --git a/tools/droplets/README.md b/tools/droplets/README.md
index 7afd7efe631..c39aa592519 100644
--- a/tools/droplets/README.md
+++ b/tools/droplets/README.md
@@ -122,75 +122,29 @@ so they are notified.
## Updating the base image
-Rough steps:
-
-1. Get the `ssh` key for `base.zulipdev.org` from Tim, Vishnu or Rishi.
-1. Power up the `base.zulipdev.org` droplet from the digitalocean UI. You
- probably have to be logged in in the Zulip organization view, rather than
- via your personal account.
-1. `git pull upstream main`
-1. `tools/provision`
-1. `git clean -f`, in case things were added/removed from `.gitignore`.
-1. `tools/run-dev.py`, let it run to completion, and then Ctrl-C (to clear
- out anything in the RabbitMQ queue, load messages, etc).
-1. `tools/run-dev.py`, and check that `base.zulipdev.org:9991` is up and running.
-1. `> ~/.bash_history && history -c && sudo shutdown -h now` to clear any command
- line history (To reduce chance of confusing new contributors in case you made a typo)
- and shut down the droplet.
-1. Go to the Images tab on DigitalOcean, and "Take a Snapshot".
-1. Wait for several minutes.
-1. Do something like
- `curl -X GET -H "Content-Type: application/json" -u <API_KEY>: "https://api.digitalocean.com/v2/images?page=11" | grep --color=always base.zulipdev.org`
- (maybe with a different page number, and replace your API_KEY).
+1. Switch to the Zulip organization.
+1. Create a new droplet, with:
+ - "Regular with SSD" / "2GB RAM / 1 CPU"
+ - Select your SSH key; this will not be built into the image, and
+ is only for access to debug if the build does not succeed.
+ - Check "Monitoring", "IPv6", and "User data"
+ - Paste the contents of `tools/droplets/new-droplet-image` into the
+ text box which says `Enter user data here...`
+ - Name it e.g. `base-ubuntu-20-04.zulipdev.org`
+1. Add an A record for `base.zulipdev.org` to point to the new host.
+1. Wait for the host to boot.
+1. `scp tools/droplets/new-droplet-image base.zulipdev.org:/tmp/new-droplet-image`
+1. `ssh [email protected] bash /tmp/new-droplet-image`; this
+ should take about 15 minutes to complete, and will finish by
+ closing the connection and shutting the host down.
+1. Go to the Snapshots tab on the image, and "Take a Snapshot".
+1. Wait for several minutes for it to complete.
+1. `curl -u <API_KEY>: https://api.digitalocean.com/v2/snapshots | jq .`
1. Replace `template_id` in `create.py` in this directory with the
appropriate `id`.
-1. Test that everything works.
-1. Open a PR with the updated template_id in zulip/zulip!
-
-## Creating a new base image
-
-Creating a new base image happens rarely since updating the base image is good enough most of the time.
-Check out https://chat.zulip.org/#narrow/stream/3-backend/topic/new.20base.20dev.20droplet to view the
-discussion when we attempted to do upgrade last time.
-
-Rough steps:
-
-1. Get the `ssh` key for `base.zulipdev.org` from Tim, Vishnu or Rishi.
-1. Log in to the Zulip organization view, rather than via your personal account.
-1. Create a new droplet in DigitalOcean with 2GB RAM and `base.zulipdev.org` as the
- SSH authentication key.
-1. Log in to the droplet as root user. Make sure to point the SSH program to the private
- key of `base.zulipdev.org` during this step.
-1. Create a user called `zulipdev` and add it to the `sudo` group.
-1. Make sudo of `zulipdev` user passwordless by including
- `zulipdev ALL=(ALL) NOPASSWD:ALL` in `/etc/sudoers.d/90-cloud-init-users`
-1. Copy the `authorized_keys` file of `root` user to the `.ssh` directory of `zulipdev` user
-1. Switch to `zulipdev` user and set the permissions for the `.ssh` folder to `700` and
- `.ssh/authorized_keys` to `600`.
-1. Clone `https://github.com/zulip/zulip` repository in the home directory of `zulipdev`.
-1. `git remote rename origin upstream`
-1. `git clean -f`, in case things were added/removed from `.gitignore`.
-1. `tools/provision`
-1. Insert `NODENAME=zulip@localhost` to `/etc/rabbitmq/rabbitmq-env.conf`
-1. `tools/provision`
-1. `tools/run-dev.py`, and check that `base.zulipdev.org:9991` is up and running.
-1. Clone `https://github.com/zulip/python-zulip-api` repository in the home directory of `zulipdev`.
-1. `git remote rename origin upstream`
-1. `git clean -f`, in case things were added/removed from `.gitignore`.
-1. `./tools/provision`.
-1. `> ~/.bash_history && history -c && exit`
-1. SSH to root user.
-1. `> ~/.bash_history && history -c && sudo shutdown -h now`
-1. Go to the Images tab on DigitalOcean, and "Take a Snapshot".
-1. Wait for several minutes.
-1. Do something like
- `curl -X GET -H "Content-Type: application/json" -u <API_KEY>: "https://api.digitalocean.com/v2/images?page=11" | grep --color=always base.zulipdev.org`
- (maybe with a different page number, and replace your API_KEY).
-1. Replace `template_id` in `create.py` in this directory with the
- appropriate `id`.
-1. Test that everything works.
-1. Open a PR with the updated template_id in zulip/zulip!
+1. Clean up by destroying the droplet (but _leaving_ all "associated
+ resources"), and removing the DNS entry for `base.zulipdev.org`
+1. Open a PR with the updated `template_id`.
## Remotely debugging a droplet
diff --git a/tools/droplets/create.py b/tools/droplets/create.py
index 956f7115bf1..292417d1f6b 100644
--- a/tools/droplets/create.py
+++ b/tools/droplets/create.py
@@ -333,11 +333,8 @@ if __name__ == "__main__":
username=username, subdomain=subdomain, userkey_dicts=public_keys
)
- # define id of image to create new droplets from
- # You can get this with something like the following. You may need to try other pages.
- # Broken in two to satisfy linter (line too long)
- # curl -X GET -H "Content-Type: application/json" -u <API_KEY>: "https://api.digitaloc
- # ean.com/v2/images?page=5" | grep --color=always base.zulipdev.org
+ # define id of image to create new droplets from; see:
+ # curl -u <API_KEY>: "https://api.digitalocean.com/v2/snapshots | jq .
template_id = "103231841"
assert_droplet_does_not_exist(
diff --git a/tools/droplets/new-droplet-image b/tools/droplets/new-droplet-image
new file mode 100644
index 00000000000..19ebb673f0a
--- /dev/null
+++ b/tools/droplets/new-droplet-image
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+set -eux
+
+if [[ $(id -u) -eq 0 ]]; then
+ # First pass through -- make the zulip user
+
+ # Add the zulipdev user, let it sudo
+ useradd -U -G sudo -m zulipdev -s /bin/bash
+ echo "zulipdev ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers.d/90-cloud-init-users
+
+ # Re-run as zulip for the remainder, which is below. We disable
+ # the shellcheck because we _do_ want to read $0 as root, as it's
+ # potentially not readable as zulipdev.
+ # shellcheck disable=SC2024
+ sudo -u zulipdev bash <"$0"
+
+ # Clear out the authorized_keys; this is filled in when the image
+ # is cloned.
+ true >~/.ssh/authorized_keys
+
+ # Clear history and reboot
+ true >~/.bash_history && history -c && rm "$0" && shutdown -h now
+ exit 0
+fi
+
+# This section is run as zulipdev
+cd
+
+# Set up an empty authorized_keys with the right permissions; this is
+# filled in when the image is cloned.
+mkdir -p .ssh
+chmod 700 .ssh
+true >.ssh/authorized_keys
+chmod 600 .ssh/authorized_keys
+
+(
+ # Set up Zulip
+ git clone https://github.com/zulip/zulip
+ cd zulip
+ git remote rename origin upstream
+
+ # Provision
+ ./tools/provision
+
+ # Make sure the nodename in RabbitMQ is not host-dependent
+ sudo perl -pi -e 's/#?NODENAME=.*/NODENAME=zulip\@localhost/' /etc/rabbitmq/rabbitmq-env.conf
+ sudo service rabbitmq-server stop
+ sudo rm -rf /var/lib/rabbitmq/mnesia/
+ sudo service rabbitmq-server start
+
+ # Re-provision for the new rabbitmq nodename
+ ./tools/provision
+
+ # Make sure it's clean
+ git clean -f
+)
+
+(
+ # Set up python-zulip-api
+ git clone https://github.com/zulip/python-zulip-api
+ cd python-zulip-api
+ git remote rename origin upstream
+)
+
+# rabbitmq-server's /var/lib/rabbitmq/.erlang.cookie is a secret, and
+# should not be included in the base image
+sudo service rabbitmq-server stop
+sudo rm /var/lib/rabbitmq/.erlang.cookie
+
+# Clear our history
+true >~/.bash_history && history -c && exit