Publishing the Static Website Automatically

Updated: Apr 22, 2023

GitLab Pages

Just like GitHub Pages [1], GitLab Pages [2] are also available. GitLab Pages are basically a git repository with special .gitlab-ci.yml which will push the static html content you have in that repository under yourname.gitlab.io/projectname. It is easy to setup [3].

Using Gitlab CI to build and publish

There are two choices for me to publish my website

  • Build html and pdf locally in my laptop and push the resulted content to gitlab. By using their default GitLab Pages specific .gitlab-ci.yml, I can just publish easily

  • Write my own .gitlab-ci.yml and build both html and pdf content using Gitlab’s CI [4] and publish.

I selected the second way and here is my custom .gitlab-ci.yml

default:
  image: ubuntu

build0:
  stage: build
  only:
    - master
  script:
    - useradd -d "${CI_PROJECT_DIR}" -m -U -s /bin/bash user0
    - chown -R user0:user0 "${CI_PROJECT_DIR}"
    - export DEBIAN_FRONTEND=noninteractive
    - apt update -y -q && apt full-upgrade -y -q
    - apt install -y -q python3-minimal python3-distutils curl patch make git zip texlive-xetex fonts-freefont-otf latexmk xindy
    - apt install -y -q $(python3 --version | tr -d ' ' | cut -d. -f1,2)-venv
    - ln -s python3 /usr/bin/python
    - su user0 -c 'cd; DEV=1 ./scripts/bootstrap poetry run make'
  artifacts:
    name: "${CI_PROJECT_NAME}"
    paths:
      - "${CI_PROJECT_NAME}/${CI_PROJECT_NAME}.html.tar.gz"
      - "${CI_PROJECT_NAME}/${CI_PROJECT_NAME}.pdf"

pages:
  stage: deploy
  only:
    - master
  script:
    - cd "${CI_PROJECT_DIR}"
    - mkdir public && tar xvzf "${CI_PROJECT_NAME}/${CI_PROJECT_NAME}.html.tar.gz" -C public/
    - cp "${CI_PROJECT_NAME}/${CI_PROJECT_NAME}.pdf" public/_static/misc/
  artifacts:
    paths:
      - public

As you see, there are three jobs I defined,

  • html

  • pdf

  • pages

html job basically build html pages, pdf job builds pdf document and pages job is job specifically for publishing the contents to GitLab Pages.

Custom Domain

GitLab Pages also supports Custom Domain [5] with SSL/TLS automatically generated through LetsEncrypt [6]. But, There are bit of work to do in our DNS Records. Once we do the required changes in the DNS Records, GitLab will do the rest automatically.

Thus, everything is automated, all I need to do is write blog posts consistently, I hope I’ll try to do after this migration, because I feel I really like writing in reStructuredText.

End.