GitHub Container CI/CD

Table of Contents

Background

I’m working on setting up a fully automated static blog workflow for this blog. Eventually I’ll move this to be hosted on a Kubernetes cluster but thats still on the todo list. The basic workflow looks to be something like this Blog Post Workflow This workflow shows that basically I want a github action/workflow (I’m still not sure on the terminology around these) to build the site with Jekyll and then create and push a container to a container registry with this.

Building the Workflow

Since I’m using the Chirpy theme, it came with a prebuilt github workflow, I deleted almost everything in it and ended up with the following from the original

name: 'Automatic build'
on:
  push:
    branches:
      - main
    paths-ignore:
      - .gitignore
      - README.md
      - LICENSE

jobs:
  continuous-delivery:

    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0  # for posts's lastmod

I then modified the ruby version

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.1
          bundler-cache: true

I then setup a task to build the site using a shell script which just calls jekyll build

      - name: Build Site
        run: bash tools/buildsite.sh

Then the fun parts begin, I use digial ocean so I setup a container registry on that and did the needed login for DO

      - name: SEtup DigitalOcean doctl
        uses: digitalocean/action-doctl@v2
        with:
          token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

I built the container next using the standard method, although I do not currently tag a version. This is something that I need to fix still

      - name: Build Container - Mannually
        run: docker build -t mattwmarshallblog .

I then login to the container registry, tag it, and push it to the appropriate registry

      - name: Login to DO Registry
        run: doctl registry login --expiry-seconds 600

      - name: Tag Container
        run: docker tag <docker-registry-path>/mattwmarshallblog
        
      - name: Push to DO Container Registry
        run: docker push <docker-registry-path>/mattwmarshallblog

Where I Got This Info

I used the scripts included in Chirpy for the build of the site. I then found a great small container image for hosting static sites from this Here. For creating the container and pushing I got the general idea from This Blog

comments