Skip to content

Instantly share code, notes, and snippets.

@vrtmrz
Last active September 19, 2023 01:54
Show Gist options
  • Save vrtmrz/f4bba6cdc4216af5cacce3c945b2fb77 to your computer and use it in GitHub Desktop.
Save vrtmrz/f4bba6cdc4216af5cacce3c945b2fb77 to your computer and use it in GitHub Desktop.
deploy-livesync-subscribe-publish-kit-to-flyio.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/vrtmrz/f4bba6cdc4216af5cacce3c945b2fb77/deploy-livesync-subscribe-publish-kit-to-flyio.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"History:\n",
"- 14, Sep, 2023: Initial."
],
"metadata": {
"id": "HiRV7G8Gk1Rs"
}
},
{
"cell_type": "code",
"source": [
"import os\n",
"# Configuration\n",
"\n",
"# The region where is located near your vault.\n",
"os.environ['region']=\"nrt\"\n",
"# Your database URL\n",
"# If your vault is running also on the fly.io, you can use an internal address like [iad].[appname].internal\n",
"# Like this: `nrt.vororamoroz-vault.internal` (Fictitious example).\n",
"# However, anyway, it would be billed.\n",
"os.environ['LSSP_URL']=\"https://your-vault.example.com\"\n",
"\n",
"# CouchDB Credentials - Keep secrets\n",
"os.environ['LSSP_USERNAME']=\"username\"\n",
"os.environ['LSSP_PASSWORD']=\"password\"\n",
"\n",
"# Vault configuraiton\n",
"os.environ['LSSP_DATABASE']=\"the_database\"\n",
"# E2EE Passphrase\n",
"os.environ['LSSP_PASSPHRASE']=\"passphrase\"\n",
"# E2EE Passphrase, if you have enabled the path obfuscation.\n",
"os.environ['LSSP_OBFUSCATEPASSPHRASE']=\"passphrase\"\n",
"\n",
"# Blog configuration\n",
"conf = {\n",
" \"env\":{\n",
" \"LSSP_SUBSCRIBEDIR\" :\"blogdir/\", # Your notes under `blogdir` with `share: true` and anything non-md files will be exposed.\n",
" \"LSSP_HUGO_LANGUAGE\":\"en-US\", #\n",
" \"LSSP_HUGO_TITLE\" :\"Your blog name\", #\n",
" # You can update the blog with accessing `your-any-fav/update` and `your-any-fav/run`.\n",
" # Please change to anything your favourite and secret word.\n",
" \"LSSP_APIPATH\" :\"/your-any-fav\",\n",
" }\n",
"}\n",
"\n",
"# Let the client choose a random name for testing.\n",
"os.environ[\"APPNAME\"]=\"--generate-name\"\n",
"# If you want to specify the URL of your blog, you can uncomment and add fix `your-lssp-blog-name`. (Be careful to not be duplicated).\n",
"#os.environ[\"APPNAME\"]=\"--name your-lssp-blog-name\""
],
"metadata": {
"id": "RvIE1fHbMf4r"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Fetch the kit\n",
"!git clone --recursive https://github.com/vrtmrz/livesync-subscribe-publish-kit\n",
"%cd livesync-subscribe-publish-kit"
],
"metadata": {
"id": "uDy4IRew8M-g"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Nze7QoxLZ7Yx"
},
"outputs": [],
"source": [
"# Installation\n",
"# You have to set up your account in here.\n",
"!curl -L https://fly.io/install.sh | sh\n",
"!/root/.fly/bin/flyctl auth signup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MVJwsIYrbgtx"
},
"outputs": [],
"source": [
"# Generate server\n",
"!/root/.fly/bin/fly launch --auto-confirm ${APPNAME} --detach --no-deploy --region ${region}\n",
"!/root/.fly/bin/fly volumes create --region ${region} blog --size 1 --yes"
]
},
{
"cell_type": "code",
"source": [
"# Check the toml once.\n",
"!cat fly.toml"
],
"metadata": {
"id": "2RSoO9o-i2TT"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Modify fly.toml\n",
"!pip install mergedeep\n",
"from mergedeep import merge\n",
"import toml\n",
"\n",
"fly = toml.load('fly.toml')\n",
"override = {\n",
" \"build\":{\n",
" \"dockerfile\":\"./Dockerfile\"\n",
" },\n",
" \"mounts\":{\n",
" \"source\":\"blog\",\n",
" \"destination\":\"/app/content/\"\n",
" },\n",
" \"env\":{\n",
" \"LSSP_LOCALDIR\":\"/app/content/sitesrc/\",\n",
" \"LSSP_SCRIPT_CMD\":\"/app/build.sh\",\n",
" \"LSSP_SCRIPT_ARGS\":\"\",\n",
" \"LSSP_STATDIR\":\"/app/content/sitesrc/\",\n",
" \"LSSP_CONFIG_PATH\":\"/app/subscriber/config.jsonc\",\n",
" \"LSSP_HUGO_BASEURL\":\"https://\"+fly[\"app\"]+\".fly.dev/\",\n",
" \"LSSP_PUBLISH_PORT\":8080,\n",
" \"LSSP_KEYFILE\":\"\"\n",
" }\n",
"}\n",
"out = merge(fly,override,conf)\n",
"with open('fly.toml', 'wt') as fp:\n",
" toml.dump(out, fp)"
],
"metadata": {
"id": "cIzjk299TFJ8"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xWdsTCI6bzk2"
},
"outputs": [],
"source": [
"# Configure password\n",
"!/root/.fly/bin/fly secrets set LSSP_DATABASE=${LSSP_DATABASE}\n",
"!/root/.fly/bin/fly secrets set LSSP_PASSPHRASE=${LSSP_PASSPHRASE}\n",
"!/root/.fly/bin/fly secrets set LSSP_PASSWORD=${LSSP_PASSWORD}\n",
"!/root/.fly/bin/fly secrets set LSSP_URL=${LSSP_URL}\n",
"!/root/.fly/bin/fly secrets set LSSP_USERNAME=${LSSP_USERNAME}\n",
"!/root/.fly/bin/fly secrets set LSSP_OBFUSCATEPASSPHRASE=${LSSP_OBFUSCATEPASSPHRASE}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "k0WIQlShcXGa"
},
"outputs": [],
"source": [
"# Deploy server\n",
"# Be sure to shutdown after the test.\n",
"!/root/.fly/bin/flyctl deploy --detach --remote-only\n",
"\n",
"import subprocess, json\n",
"result = subprocess.run([\"/root/.fly/bin/flyctl\",\"status\",\"-j\"], capture_output=True, text=True)\n",
"if result.returncode==0:\n",
" hostname = json.loads(result.stdout)[\"Hostname\"]\n",
" print(\"Notes with `share: true` on your vault are now broadcasting! : https://%s/\" % (hostname))\n",
" print(\"---\")\n",
" print(\"You can fetch new notes to the blog by : https://%s%s/update\" % (hostname,fly[\"env\"][\"LSSP_APIPATH\"]))\n",
" print(\"You can update the blog by accessing : https://%s%s/run\" % (hostname,fly[\"env\"][\"LSSP_APIPATH\"]))\n",
" print(\"If you want to rebuild the blog, by here: https://%s%s/rebuild\" % (hostname,fly[\"env\"][\"LSSP_APIPATH\"]))\n",
" print(\"---\")\n",
" print(\"Just to be sure, but the dashboard is : https://fly.io/apps/%s/settings\" % (fly[\"app\"]))\n",
"else:\n",
" print(\"Something occured.\")\n"
]
},
{
"cell_type": "markdown",
"source": [
"Cheers! You got your blog. However, **Please confirm that unexpected notes were not exposed again.**\n",
"\n",
"Also, You can destroy the blog in an instant from the dashboard of fly.io.\n"
],
"metadata": {
"id": "VBuqzGYoNW8k"
}
}
],
"metadata": {
"colab": {
"provenance": [],
"private_outputs": true,
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
},
"gpuClass": "standard"
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment