Starting a New Blog, and hosting it

Doing it as simply and cheaply as possible.

Posted by Scott K. Ralph on November 10, 2020 · 4 mins read

Motivation

The reason for starting this, is that:

  • I wanted to play more with GCP Cloud Run, and see if I could deploy something simple, cheaply.
  • I was getting pretty tired of the FaceBook censorship of anything progressive while letting all the ALT-right miscreants do anything they wanted, all in the name of Bay-Area-Libertarianism..... Enough said.
  • I wanted to see if I could host something that was low-volume (traffic-wise), very cheaply with Google Cloud Platform.

The Parts:

  1. Jeckyll

    Jekyll has a simple way to author new articles using either markdown

  2. Clean Blog Style

    This is a simple clean blogging style that can be used as a theme to make the out-of-the-box theme appear a little less dowdy.

  3. A good article on how to set it up (ref: blog)

    Daniel Azuma's article affirmed my prior experiences with hosting with Cloud Run.

  4. Docker

    Docker allows you to nicely test your deployment locally, and then easily deploy to Cloud Run.

  5. Cloud Run

    Packaging everything into docker, and running in Kubernetes is great. You don't have to worry about provisioning. You get all of the nice benefits of Kubernetes, but without the cost of having a provisioned cluster. Stealing the pricing table entry from Cloud Run Pricing:

    Tier CPU Memory Requests Networking
    Free First 180,000 vCPU-seconds free per month First 360,000 GiB-seconds free per month 2 million requests free per month 1 GiB free egress within North America per month
    You can see that the essentially the first 5 hours of CPU are free. If I ever run beyond that, then either someone is hitting it just to be mean, or I've magically become popular. I get an alert if the cost per month ever exceeds $25.00.

  6. The Full Lifecycle

    First start up the jekyll server. This monitors the files that you change, and automatically re-renders the HTML as you save files.

    This is done with the command:
    bundle exec jekyll serve --watch

    The blog can be previewed with a web browser with the url http://localhost:4000

    Once I am happy with the content, then I can deploy locally to a local Docker instance

    FROM ruby:2 AS build
    RUN gem install bundler
    WORKDIR /workspace
    COPY Gemfile* /workspace/
    RUN bundle install
    COPY . /workspace
    ENV JEKYLL_ENV=production
    RUN bundle exec jekyll build
    FROM nginx:1

    WORKDIR /app
    COPY _app /app
    COPY --from=build /workspace/_site /app/site
    CMD ["/app/start.sh"]

    This just starts with a Ruby image, installs the bundler, and then performs the Jekyll build. The second part just takes the static HTML content, and serves it with an NGIX small apache-server.

    To hide things away from Jekyll, all of the interesting scripts are kept hidden in folders _app and _build.

    To test the local Docker image, I have a helpful script build_local.sh that simply does:
    docker build -t blog -f _build/Dockerfile .
    and another run_local.sh that does this:
    google-chrome http://localhost:8888
    docker run --rm -it -p 8888:8888 blog

    Building for production is done on Cloud Build, with the script:
    gcloud builds submit --config _build/cloudbuild.yaml \
    --substitutions _IMAGE=gcr.io/scottralphorg-container/blog:v1

    Upon completion the docker image is stored within GCP's container registry.

    Deploying to Cloud Run is as simple as:
    gcloud run deploy blog --platform managed --region us-central1 \
    --image gcr.io/scottralphorg-container/blog:v1 \
    --allow-unauthenticated --concurrency 80

    The last argument limits the number of concurrent accesses to 80, the current limit for single cloud-run instances.

    scott@ubuntu-server:~/Documents/git/blog$ _build/deploy.sh
    Deploying container to Cloud Run service [blog] in project [scottralphorg-container] region [us-central1]
    ✓ Deploying... Done.
    ✓ Creating Revision...
    ✓ Routing traffic...
    ✓ Setting IAM Policy...
    Done.
    Service [blog] revision [blog-00005-hev] has been deployed and is serving 100 percent of traffic.
    Service URL: https://blog-sz6gql4gna-uc.a.run.app