post image May 19, 2023 | 1 min Read

Simple hugo Gitlab pipeline

Hugo deployment from a local Gitlab instance

variables:
  BASE_URL: "https://github.com/gohugoio/hugo/releases/download"
  SSH_OPTIONS: "-o HostKeyAlgorithms=ssh-rsa -o PreferredAuthentications=password -o StrictHostKeyChecking=no"
  VERSION: "0.112.1"
  ARTIFACT: "public-${CI_COMMIT_SHORT_SHA}.tgz"

stages:
  - build
  - deploy

hugo:build:
  rules:
   - if: '$CI_COMMIT_BRANCH == "main"'
     changes:
     - hugo/**/* # folder including all files and subfolders
  stage: build
  script:
   - apt update && apt install curl -y
   - curl -L ${BASE_URL}/v${VERSION}/hugo_extended_${VERSION}_linux-arm64.tar.gz  | tar -xvz -C /usr/local/bin/ && hugo version
   - cd hugo && hugo --minify
   - rm -rf public/tags && ls -al && pwd && tar -cvzf ../${ARTIFACT} public && du -sh ../${ARTIFACT}
  artifacts:
    paths:
    - ${ARTIFACT}
    expire_in: 1 week

hugo:deploy:
  rules:
   - if: '$CI_COMMIT_BRANCH == "main"'
  stage: deploy
  dependencies: ['hugo:build']
  script:
  - apt update && apt install sshpass -y && ls -al && pwd
  - tar -xvzf ${ARTIFACT} && ls -al && pwd
  - sshpass -v -e scp -r -C ${SSH_OPTIONS} public/ devopsinuse.com@devopsinuse.com:/
author image

Jan Toth

I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …

comments powered by Disqus