Gitlab CI Docker Container Build
To facilitate my move to Kubernetes for this and future websites/applications, I needed to containerize this site.
I use Gitlab CI so this post will cover building a Docker container and pushing it to a registry.
Dockerize
Since this is a static site that is generated by CI when a new commit is merged to master
, it is straightforward to Dockerize. Previously this site was hosted on a VPS with nginx serving the staic pages so I decided to use the nginx base image for this container. I simply need to copy the static site that is generated by the build in _site
into the correct directory.
Following the directions on the nginx Docker Hub page, my Dockerfile
looks as below:
Gitlab CI
Currently my Gitlab CI has a Docker runner, so I use Kaniko to build Docker containers without having to give privileged mode as Docker in Docker would require.
The containerize stage in my Gitlab CI config looks as below:
To allow Kaniko to push the image to Docker Hub, the registry credentials are set from Environment Variables set in Gitlab CI. The Dockerfile
is in the devops
directory and the resulting image is tagged as andrewtchin/andrewtchin.com:latest
and pushed.
Conclusion
After the image is pushed to Docker Hub, it is ready to be used in a Kubernetes Deployment which will be described in a future post.