Skip to content

Commit

Permalink
chore(do/1-click): sunset DigitalOcean 1-click app (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
iainsproat authored Jun 21, 2024
1 parent 2e59d23 commit 08d1bff
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 379 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ What is Speckle? Check our [![YouTube Video Views](https://img.shields.io/youtub

Give Speckle a try in no time by:

- [![speckle](https://img.shields.io/badge/https://-app.speckle.systems-0069ff?style=flat-square&logo=hackthebox&logoColor=white)](https://app.speckle.systems) ⇒ creating an account
- [![create a droplet](https://img.shields.io/badge/Create%20a%20Droplet-0069ff?style=flat-square&logo=digitalocean&logoColor=white)](https://marketplace.digitalocean.com/apps/speckle-server?refcode=947a2b5d7dc1) ⇒ deploying an instance in 1 click
- [![app.speckle.systems](https://img.shields.io/badge/https://-app.speckle.systems-0069ff?style=flat-square&logo=hackthebox&logoColor=white)](https://app.speckle.systems) ⇒ Create an account at app.speckle.systems
- [![Deploy on your own infrastructure with docker compose](https://img.shields.io/badge/https://-speckle.guide-0069ff?style=flat-square&logo=hackthebox&logoColor=white)](<[https://](https://speckle.guide/dev/server-manualsetup.html)>) ⇒ Deploy on your own infrastructure with Docker Compose
- [![Deploy on your own infrastructure with docker compose](https://img.shields.io/badge/https://-speckle.guide-0069ff?style=flat-square&logo=hackthebox&logoColor=white)](<[https://](https://speckle.guide/dev/server-setup-k8s.html)>) ⇒ Deploy on your own infrastructure with Kubernetes

## Resources

Expand Down
17 changes: 0 additions & 17 deletions utils/1click_image_scripts/download.sh

This file was deleted.

203 changes: 7 additions & 196 deletions utils/1click_image_scripts/setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/usr/bin/env python3

import os
import socket
import subprocess
import secrets
import ruamel.yaml # this module preserves yaml comments and whitespaces
from ruamel.yaml.scalarstring import DoubleQuotedScalarString

FILE_PATH = os.path.dirname(os.path.abspath(__file__))

LOGO_STR = """
_____ _ _ _____
/ ___| | | | | / ___|
Expand All @@ -21,202 +12,22 @@
"""


def get_local_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
if not ip:
print("Error: Can't get local IP address")
exit(1)
return ip


def read_domain(ip):
print("\nYou can set up a domain name for this Speckle server.")
print(
"Important: To use a domain name, you must first configure it to point to this VM address (so we can issue the SSL certificate)"
)
print(f"VM address: {ip}")
while True:
domain = input("Domain name (leave blank to use the IP address): ").strip()
if not domain:
return None
try:
domain_ip = socket.gethostbyname(domain.strip())
except Exception as ex:
print(f"Error: Domain '{domain}' cannot be resolved: {str(ex)}")
continue

if domain_ip != ip:
print(f"Error: Domain '{domain}' points to {domain_ip} instead of {ip}")
continue

return domain


def read_email_settings(domain):
def main():
print(LOGO_STR)
print(
"\nYou should configure an email provider to allow the Speckle Server to send emails."
"\nAs of March 2024, Speckle server DigitalOcean 1-click setup script is no longer supported."
)
print(
"Supported vendors: Any email provider that can provide SMTP connection details (mailjet, mailgun, etc)."
"\nPlease use the official Speckle Server installation guide to install Speckle Server on your own infrastructure."
)
print(
"Important: If you don't configure email details, some features that require sending emails will not work, nevertheless the server should be functional."
"\nThis could be on a DigitalOcean Droplet that you have created yourself using an Ubuntu image."
)
while True:
enable_email = False
while True:
enable_email = input("Enable emails? [Y/n]: ").strip().lower()
if enable_email in ["n", "no"]:
enable_email = False
break
elif enable_email in ["", "y", "yes"]:
enable_email = True
break
else:
print("Unrecognized option")
continue

if not enable_email:
return None

print("Enter your SMTP connection details offered by your email provider")
smtp_host = input("SMTP server / host: ").strip()
smtp_port = input("SMTP port: ").strip()
try:
int(smtp_port)
except Exception:
print("Error: SMTP port must be a number. Retrying...")
continue
smtp_user = input("SMTP Username: ").strip()
smtp_pass = input("SMTP Password: ").strip()

if domain:
default_from_email = "no-reply@" + domain
else:
default_from_email = ""
email_from = input(f"Email address to send email as [{default_from_email}]: ")
if not email_from.strip():
email_from = default_from_email

if (
not smtp_host
or not smtp_port
or not smtp_user
or not smtp_pass
or not email_from
):
print("Error: One or more fields were empty. Retrying...")
continue

return {
"host": smtp_host,
"port": smtp_port,
"user": smtp_user,
"pass": smtp_pass,
"from": email_from,
}


def main():
print(LOGO_STR)
ip = get_local_ip()

###
### Read user input
#########
domain = read_domain(ip)
if domain:
canonical_url = f"https://{domain}"
else:
canonical_url = f"http://{ip}"

email = read_email_settings(domain)

###
### Create docker-compose.yml from the template
#########
print("\nConfiguring docker containers...")

yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
with open(os.path.join(FILE_PATH, "template-docker-compose.yml"), "r") as f:
yml_doc = yaml.load(f)
env = yml_doc["services"]["speckle-server"]["environment"]
env["CANONICAL_URL"] = DoubleQuotedScalarString(canonical_url)
env["FRONTEND_ORIGIN"] = DoubleQuotedScalarString(canonical_url)
env["SESSION_SECRET"] = DoubleQuotedScalarString(secrets.token_hex(32))
if email:
env["EMAIL"] = DoubleQuotedScalarString("true")
env["EMAIL_HOST"] = DoubleQuotedScalarString(email["host"])
env["EMAIL_PORT"] = DoubleQuotedScalarString(email["port"])
env["EMAIL_USERNAME"] = DoubleQuotedScalarString(email["user"])
env["EMAIL_PASSWORD"] = DoubleQuotedScalarString(email["pass"])
env["EMAIL_FROM"] = DoubleQuotedScalarString(email["from"])
else:
env["EMAIL"] = DoubleQuotedScalarString("false")

fe2env = yml_doc["services"]["speckle-frontend-2"]["environment"]
fe2env["NUXT_PUBLIC_SERVER_NAME"] = DoubleQuotedScalarString(canonical_url)
fe2env["NUXT_PUBLIC_API_ORIGIN"] = DoubleQuotedScalarString(canonical_url)
fe2env["NUXT_PUBLIC_BASE_URL"] = DoubleQuotedScalarString(canonical_url)

with open(os.path.join(FILE_PATH, "docker-compose.yml"), "w") as f:
f.write("# This file was generated by SpeckleServer setup.\n")
f.write("# If the setup is re-run, this file will be overwritten.\n\n")
yaml.dump(yml_doc, f)

###
### Run the new docker compose file (will update containers if already running)
#########
subprocess.run(
["bash", "-c", f'cd "{FILE_PATH}"; docker compose up -d'], check=True
)

###
### Update nginx config and restart nginx
#########
print("\nConfiguring local nginx...")

nginx_conf_str = "# This file is managed by SpeckleServer setup script.\n"
nginx_conf_str += (
"# Any modifications will be removed when the setup script is re-executed\n\n"
)
with open(os.path.join(FILE_PATH, "template-nginx-site.conf"), "r") as f:
nginx_conf_str += f.read()
if domain:
nginx_conf_str = nginx_conf_str.replace("TODO_REPLACE_WITH_SERVER_NAME", domain)
else:
nginx_conf_str = nginx_conf_str.replace("TODO_REPLACE_WITH_SERVER_NAME", "_")
with open("/etc/nginx/sites-available/speckle-server", "w") as f:
f.write(nginx_conf_str)
subprocess.run(["nginx", "-s", "reload"], check=True)

###
### Run letsencrypt on new config
#########
if domain:
print("\n***")
print(
"*** Will now run LetsEncrypt utility to generate https certificate. Please answer any questions that are presented"
)
print(
"*** We highly recommend setting a good email address so that you are notified if there is any action needed to renew certificates"
)
print("***")
subprocess.run(["certbot", "--nginx", "-d", domain])

print("\nConfiguration complete!")
print("You can access your speckle server at: " + canonical_url)
print(LOGO_STR)
print("\nOne more thing and you are ready to roll:")
print(
f" - Go to {canonical_url} in your browser and create an account. The first user to register will be granted administrator rights."
"\nOur documentation can be found at https://speckle.guide/dev/server-manualsetup.html"
)
print(
" - Fill in information about your server under your profile page (in the lower left corner)."
"\nIf you require to view previous versions of the 1-click setup script, please review the history of the speckle-server repository on GitHub."
)
print("\nHappy Speckling!")

Expand Down
129 changes: 0 additions & 129 deletions utils/1click_image_scripts/template-docker-compose.yml

This file was deleted.

Loading

0 comments on commit 08d1bff

Please sign in to comment.