Automate Posting Hugo Blog to Social Sites (with a db) Part 3
Jul 12, 2024
Automate Blog with GCP MYSQL Server
So I am just going to create my own CMS. I know there are other solutions.. but I am nearly there.. I also want to manage content like i manage a linux system.. So I am going to do this with a db.. bashscripts.. and linux servers.
Create the MYSQL Instance
I could just use a db wihtin a container.. but i want to scale this out..I have a few ideas.. So I will be initializing the server on gcp
Write an initialization script
#!/bin/bash
# Source the .env file to load environment variables
# Set other variables
PROJECT_ID="smart-axis-421517"
INSTANCE_NAME="jnapolitano-db"
REGION="us-west2" # e.g., us-central1
DATABASE_NAME="jnapolitano"
BUILDS_SQL_FILE="builds.sql" # Name of your builds SQL file
FEED_SQL_FILE="feed.sql" # Name of your feeds SQL file
# Authenticate with GCP (make sure you have gcloud SDK installed and authenticated)
# Set the project
# Enable the Cloud SQL Admin API
# Create a Cloud SQL instance
# Set the root password using environment variable
# Create a user called 'cobra' using environment variable
# Grant superuser privileges to 'cobra'
# Optional: Create a database (uncomment if needed)
# DATABASE_NAME="your-database-name"
# gcloud sql databases create $DATABASE_NAME --instance=$INSTANCE_NAME
# Create a database
# Execute the SQL files to create the 'builds' and 'feeds' tables
Create a .env file to save your passwords
There are a number of ways to keep passwords out of github. In this case I am just going to add the passes to a .env file and source it
the file looks like
# .env
ROOT_PASSWORD="your-pass"
COBRA_PASSWORD="your-pass"
Run
Chmod
Write the sql files used to create the feed and builds tables
I added a submodule that contains my scripts gh link
Builds
(
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
link VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
generator VARCHAR(255),
language VARCHAR(10),
copyright VARCHAR(255),
lastBuildDate TIMESTAMP,
atom_link_href VARCHAR(255),
atom_link_rel VARCHAR(50),
atom_link_type VARCHAR(50)
);
Feed
(
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
link VARCHAR(255) NOT NULL,
pubDate TIMESTAMP,
guid VARCHAR(255),
description TEXT
);
Run the script
./yourscript
The script should work and create your basic files.. I have some more work to do to create an api to update the tables.