2017-10-29 02:02:58 +01:00
|
|
|
# Creates a Droplet on Digital Ocean for remote Zulip development.
|
|
|
|
# Particularly useful for sprints/hackathons, interns, and other
|
|
|
|
# situation where one wants to quickly onboard new contributors.
|
|
|
|
#
|
|
|
|
# This script takes one argument: the name of the GitHub user for whom you want
|
|
|
|
# to create a Zulip developer environment. Requires Python 3.
|
|
|
|
#
|
|
|
|
# Requires python-digitalocean library:
|
|
|
|
# https://github.com/koalalorenzo/python-digitalocean
|
|
|
|
#
|
|
|
|
# Also requires Digital Ocean team membership for Zulip and api token:
|
|
|
|
# https://cloud.digitalocean.com/settings/api/tokens
|
|
|
|
#
|
|
|
|
# Copy conf.ini-template to conf.ini and populate with your api token.
|
|
|
|
#
|
|
|
|
# usage: python3 create.py <username>
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import configparser
|
|
|
|
import urllib.error
|
|
|
|
import urllib.request
|
|
|
|
import json
|
|
|
|
import digitalocean
|
|
|
|
import time
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
from typing import Any, Dict, List
|
|
|
|
|
|
|
|
# initiation argument parser
|
|
|
|
parser = argparse.ArgumentParser(description='Create a Zulip devopment VM Digital Ocean droplet.')
|
|
|
|
parser.add_argument("username", help="Github username for whom you want to create a Zulip dev droplet")
|
|
|
|
parser.add_argument('--tags', nargs='+', default=[])
|
2017-11-23 16:29:08 +01:00
|
|
|
parser.add_argument('-f', '--recreate', dest='recreate', action="store_true", default=False)
|
2017-10-29 02:02:58 +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()
|
|
|
|
config.read(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf.ini'))
|
|
|
|
return config
|
|
|
|
|
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 user_exists(username: str) -> bool:
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Checking to see if GitHub user {username} exists...")
|
|
|
|
user_api_url = f"https://api.github.com/users/{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)
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Does the github user {username} exist?")
|
2017-10-29 02:02:58 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
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_keys(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...")
|
2020-06-09 00:25:09 +02:00
|
|
|
apiurl_keys = f"https://api.github.com/users/{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:
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"No keys found. Has user {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)
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Has user {username} added ssh keys to their github account?")
|
2017-10-29 02:02:58 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
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 fork_exists(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)
|
|
|
|
|
2017-11-23 16:29:08 +01:00
|
|
|
def exit_if_droplet_exists(my_token: str, username: str, recreate: bool) -> None:
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Checking to see if droplet for {username} 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:
|
2020-06-09 00:25:09 +02:00
|
|
|
if droplet.name.lower() == f"{username}.zulipdev.org":
|
2017-11-23 16:29:08 +01:00
|
|
|
if not recreate:
|
2020-04-09 21:51:58 +02:00
|
|
|
print("Droplet for user {} already exists. Pass --recreate if you "
|
2017-11-23 16:29:08 +01:00
|
|
|
"need to recreate the droplet.".format(username))
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Deleting existing droplet for {username}.")
|
2017-11-23 16:29:08 +01:00
|
|
|
droplet.destroy()
|
|
|
|
return
|
2017-10-29 02:02:58 +01:00
|
|
|
print("...No droplet found...proceeding.")
|
|
|
|
|
2020-05-01 21:38:33 +02:00
|
|
|
def set_user_data(username: str, userkey_dicts: List[Dict[str, Any]]) -> str:
|
2017-10-29 02:02:58 +01:00
|
|
|
print("Setting cloud-config data, populated with GitHub user's public keys...")
|
2020-05-01 21:38:33 +02:00
|
|
|
userkeys = [userkey_dict["key"] for userkey_dict in userkey_dicts]
|
|
|
|
ssh_keys = "\n".join(userkeys)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
2020-06-09 00:25:09 +02:00
|
|
|
setup_root_ssh_keys = f"printf '{ssh_keys}' > /root/.ssh/authorized_keys"
|
|
|
|
setup_zulipdev_ssh_keys = f"printf '{ssh_keys}' > /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.
|
2020-06-09 00:25:09 +02:00
|
|
|
hostname_setup = f"hostnamectl set-hostname {username}.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")
|
|
|
|
|
2020-05-01 21:38:33 +02:00
|
|
|
cloudconf = """\
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
{setup_zulipdev_ssh_keys}
|
|
|
|
{setup_root_ssh_keys}
|
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
|
|
|
|
""".format(setup_root_ssh_keys=setup_root_ssh_keys,
|
|
|
|
setup_zulipdev_ssh_keys=setup_zulipdev_ssh_keys,
|
|
|
|
hostname_setup=hostname_setup,
|
|
|
|
server_repo_setup=server_repo_setup, python_api_repo_setup=python_api_repo_setup)
|
2017-10-29 02:02:58 +01:00
|
|
|
print("...returning cloud-config data.")
|
|
|
|
return cloudconf
|
|
|
|
|
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 create_droplet(my_token: str, template_id: str, username: str, tags: List[str], user_data: str) -> str:
|
2017-10-29 02:02:58 +01:00
|
|
|
droplet = digitalocean.Droplet(
|
|
|
|
token=my_token,
|
2020-06-09 00:25:09 +02:00
|
|
|
name=f'{username}.zulipdev.org',
|
2018-05-07 16:08:31 +02:00
|
|
|
region='nyc3',
|
2017-10-29 02:02:58 +01:00
|
|
|
image=template_id,
|
2020-04-28 21:19:23 +02:00
|
|
|
size_slug='s-1vcpu-2gb',
|
2017-10-29 02:02:58 +01:00
|
|
|
user_data=user_data,
|
|
|
|
tags=tags,
|
|
|
|
backups=False)
|
|
|
|
|
|
|
|
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}")
|
2017-10-29 02:02:58 +01:00
|
|
|
if action.type == 'create' and action.status == 'completed':
|
|
|
|
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}.")
|
2017-10-29 02:02:58 +01:00
|
|
|
return droplet.ip_address
|
|
|
|
|
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:
|
2017-11-11 00:47:10 +01:00
|
|
|
if record.name == record_name and record.domain == 'zulipdev.org' and record.type == 'A':
|
2017-11-05 21:23:50 +01:00
|
|
|
record.destroy()
|
|
|
|
count = count + 1
|
|
|
|
if count:
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Deleted {count} existing A records for {record_name}.zulipdev.org.")
|
2017-11-11 00:47:10 +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 create_dns_record(my_token: str, username: str, ip_address: str) -> None:
|
2017-11-11 00:47:10 +01:00
|
|
|
domain = digitalocean.Domain(token=my_token, name='zulipdev.org')
|
|
|
|
domain.load()
|
|
|
|
records = domain.get_records()
|
|
|
|
|
|
|
|
delete_existing_records(records, username)
|
|
|
|
wildcard_name = "*." + username
|
|
|
|
delete_existing_records(records, wildcard_name)
|
2017-11-05 21:23:50 +01:00
|
|
|
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Creating new A record for {username}.zulipdev.org that points to {ip_address}.")
|
2017-10-29 02:02:58 +01:00
|
|
|
domain.create_new_domain_record(type='A', name=username, data=ip_address)
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Creating new A record for *.{username}.zulipdev.org that points to {ip_address}.")
|
2017-11-11 00:47:10 +01:00
|
|
|
domain.create_new_domain_record(type='A', name=wildcard_name, data=ip_address)
|
2017-10-29 02:02:58 +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 print_completion(username: str) -> None:
|
2017-10-29 02:02:58 +01:00
|
|
|
print("""
|
|
|
|
COMPLETE! Droplet for GitHub user {0} is available at {0}.zulipdev.org.
|
|
|
|
|
|
|
|
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
|
|
|
|
`ssh zulipdev@{0}.zulipdev.org` on the command line
|
|
|
|
(Terminal for macOS and Linux, Bash for Git on Windows).
|
|
|
|
- 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) ~$`.
|
2017-10-29 02:02:58 +01:00
|
|
|
- To start the dev server, `cd zulip` and then run `./tools/run-dev.py`.
|
2017-11-08 03:41:48 +01:00
|
|
|
- While the dev server is running, you can see the Zulip server in your browser at
|
|
|
|
http://{0}.zulipdev.org:9991.
|
2017-10-29 02:02:58 +01:00
|
|
|
""".format(username))
|
|
|
|
|
2017-11-16 19:54:24 +01:00
|
|
|
print("See [Developing remotely](https://zulip.readthedocs.io/en/latest/development/remote.html) "
|
2017-10-29 02:02:58 +01:00
|
|
|
"for tips on using the remote dev instance and "
|
2017-11-24 01:24:00 +01:00
|
|
|
"[Git & GitHub Guide](https://zulip.readthedocs.io/en/latest/git/index.html) "
|
2017-11-16 19:54:24 +01:00
|
|
|
"to learn how to use Git with Zulip.\n")
|
2017-10-29 02:02:58 +01:00
|
|
|
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.")
|
|
|
|
print("------")
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# 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
|
2020-04-28 21:19:23 +02:00
|
|
|
template_id = "63219191"
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
# get command line arguments
|
|
|
|
args = parser.parse_args()
|
2020-05-20 10:39:35 +02:00
|
|
|
username = args.username.lower()
|
2020-06-09 00:25:09 +02:00
|
|
|
print(f"Creating Zulip developer environment for GitHub user {username}...")
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
# get config details
|
|
|
|
config = get_config()
|
|
|
|
|
|
|
|
# see if droplet already exists for this user
|
2020-05-20 10:39:35 +02:00
|
|
|
user_exists(username=username)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
# grab user's public keys
|
2020-05-20 10:39:35 +02:00
|
|
|
public_keys = get_keys(username=username)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
# now make sure the user has forked zulip/zulip
|
2020-05-20 10:39:35 +02:00
|
|
|
fork_exists(username=username)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
api_token = config['digitalocean']['api_token']
|
|
|
|
# does the droplet already exist?
|
2020-05-20 10:39:35 +02:00
|
|
|
exit_if_droplet_exists(my_token=api_token, username=username, recreate=args.recreate)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
# set user_data
|
2020-05-20 10:39:35 +02:00
|
|
|
user_data = set_user_data(username=username, userkey_dicts=public_keys)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
# create droplet
|
|
|
|
ip_address = create_droplet(my_token=api_token,
|
|
|
|
template_id=template_id,
|
2020-05-20 10:39:35 +02:00
|
|
|
username=username,
|
2017-10-29 02:02:58 +01:00
|
|
|
tags=args.tags,
|
|
|
|
user_data=user_data)
|
|
|
|
|
|
|
|
# create dns entry
|
2020-05-20 10:39:35 +02:00
|
|
|
create_dns_record(my_token=api_token, username=username, ip_address=ip_address)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
# print completion message
|
2020-05-20 10:39:35 +02:00
|
|
|
print_completion(username=username)
|
2017-10-29 02:02:58 +01:00
|
|
|
|
|
|
|
sys.exit(1)
|