2021-03-17 20:03:43 +01:00
|
|
|
# Creates a Zulip remote development environment droplet or
|
|
|
|
# a production droplet in DigitalOcean.
|
|
|
|
#
|
2017-10-29 02:02:58 +01:00
|
|
|
# Particularly useful for sprints/hackathons, interns, and other
|
|
|
|
# situation where one wants to quickly onboard new contributors.
|
|
|
|
#
|
|
|
|
# Requires python-digitalocean library:
|
|
|
|
# https://github.com/koalalorenzo/python-digitalocean
|
|
|
|
#
|
2020-10-23 02:43:28 +02:00
|
|
|
# Also requires DigitalOcean team membership for Zulip and API token:
|
2017-10-29 02:02:58 +01:00
|
|
|
# https://cloud.digitalocean.com/settings/api/tokens
|
|
|
|
#
|
2020-10-23 02:43:28 +02:00
|
|
|
# Copy conf.ini-template to conf.ini and populate with your API token.
|
2020-06-11 00:54:34 +02:00
|
|
|
import argparse
|
2017-10-29 02:02:58 +01:00
|
|
|
import configparser
|
|
|
|
import json
|
|
|
|
import os
|
2022-03-10 03:44:51 +01:00
|
|
|
import secrets
|
2020-06-11 00:54:34 +02:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import urllib.error
|
|
|
|
import urllib.request
|
2022-04-28 03:34:16 +02:00
|
|
|
from typing import Any, Dict, List, Tuple
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
import digitalocean
|
2021-03-17 20:03:43 +01:00
|
|
|
import requests
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
parser = argparse.ArgumentParser(description="Create a Zulip development VM DigitalOcean droplet.")
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"username", help="GitHub username for whom you want to create a Zulip dev droplet"
|
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("--tags", nargs="+", default=[])
|
|
|
|
parser.add_argument("-f", "--recreate", action="store_true")
|
2022-03-10 03:36:09 +01:00
|
|
|
parser.add_argument("-s", "--subdomain")
|
2021-03-17 20:03:43 +01:00
|
|
|
parser.add_argument("-p", "--production", action="store_true")
|
2022-04-28 03:33:57 +02:00
|
|
|
parser.add_argument("-r", "--region", choices=("nyc3", "sfo3", "blr1", "fra1"), default="nyc3")
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_config() -> configparser.ConfigParser:
|
2017-10-29 02:02:58 +01:00
|
|
|
config = configparser.ConfigParser()
|
2021-02-12 08:20:45 +01:00
|
|
|
config.read(os.path.join(os.path.dirname(os.path.abspath(__file__)), "conf.ini"))
|
2017-10-29 02:02:58 +01:00
|
|
|
return config
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-03-17 18:13:11 +01:00
|
|
|
def assert_github_user_exists(github_username: str) -> bool:
|
|
|
|
print(f"Checking to see if GitHub user {github_username} exists...")
|
|
|
|
user_api_url = f"https://api.github.com/users/{github_username}"
|
2017-10-29 02:02:58 +01:00
|
|
|
try:
|
|
|
|
response = urllib.request.urlopen(user_api_url)
|
2020-03-20 02:12:02 +01:00
|
|
|
json.load(response)
|
2017-10-29 02:02:58 +01:00
|
|
|
print("...user exists!")
|
|
|
|
return True
|
|
|
|
except urllib.error.HTTPError as err:
|
|
|
|
print(err)
|
2021-03-17 18:13:11 +01:00
|
|
|
print(f"Does the GitHub user {github_username} exist?")
|
2017-10-29 02:02:58 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-03-17 20:50:36 +01:00
|
|
|
def get_ssh_public_keys_from_github(github_username: str) -> List[Dict[str, Any]]:
|
2017-10-29 02:02:58 +01:00
|
|
|
print("Checking to see that GitHub user has available public keys...")
|
2021-03-17 20:50:36 +01:00
|
|
|
apiurl_keys = f"https://api.github.com/users/{github_username}/keys"
|
2017-10-29 02:02:58 +01:00
|
|
|
try:
|
|
|
|
response = urllib.request.urlopen(apiurl_keys)
|
2020-03-20 02:12:02 +01:00
|
|
|
userkeys = json.load(response)
|
2017-10-29 02:02:58 +01:00
|
|
|
if not userkeys:
|
2021-03-17 20:50:36 +01:00
|
|
|
print(
|
|
|
|
f"No keys found. Has user {github_username} added SSH keys to their GitHub account?"
|
|
|
|
)
|
2017-10-29 02:02:58 +01:00
|
|
|
sys.exit(1)
|
|
|
|
print("...public keys found!")
|
|
|
|
return userkeys
|
|
|
|
except urllib.error.HTTPError as err:
|
|
|
|
print(err)
|
2021-03-17 20:50:36 +01:00
|
|
|
print(f"Has user {github_username} added SSH keys to their GitHub account?")
|
2017-10-29 02:02:58 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-03-17 20:48:32 +01:00
|
|
|
def assert_user_forked_zulip_server_repo(username: str) -> bool:
|
2017-10-29 02:02:58 +01:00
|
|
|
print("Checking to see GitHub user has forked zulip/zulip...")
|
2020-06-09 00:25:09 +02:00
|
|
|
apiurl_fork = f"https://api.github.com/repos/{username}/zulip"
|
2017-10-29 02:02:58 +01:00
|
|
|
try:
|
|
|
|
response = urllib.request.urlopen(apiurl_fork)
|
2020-03-20 02:12:02 +01:00
|
|
|
json.load(response)
|
2017-10-29 02:02:58 +01:00
|
|
|
print("...fork found!")
|
|
|
|
return True
|
|
|
|
except urllib.error.HTTPError as err:
|
|
|
|
print(err)
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Has user {username} forked zulip/zulip?")
|
2017-10-29 02:02:58 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-03-17 19:57:37 +01:00
|
|
|
def assert_droplet_does_not_exist(my_token: str, droplet_name: str, recreate: bool) -> None:
|
|
|
|
print(f"Checking to see if droplet {droplet_name} already exists...")
|
2017-10-29 02:02:58 +01:00
|
|
|
manager = digitalocean.Manager(token=my_token)
|
|
|
|
my_droplets = manager.get_all_droplets()
|
|
|
|
for droplet in my_droplets:
|
2021-03-17 19:57:37 +01:00
|
|
|
if droplet.name.lower() == droplet_name:
|
2017-11-23 16:29:08 +01:00
|
|
|
if not recreate:
|
2021-02-12 08:19:30 +01:00
|
|
|
print(
|
2021-03-17 19:57:37 +01:00
|
|
|
"Droplet {} already exists. Pass --recreate if you "
|
|
|
|
"need to recreate the droplet.".format(droplet_name)
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-11-23 16:29:08 +01:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2021-03-17 19:57:37 +01:00
|
|
|
print(f"Deleting existing droplet {droplet_name}.")
|
2017-11-23 16:29:08 +01:00
|
|
|
droplet.destroy()
|
|
|
|
return
|
2017-10-29 02:02:58 +01:00
|
|
|
print("...No droplet found...proceeding.")
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-03-17 11:04:22 +01:00
|
|
|
def get_ssh_keys_string_from_github_ssh_key_dicts(userkey_dicts: List[Dict[str, Any]]) -> str:
|
|
|
|
return "\n".join([userkey_dict["key"] for userkey_dict in userkey_dicts])
|
|
|
|
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2022-03-10 03:36:09 +01:00
|
|
|
def generate_dev_droplet_user_data(
|
|
|
|
username: str, subdomain: str, userkey_dicts: List[Dict[str, Any]]
|
|
|
|
) -> str:
|
2021-03-17 11:04:22 +01:00
|
|
|
ssh_keys_string = get_ssh_keys_string_from_github_ssh_key_dicts(userkey_dicts)
|
|
|
|
setup_root_ssh_keys = f"printf '{ssh_keys_string}' > /root/.ssh/authorized_keys"
|
|
|
|
setup_zulipdev_ssh_keys = f"printf '{ssh_keys_string}' > /home/zulipdev/.ssh/authorized_keys"
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2020-04-27 20:35:16 +02:00
|
|
|
# We pass the hostname as username.zulipdev.org to the DigitalOcean API.
|
|
|
|
# But some droplets (eg on 18.04) are created with with hostname set to just username.
|
|
|
|
# So we fix the hostname using cloud-init.
|
2022-03-10 03:36:09 +01:00
|
|
|
hostname_setup = f"hostnamectl set-hostname {subdomain}.zulipdev.org"
|
2020-04-27 20:35:16 +02:00
|
|
|
|
2020-04-27 20:39:19 +02:00
|
|
|
setup_repo = (
|
|
|
|
"cd /home/zulipdev/{1} && "
|
|
|
|
"git remote add origin https://github.com/{0}/{1}.git && "
|
|
|
|
"git fetch origin && "
|
|
|
|
"git clean -f"
|
|
|
|
)
|
2018-05-07 16:25:49 +02:00
|
|
|
|
|
|
|
server_repo_setup = setup_repo.format(username, "zulip")
|
|
|
|
python_api_repo_setup = setup_repo.format(username, "python-zulip-api")
|
|
|
|
|
2022-03-10 03:44:51 +01:00
|
|
|
erlang_cookie = secrets.token_hex(16)
|
|
|
|
setup_erlang_cookie = (
|
|
|
|
f"echo '{erlang_cookie}' > /var/lib/rabbitmq/.erlang.cookie && "
|
|
|
|
"chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie && "
|
|
|
|
"service rabbitmq-server restart"
|
|
|
|
)
|
|
|
|
|
2020-06-13 08:57:35 +02:00
|
|
|
cloudconf = f"""\
|
2020-05-01 21:38:33 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
{setup_zulipdev_ssh_keys}
|
|
|
|
{setup_root_ssh_keys}
|
2022-03-10 03:44:51 +01:00
|
|
|
{setup_erlang_cookie}
|
2020-05-06 16:47:35 +02:00
|
|
|
sed -i "s/PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
|
|
|
|
service ssh restart
|
2020-05-01 21:38:33 +02:00
|
|
|
{hostname_setup}
|
|
|
|
su -c '{server_repo_setup}' zulipdev
|
|
|
|
su -c '{python_api_repo_setup}' zulipdev
|
|
|
|
su -c 'git config --global core.editor nano' zulipdev
|
|
|
|
su -c 'git config --global pull.rebase true' zulipdev
|
2020-06-13 08:57:35 +02:00
|
|
|
"""
|
2017-10-29 02:02:58 +01:00
|
|
|
print("...returning cloud-config data.")
|
|
|
|
return cloudconf
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-03-17 20:03:43 +01:00
|
|
|
def generate_prod_droplet_user_data(username: str, userkey_dicts: List[Dict[str, Any]]) -> str:
|
|
|
|
ssh_keys_string = get_ssh_keys_string_from_github_ssh_key_dicts(userkey_dicts)
|
|
|
|
setup_root_ssh_keys = f"printf '{ssh_keys_string}' > /root/.ssh/authorized_keys"
|
|
|
|
|
|
|
|
cloudconf = f"""\
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
{setup_root_ssh_keys}
|
|
|
|
passwd -d root
|
|
|
|
sed -i "s/PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
|
|
|
|
service ssh restart
|
|
|
|
"""
|
|
|
|
print("...returning cloud-config data.")
|
|
|
|
return cloudconf
|
|
|
|
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
def create_droplet(
|
2022-04-28 03:33:57 +02:00
|
|
|
my_token: str,
|
|
|
|
template_id: str,
|
|
|
|
name: str,
|
|
|
|
tags: List[str],
|
|
|
|
user_data: str,
|
|
|
|
region: str = "nyc3",
|
2022-04-28 03:34:16 +02:00
|
|
|
) -> Tuple[str, str]:
|
2017-10-29 02:02:58 +01:00
|
|
|
droplet = digitalocean.Droplet(
|
|
|
|
token=my_token,
|
2021-03-17 11:13:10 +01:00
|
|
|
name=name,
|
2022-04-28 03:33:57 +02:00
|
|
|
region=region,
|
2017-10-29 02:02:58 +01:00
|
|
|
image=template_id,
|
2021-02-12 08:20:45 +01:00
|
|
|
size_slug="s-1vcpu-2gb",
|
2017-10-29 02:02:58 +01:00
|
|
|
user_data=user_data,
|
|
|
|
tags=tags,
|
2021-02-12 08:19:30 +01:00
|
|
|
backups=False,
|
2022-04-28 03:34:16 +02:00
|
|
|
ipv6=True,
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
print("Initiating droplet creation...")
|
|
|
|
droplet.create()
|
|
|
|
|
|
|
|
incomplete = True
|
|
|
|
while incomplete:
|
|
|
|
actions = droplet.get_actions()
|
|
|
|
for action in actions:
|
|
|
|
action.load()
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"...[{action.type}]: {action.status}")
|
2021-02-12 08:20:45 +01:00
|
|
|
if action.type == "create" and action.status == "completed":
|
2017-10-29 02:02:58 +01:00
|
|
|
incomplete = False
|
|
|
|
break
|
|
|
|
if incomplete:
|
|
|
|
time.sleep(15)
|
|
|
|
print("...droplet created!")
|
|
|
|
droplet.load()
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"...ip address for new droplet is: {droplet.ip_address}.")
|
2022-04-28 03:34:16 +02:00
|
|
|
return (droplet.ip_address, droplet.ip_v6_address)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2017-11-11 00:47:10 +01:00
|
|
|
def delete_existing_records(records: List[digitalocean.Record], record_name: str) -> None:
|
2017-11-05 21:23:50 +01:00
|
|
|
count = 0
|
|
|
|
for record in records:
|
2022-04-28 03:34:16 +02:00
|
|
|
if (
|
|
|
|
record.name == record_name
|
|
|
|
and record.domain == "zulipdev.org"
|
|
|
|
and record.type in ("AAAA", "A")
|
|
|
|
):
|
2017-11-05 21:23:50 +01:00
|
|
|
record.destroy()
|
|
|
|
count = count + 1
|
|
|
|
if count:
|
2022-04-28 03:34:16 +02:00
|
|
|
print(f"Deleted {count} existing A / AAAA records for {record_name}.zulipdev.org.")
|
2017-11-11 00:47:10 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2022-04-28 03:34:16 +02:00
|
|
|
def create_dns_record(my_token: str, record_name: str, ipv4: str, ipv6: str) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
domain = digitalocean.Domain(token=my_token, name="zulipdev.org")
|
2017-11-11 00:47:10 +01:00
|
|
|
domain.load()
|
|
|
|
records = domain.get_records()
|
|
|
|
|
2021-03-18 19:44:09 +01:00
|
|
|
delete_existing_records(records, record_name)
|
|
|
|
wildcard_name = "*." + record_name
|
2017-11-11 00:47:10 +01:00
|
|
|
delete_existing_records(records, wildcard_name)
|
2017-11-05 21:23:50 +01:00
|
|
|
|
2022-04-28 03:34:16 +02:00
|
|
|
print(f"Creating new A record for {record_name}.zulipdev.org that points to {ipv4}.")
|
|
|
|
domain.create_new_domain_record(type="A", name=record_name, data=ipv4)
|
|
|
|
print(f"Creating new A record for *.{record_name}.zulipdev.org that points to {ipv4}.")
|
|
|
|
domain.create_new_domain_record(type="A", name=wildcard_name, data=ipv4)
|
|
|
|
|
|
|
|
print(f"Creating new AAAA record for {record_name}.zulipdev.org that points to {ipv6}.")
|
|
|
|
domain.create_new_domain_record(type="AAAA", name=record_name, data=ipv6)
|
|
|
|
print(f"Creating new AAAA record for *.{record_name}.zulipdev.org that points to {ipv6}.")
|
|
|
|
domain.create_new_domain_record(type="AAAA", name=wildcard_name, data=ipv6)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2022-03-10 05:58:38 +01:00
|
|
|
def print_dev_droplet_instructions(username: str, droplet_domain_name: str) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
print(
|
|
|
|
"""
|
2022-03-10 05:58:38 +01:00
|
|
|
COMPLETE! Droplet for GitHub user {0} is available at {1}.
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
Instructions for use are below. (copy and paste to the user)
|
|
|
|
|
|
|
|
------
|
|
|
|
Your remote Zulip dev server has been created!
|
|
|
|
|
|
|
|
- Connect to your server by running
|
2022-03-10 05:58:38 +01:00
|
|
|
`ssh zulipdev@{1}` on the command line
|
2017-10-29 02:02:58 +01:00
|
|
|
(Terminal for macOS and Linux, Bash for Git on Windows).
|
2020-10-23 02:43:28 +02:00
|
|
|
- There is no password; your account is configured to use your SSH keys.
|
2019-01-10 01:30:44 +01:00
|
|
|
- Once you log in, you should see `(zulip-py3-venv) ~$`.
|
2023-03-04 02:17:54 +01:00
|
|
|
- To start the dev server, `cd zulip` and then run `./tools/run-dev`.
|
2017-11-08 03:41:48 +01:00
|
|
|
- While the dev server is running, you can see the Zulip server in your browser at
|
2022-03-10 05:58:38 +01:00
|
|
|
http://{1}:9991.
|
2021-02-12 08:19:30 +01:00
|
|
|
""".format(
|
2022-03-10 05:58:38 +01:00
|
|
|
username, droplet_domain_name
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
print(
|
|
|
|
"See [Developing remotely](https://zulip.readthedocs.io/en/latest/development/remote.html) "
|
|
|
|
"for tips on using the remote dev instance and "
|
2021-05-10 07:02:14 +02:00
|
|
|
"[Git & GitHub guide](https://zulip.readthedocs.io/en/latest/git/index.html) "
|
2021-02-12 08:19:30 +01:00
|
|
|
"to learn how to use Git with Zulip.\n"
|
|
|
|
)
|
|
|
|
print(
|
|
|
|
"Note that this droplet will automatically be deleted after a month of inactivity. "
|
|
|
|
"If you are leaving Zulip for more than a few weeks, we recommend pushing all of your "
|
|
|
|
"active branches to GitHub."
|
|
|
|
)
|
2017-10-29 02:02:58 +01:00
|
|
|
print("------")
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-03-17 20:03:43 +01:00
|
|
|
def print_production_droplet_instructions(droplet_domain_name: str) -> None:
|
|
|
|
print(
|
|
|
|
"""
|
|
|
|
-----
|
|
|
|
|
|
|
|
Production droplet created successfully!
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-03-17 20:03:43 +01:00
|
|
|
Connect to the server by running
|
|
|
|
|
|
|
|
ssh root@{}
|
|
|
|
|
|
|
|
-----
|
|
|
|
""".format(
|
|
|
|
droplet_domain_name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def get_zulip_oneclick_app_slug(api_token: str) -> str:
|
|
|
|
response = requests.get(
|
|
|
|
"https://api.digitalocean.com/v2/1-clicks", headers={"Authorization": f"Bearer {api_token}"}
|
|
|
|
).json()
|
|
|
|
one_clicks = response["1_clicks"]
|
|
|
|
|
|
|
|
for one_click in one_clicks:
|
|
|
|
if one_click["slug"].startswith("kandralabs"):
|
|
|
|
return one_click["slug"]
|
|
|
|
raise Exception("Unable to find Zulip One-click app slug")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-10-29 02:02:58 +01:00
|
|
|
args = parser.parse_args()
|
2020-05-20 10:39:35 +02:00
|
|
|
username = args.username.lower()
|
2022-03-10 03:36:09 +01:00
|
|
|
if args.subdomain:
|
|
|
|
subdomain = args.subdomain.lower()
|
|
|
|
elif args.production:
|
|
|
|
subdomain = "{username}-prod"
|
|
|
|
else:
|
|
|
|
subdomain = username
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-03-17 20:03:43 +01:00
|
|
|
if args.production:
|
|
|
|
print(f"Creating production droplet for GitHub user {username}...")
|
|
|
|
else:
|
|
|
|
print(f"Creating Zulip developer environment for GitHub user {username}...")
|
2021-03-17 11:13:10 +01:00
|
|
|
|
2017-10-29 02:02:58 +01:00
|
|
|
config = get_config()
|
2021-03-17 20:03:43 +01:00
|
|
|
api_token = config["digitalocean"]["api_token"]
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-03-17 18:13:11 +01:00
|
|
|
assert_github_user_exists(github_username=username)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-03-17 20:50:36 +01:00
|
|
|
public_keys = get_ssh_public_keys_from_github(github_username=username)
|
2022-03-10 05:58:17 +01:00
|
|
|
droplet_domain_name = f"{subdomain}.zulipdev.org"
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-03-17 20:03:43 +01:00
|
|
|
if args.production:
|
|
|
|
template_id = get_zulip_oneclick_app_slug(api_token)
|
|
|
|
user_data = generate_prod_droplet_user_data(username=username, userkey_dicts=public_keys)
|
|
|
|
|
|
|
|
else:
|
2021-03-17 20:48:32 +01:00
|
|
|
assert_user_forked_zulip_server_repo(username=username)
|
2022-03-10 03:36:09 +01:00
|
|
|
user_data = generate_dev_droplet_user_data(
|
|
|
|
username=username, subdomain=subdomain, userkey_dicts=public_keys
|
|
|
|
)
|
2021-03-17 20:03:43 +01:00
|
|
|
|
2022-04-28 03:31:25 +02:00
|
|
|
# define id of image to create new droplets from; see:
|
|
|
|
# curl -u <API_KEY>: "https://api.digitalocean.com/v2/snapshots | jq .
|
2022-04-28 03:50:10 +02:00
|
|
|
template_id = "107085241"
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-03-17 19:57:37 +01:00
|
|
|
assert_droplet_does_not_exist(
|
|
|
|
my_token=api_token, droplet_name=droplet_domain_name, recreate=args.recreate
|
|
|
|
)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2022-04-28 03:34:16 +02:00
|
|
|
(ipv4, ipv6) = create_droplet(
|
2021-02-12 08:19:30 +01:00
|
|
|
my_token=api_token,
|
|
|
|
template_id=template_id,
|
2021-03-17 11:13:10 +01:00
|
|
|
name=droplet_domain_name,
|
2023-01-26 00:12:09 +01:00
|
|
|
tags=[*args.tags, "dev"],
|
2021-02-12 08:19:30 +01:00
|
|
|
user_data=user_data,
|
2022-04-28 03:33:57 +02:00
|
|
|
region=args.region,
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2022-04-28 03:34:16 +02:00
|
|
|
create_dns_record(my_token=api_token, record_name=subdomain, ipv4=ipv4, ipv6=ipv6)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2021-03-17 20:03:43 +01:00
|
|
|
if args.production:
|
|
|
|
print_production_droplet_instructions(droplet_domain_name=droplet_domain_name)
|
|
|
|
else:
|
2022-03-10 05:58:38 +01:00
|
|
|
print_dev_droplet_instructions(username=username, droplet_domain_name=droplet_domain_name)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
sys.exit(1)
|