The reason for starting this, is that:
Jekyll has a simple way to author new articles using either markdown
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.
Daniel Azuma's article affirmed my prior experiences with hosting with Cloud Run.
Docker allows you to nicely test your deployment locally, and then easily deploy to 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 |
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