Skip to content

Instantly share code, notes, and snippets.

@hiyukoim
Last active September 14, 2024 17:06
Show Gist options
  • Select an option

  • Save hiyukoim/f7853639aa7064953100e65018826c93 to your computer and use it in GitHub Desktop.

Select an option

Save hiyukoim/f7853639aa7064953100e65018826c93 to your computer and use it in GitHub Desktop.
copy-of-install-ghost-for-free-on-fly-io.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyPgdGURCr/+bAYfIu6+oiWH",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/hiyukoim/f7853639aa7064953100e65018826c93/copy-of-install-ghost-for-free-on-fly-io.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Host Ghost 5 + MySQL 8 on Fly.io Free Tier\n",
"\n",
"This awsome script originall came from this awesome article by @curiositry.\n",
"All the important details are written on this article, so before you jump in, read this blog post carefully.\n",
"\n",
"https://www.autodidacts.io/host-ghost-mysql8-on-fly-io-free-tier/\n",
"\n",
"Naturally, I'm not the original creator of the script.\n",
"I just wanted to get it on google collab for make it easier for everybody :)\n",
"Therefore, this collab is not maintained by the original script author, so it might not be up-to-date by the time you use it.\n",
"\n",
"Follow these steps to deploy your Ghost blog:\n",
"\n",
"1. Fill in the \"Input Fields\" section with your desired app name, MySQL password, and MySQL root password\n",
"2. Select your preferred region from the \"Select Region\" dropdown.\n",
"3. Run the installation script cell one by one.\n",
"4. When prompted, authenticate with Fly.io in the browser window that opens.\n",
"5. Wait for the deployment to complete. This may take several minutes.\n",
"\n",
"Once the deployment is finished, your Ghost blog will be available at an address like `https://your-app-name.fly.dev`.\n",
"\n",
"Note: You may need to wait a few minutes after deployment for your blog to become fully accessible.\n"
],
"metadata": {
"id": "a8UdAfHEeCly"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5efsC5h_d7nr"
},
"outputs": [],
"source": [
"#@title Set Up Your Ghost Blog on Fly.io\n",
"#@markdown Decide on a unique app name and database passwords, and make sure to write them down and save them in a secure place.\n",
"app_name = \"(e.g., my-awesome-blog)\" #@param {type:\"string\"}\n",
"mysql_password = \"(e.g., Database!Pass0)\" #@param {type:\"string\"}\n",
"mysql_root_password = \"(e.g., Database-RootPass7)\" #@param {type:\"string\"}"
]
},
{
"cell_type": "code",
"source": [
"#@title Select Region\n",
"region = \"sea/Seattle, Washington (US)\" #@param [\"ams/Amsterdam, Netherlands\",\"arn/Stockholm, Sweden\",\"atl/Atlanta, Georgia (US)\",\"bog/Bogotá, Colombia\",\"bos/Boston, Massachusetts (US)\",\"cdg/Paris, France\",\"den/Denver, Colorado (US)\",\"dfw/Dallas, Texas (US)\",\"ewr/Secaucus, NJ (US)\",\"eze/Ezeiza, Argentina\",\"gdl/Guadalajara, Mexico\",\"gig/Rio de Janeiro, Brazil\",\"gru/Sao Paulo, Brazil\",\"hkg/Hong Kong, Hong Kong\",\"iad/Ashburn, Virginia (US)\",\"jnb/Johannesburg, South Africa\",\"lax/Los Angeles, California (US)\",\"lhr/London, United Kingdom\",\"mad/Madrid, Spain\",\"mia/Miami, Florida (US)\",\"nrt/Tokyo, Japan\",\"ord/Chicago, Illinois (US)\",\"otp/Bucharest, Romania\",\"phx/Phoenix, Arizona (US)\",\"qro/Querétaro, Mexico\",\"scl/Santiago, Chile\",\"sea/Seattle, Washington (US)\",\"sin/Singapore, Singapore\",\"sjc/San Jose, California (US)\",\"syd/Sydney, Australia\",\"waw/Warsaw, Poland\",\"yul/Montreal, Canada\",\"yyz/Toronto, Canada\" ] {allow-input: true}"
],
"metadata": {
"id": "Iarazu8veiWa"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Install Fly.io CLI\n",
"!curl -L https://fly.io/install.sh | sh\n",
"import os\n",
"os.environ['PATH'] = f\"/root/.fly/bin:{os.environ['PATH']}\"\n",
"!echo $PATH\n",
"\n",
"#@title Verify Fly.io CLI Installation\n",
"!flyctl version"
],
"metadata": {
"id": "QTpkzrPve5EB"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Sign up or Login\n",
"!flyctl auth signup"
],
"metadata": {
"id": "uNzgonpofOpl"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"%%bash -s \"$app_name\" \"$mysql_password\" \"$mysql_root_password\" \"$region\"\n",
"# Get parameters\n",
"appname=$1\n",
"mysqlpassword=$2\n",
"mysqlrootpassword=$3\n",
"region=$(echo $4 | cut -d'/' -f1)\n",
"\n",
"# Create a directory for the project and enter it\n",
"mkdir ghost-flyio && cd ghost-flyio\n",
"\n",
"# Create an app\n",
"flyctl launch --name $appname --image=ghost:5-alpine --vm-memory 512 --region $region --no-deploy --org personal\n",
"\n",
"# Provision a volume for Ghost's content\n",
"flyctl volumes create ghost_data --region $region --size 1 --auto-confirm\n",
"\n",
"# Install sed if not already installed\n",
"command -v sed >/dev/null 2>&1 || { echo >&2 \"sed (Stream EDitor) required and not found. Installing...\"; sudo apt install sed; }\n",
"\n",
"# Update the port to Ghost's default (2368) and set min_machines_running to 1\n",
"sed -i 's/internal_port = 8080/internal_port = 2368/g' fly.toml\n",
"sed -i 's/min_machines_running = 0/min_machines_running = 1/g' fly.toml\n",
"\n",
"# Append info about where to find the persistent storage to fly.toml\n",
"cat >> fly.toml << BLOCK\n",
"[mounts]\n",
"source=\"ghost_data\"\n",
"destination=\"/var/lib/ghost/content\"\n",
"BLOCK\n",
"\n",
"# Set Ghost url\n",
"flyctl secrets set url=https://$appname.fly.dev\n",
"\n",
"# Spin up a second instance for our database server\n",
"mkdir ghost-flyio-mysql && cd ghost-flyio-mysql\n",
"\n",
"# Create an app for our mysql\n",
"flyctl launch --name ${appname}-mysql --image=mysql:8 --vm-memory 512 --region $region --no-deploy --org personal\n",
"\n",
"# Create a persistent volume for our MYSQL data\n",
"fly volumes create mysql_data --size 2 --region $region --auto-confirm\n",
"\n",
"fly secrets set MYSQL_PASSWORD=$mysqlpassword MYSQL_ROOT_PASSWORD=$mysqlrootpassword\n",
"\n",
"# Add our database credentials to the Ghost instance\n",
"fly secrets set database__client=mysql -a $appname\n",
"fly secrets set database__connection__host=${appname}-mysql.internal -a $appname\n",
"fly secrets set database__connection__user=ghost -a $appname\n",
"fly secrets set database__connection__password=$mysqlpassword -a $appname\n",
"fly secrets set database__connection__database=ghost -a $appname\n",
"fly secrets set database__connection__port=3306 -a $appname\n",
"fly secrets set NODE_ENV=production\n",
"\n",
"cat > fly.toml << BLOCK2\n",
"app = \"$appname-mysql\"\n",
"primary_region = \"$region\"\n",
"\n",
"[build]\n",
"image = \"mysql:8\"\n",
"\n",
"[env]\n",
"MYSQL_DATABASE = \"ghost\"\n",
"MYSQL_USER = \"ghost\"\n",
"\n",
"[processes]\n",
"app = \"--datadir /data/mysql --mysql-native-password=ON --performance-schema=OFF --innodb-buffer-pool-size 64M\"\n",
"\n",
"[[mounts]]\n",
"source = \"mysql_data\"\n",
"destination = \"/data\"\n",
"\n",
"[http_service]\n",
"internal_port = 3306\n",
"force_https = true\n",
"auto_stop_machines = \"stop\"\n",
"auto_start_machines = true\n",
"min_machines_running = 1\n",
"processes = [\"app\"]\n",
"\n",
"[[vm]]\n",
"memory = \"512mb\"\n",
"cpu_kind = \"shared\"\n",
"cpus = 1\n",
"BLOCK2\n",
"\n",
"# Note: if you aren't trying to stay within the free tier, you might want to remove the performance schema and buffer pool size flags above.\n",
"\n",
"# Deploy MySQL server\n",
"flyctl deploy\n",
"\n",
"cd ../\n",
"\n",
"# Deploy Ghost application server\n",
"flyctl deploy\n",
"\n",
"# Boom! We're airborne."
],
"metadata": {
"id": "N1k04U0xfeUw"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment