hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

hosting-on-keycdn.md (4398B)

    1 ---
    2 title: "Hosting on KeyCDN"
    3 date: 2017-09-12
    4 description: "Accelerate your Hugo site globally with a KeyCDN integration. This tutorial shows you how to setup your static site as a GitLab page behind a KeyCDN pull zone."
    5 categories: [hosting and deployment]
    6 keywords: [keycdn,hosting,deployment,cdn]
    7 menu:
    8   docs:
    9     parent: "hosting-and-deployment"
   10     weight: 40
   11 slug: ""
   12 aliases: []
   13 toc: false
   14 draft: false
   15 ---
   16 
   17 [KeyCDN](https://www.keycdn.com/) provides a multitude of features to help accelerate and secure your Hugo site globally including Brotli compression, Let's Encrypt support, Origin Shield, and more.
   18 
   19 ## Assumptions
   20 
   21 - You already have a Hugo page configured
   22 - You have a GitLab account
   23 - You have a KeyCDN account
   24 
   25 ## Create a KeyCDN Pull Zone
   26 
   27 The first step will be to login to your KeyCDN account and create a new zone. Name this whatever you like and select the [Pull Zone](https://www.keycdn.com/support/create-a-pull-zone/) option. As for the origin URL, your site will be running on [GitLab Pages](https://docs.gitlab.com/ee/user/project/pages/getting_started_part_one.html) with a URL of `https://youruser.gitlab.io/reponame/`. Use this as the Origin URL.
   28 
   29 ![Screenshot of KeyCDN's pull zone creation page](/images/hosting-and-deployment/hosting-on-keycdn/keycdn-pull-zone.png)
   30 
   31 While the origin location doesn’t exist yet, you will need to use your new Zone URL address (or [Zone Alias](https://www.keycdn.com/support/create-a-zone-alias/)) in the `.gitlab-ci.yml` file that will be uploaded to your GitLab project.
   32 
   33 Ensure that you use your Zone URL or Zone alias as the `BASEURL` variable in the example below. This will be the user-visible website address.
   34 
   35 ## Configure Your .gitlab-ci.yml File
   36 
   37 Your `.gitlab-ci.yml` file should look similar to the example below. Be sure to modify any variables that are specific to your setup.
   38 
   39 ```
   40 image: alpine:latest
   41 
   42 variables:
   43     BASEURL: "https://cipull-7bb7.kxcdn.com/"
   44     HUGO_VERSION: "0.26"
   45     HUGO_CHECKSUM: "67e4ba5ec2a02c8164b6846e30a17cc765b0165a5b183d5e480149baf54e1a50"
   46     KEYCDN_ZONE_ID: "75544"
   47 
   48 before_script:
   49     - apk update
   50     - apk add curl
   51 
   52 pages:
   53     stage: deploy
   54     script:
   55     - apk add git
   56     - git submodule update --init
   57     - curl -sSL https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz
   58     - echo "${HUGO_CHECKSUM}  /tmp/hugo.tar.gz" | sha256sum -c
   59     - tar xf /tmp/hugo.tar.gz hugo -C /tmp/ && cp /tmp/hugo /usr/bin
   60     - hugo --baseURL ${BASEURL}
   61     - curl "https://api.keycdn.com/zones/purge/${KEYCDN_ZONE_ID}.json" -u "${KEYCDN_API_KEY}:"
   62     artifacts:
   63     paths:
   64     - public
   65     only:
   66     - master
   67 
   68 ```
   69 Using this integration method,  you will have to specify the Zone ID and your [KeyCDN API](https://www.keycdn.com/api) key as secret variables. To do this, navigate to the top-left menu bar in GitLab and select Projects. Then, select your project and click on the Settings page. Finally, select Pipelines from the sub-menu and scroll down to the Secret Variable section.
   70 
   71 The Secret Variable for your Zone ID should look similar to:
   72 
   73 ![Screenshot of setting the Zone ID secret variable](/images/hosting-and-deployment/hosting-on-keycdn/secret-zone-id.png)
   74 
   75 While the Secret Variable for your API Key will look similar to:
   76 
   77 ![Screenshot of setting the API Key secret variable](/images/hosting-and-deployment/hosting-on-keycdn/secret-api-key.png)
   78 
   79 The Zone ID and API key are used to purge your zone – it’s not strictly needed but otherwise, the CDN might deliver older versions of your assets for quite a while.
   80 
   81 ## Push Your Changes to GitLab
   82 
   83 Now it’s time to push the newly created repository to GitLab:
   84 
   85 ```
   86 git remote add origin git@gitlab.com:youruser/ci-example.git
   87 git push -u origin master
   88 ```
   89 
   90 You can watch the progress and CI job output in your Gitlab project under “Pipelines”.
   91 
   92 After verifying your CI job ran without issues, first check that your GitLab page shows up under `https://youruser.gitlab.io/reponame/` (it might look broken depending on your browser settings as all links point to your KeyCDN zone – don’t worry about that) and then by heading to whatever Zone alias / Zone URL you defined.
   93 
   94 To learn more about Hugo hosting options with KeyCDN, check out the complete [Hugo hosting with KeyCDN integration guide](https://www.keycdn.com/support/hugo-hosting/).