Skip to content
⚠️ This wiki is intended and relevant only for DTU Compute - Department of Applied Mathematics and Computer Science

Pages

Warning

STATUS:DRAFT1 STATUS:EFER

You can host a project or personal web page via the Pages feature in GitLab.

Deploy pages to external web server

Alternatively, host your pages on another server, such as the DTU Compute Web Server by adding a deploy stage to your project’s .gitlab-ci.yml file, and setting up variables for your SSH keys. In the following example, we use Jane with DTU username jado who wants to deploy her GitLab Pages made with Hugo, to her personal people.compute.dtu.dk site:

Create a new SSH key pair for this purpose and authorize it on the remote host:

ssh-keygen -f ~/.ssh/deploy -C "GitLab Pages CI"
ssh-copy-id -i ~/.ssh/deploy jado@linuxterm1.compute.dtu.dk

Using the GitLab web interface, in your Pages repository go to Settings → CI/CD and expand Variables

image

Two variables need to be added here, with the first one called SSH_PRIVATE_KEY with its value being the content of ~/.ssh/deploy and the second variable called SSH_KNOWN_HOSTS with its value being the output of the following command (leaving out comments starting with #):

ssh-keyscan linuxterm1.compute.dtu.dk

With the variables set it is time to add a basic deploy stage to the .gitlab-ci.yml file:

# All available Hugo versions are listed here: https://gitlab.com/pages/hugo/container_registry
image: registry.gitlab.com/pages/hugo:latest

variables:
  GIT_SUBMODULE_STRATEGY: recursive

deploy:
  timeout: 5 minutes
  script:
    # Need SSH client for rsync to use
    - apk add rsync openssh-client
    # Add the key and known host
    - mkdir -p ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - echo "$SSH_PRIVATE_KEY" > ~/.ssh/key
    - chmod -R 700 ~/.ssh
    - eval "$(ssh-agent -s)"
    - ssh-add ~/.ssh/key
    # Build the website
    - hugo
    # Sync the built site
    - rsync -cavz --delete ./public/ jado@linuxterm1.compute.dtu.dk:/www/home/jado/public_html/
  only:
  - master

# Uncomment lines below to also deploy to Gitlab Pages server
#pages:
#  script:
#  - hugo
#  artifacts:
#    paths:
#    - public
#  only:
#  - master

Add and commit the changes and push to the repository. If the CI/CD Pipeline passed, Jane’s website is now available at https://people.compute.dtu.dk/jado

Last updated on