Skip to main content

Migrating to a static site

The old happy consultancy site

Migrating the old site

The old site was hosted on Drupal 6 and when we were planning to redesign it and move to Drupal 8, the question arose what to do with the old site. We decided to archive it and host it as a static site, for nostalgic reasons. Below is a description of how we did this using a combination of Httrack, Docker and Kubernetes. The end result is a static site that is build in a CI/CD pipeline and deployed on a Kubernetes cluster using Helm.

Check out the end result:

Archiving the site

Before mirroring a website, disable commenting, contact forms, logging in, etc. This will prevent inactive elements to show up on the static copy. Depending on the website or cms used, you may need to do some clean up in the mirror after downloading. 

Start by making a local copy using httrack (wget, curl, c.s. can be used as well, but I found Httrack worked best):

$ mkdir happycons && cd happycons
$ httrack -O httrackmirror -v -s0
$ cd httrackmirror/
$ cd

You can go through the local site, or browse it from a browser, fixing any broken links or leftover elements. A quick way to bring it up in a webserver is to create an Nginx container to serve the content:

FROM nginx:latest
COPY /usr/share/nginx/html

Build and run the container: 

$ docker build -t happycons .
$ docker run --rm -d -p 6080:80 happycons


Building the container

We would like to host the site in a git repo and automate creating and pushing the image. We'll use Gitlab CI/CD in this case.

With the Dockerfile already present, we just need to add a .gitlab-ci.yml to configure building and pushing of the container image. We are using the variables as defined for the Gitlab repository. Also, we'll use Kaniko to do the building, rather than regular Docker. 

    - build

  stage: build
    entrypoint: [""]
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor  --cache=true --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE 

Commit and push to the Gitlab server. Gitlab will trigger a build that creates the container image and then pushes it to it's registry

Helm chart and deployment

We'll create a simple helm chart so we can easily deploy the static website on our kubernetes cluster. We'll need to define the deployment, service, ingress and also attach a certificate from LetsEncrypt using the cert-manager already available in the cluster.

Basic structure of the Helm chart:

├── Chart.yaml             #Version/name of chart
├── templates                   
│   ├── certificate.yaml   #Defines the ssl cert to request
│   ├── deployment.yaml    #Defines the deployment
│   ├── ingress.yaml       #Defines the ingress (using traefik here)
│   └── services.yaml      #Service
└── values.yaml            #Contains image tagname, repository, pull secret to use and certissuer to use

Then we simply deploy the static site to our cluster. Ingress, with a free LetsEncrypt certificate will be setup. We could scale up the replicas if we expected a lot of traffic.