Self-Hosted Blog Part 6 - Build

2/12/2021 2-minute read

In part 5 we got our static site into a container. Now, we’re going to replicate the build process I did on my local machine in my CI/CD pipeline on every git push. I’m hosting the source for the site in GitHub. For this, I’m going to use GitHub Actions, because it’s free and integrated right into GitHub. GitHub Actions defines workflows in your repository, and then executes those workflows on various triggers.

The basic steps I want my CI/CD pipeline to execute are:

  1. Build the static site
  2. Build a docker container for x86_64 and arm64
  3. Push that docker container to Docker Hub
  4. Tell Kubernetes to deploy the latest container

We will cover steps 1-3 in this portion of the tutorial and step 4 in the next section. I spent some time researching how to build an actions workflow that does exactly that, but really it’s pretty straightforward once you see it materialized in the configuration YAML:

name: ci

      - 'main'

    runs-on: ubuntu-latest
        name: Checkout
        uses: actions/checkout@v2
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
        name: Login to DockerHub
        uses: docker/login-action@v1 
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
        name: Build and push
        uses: docker/build-push-action@v2
          context: .
          platforms: linux/amd64,linux/arm64
          push: true
          tags: clintsharp/blog:latest

It should be pretty straightforward to read. It checks out the repo. It sets up QEMU, which will be used by docker buildx. We need to build both x86_64 images so I can run them on my development machine and arm64 images to run on the Raspberry Pis. docker buildx makes this very easy. We setup docker buildx. We login to Docker Hub with secrets stored in our Repo settings. Next, we use the build and push action to build x86_64 and arm64 images and push them to Docker Hub.

Getting this initial configuration took some research and experimenting, but it was one of the more straight forward portions of the project. Now, when I push a change to the main branch, GitHub actions rebuilds my container and pushes it up to Docker Hub. You can see the build logs on GitHub.

Next, we’re going to get our blog running in K8S

Posts in this Series