This blog is deployed using a series of technologies from Kubernetes and Helm down to its core using Hugo. One of the annoyances with Hugo is that one needs to build the static content before it is deployed. This is easy enough to do, all you need to do is invoke the
hugo command while in the correct directory, but I constantly forget to to this manual step. Instead of manually trying to remember to run this, I built out my Drone CI to do it for me.
First I built a container that includes Hugo. I have made this available via my Docker Hub: binaryronin/drone-hugo. This container doesn’t require any arguments and works on the assumption that Drone automatically clones to
/drone/src and moves this directory between the containers. In my example below however, my blog does not sit at the root level of the git repo, but in a subdirectory called
blog. I also make use of Git Submodules for my theme, so it is important to also make sure and clone those as well.
- name: clone submodules image: alpine/git commands: - git submodule init - git submodule update --recursive --remote - name: build static content image: binaryronin/drone-hugo:latest pull: always commands: - cd /drone/src/blog - hugo
That’s really about it. After that is all the normal stuff of building the container and deploying it with Helm. The entire configuration is included below for the sake of completeness.
--- kind: pipeline type: kubernetes name: build and deploy steps: - name: clone submodules image: alpine/git commands: - git submodule init - git submodule update --recursive --remote - name: lint chart image: pelotech/drone-helm3 settings: mode: lint chart: ./helm/ - name: build static content image: binaryronin/drone-hugo:latest pull: always commands: - cd /drone/src/blog - hugo - name: build production container image: plugins/buildah-docker settings: repo: binaryronin/website tags: latest username: from_secret: docker_username password: from_secret: docker_secret when: branch: - master - name: deploy image: pelotech/drone-helm3 settings: mode: upgrade chart: ./helm/ namespace: blog release: binaryronin values_files: ./helm/values.yaml skip_tls_verify: true environment: KUBE_API_SERVER: from_secret: k8s_api_server KUBE_TOKEN: from_secret: k8s_token KUBE_SERVICE_ACCOUNT: from_secret: k8s_service_account when: branch: - master - name: notify image: appleboy/drone-discord settings: webhook_id: from_secret: discord_id webhook_token: from_secret: discord_secret when: branch: - master image_pull_secrets: - docker_pull