From 47c6d1e61daf61fe41818977cbae90bdeee6cd64 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 3 Mar 2020 18:43:48 -0600 Subject: [PATCH] ci: Begin Jenkins pipeline This is a very simple pipeline that consists of 3 steps: 1. Download the Hugo binary from Github (if necessary) 2. Run `hugo` 3. Publish the generated site with `rsync` --- .gitignore | 4 ++++ ci/Jenkinsfile | 33 +++++++++++++++++++++++++++++++++ ci/build.sh | 5 +++++ ci/prepare.sh | 30 ++++++++++++++++++++++++++++++ ci/publish.sh | 5 +++++ 5 files changed, 77 insertions(+) create mode 100644 ci/Jenkinsfile create mode 100644 ci/build.sh create mode 100644 ci/prepare.sh create mode 100644 ci/publish.sh diff --git a/.gitignore b/.gitignore index 9ae0f08..b6c9880 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ +/hugo +/hugo-* +/hugo_*.tar.gz +/hugo_*_checksums.txt /public/ /resources/_gen/ diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile new file mode 100644 index 0000000..880de0d --- /dev/null +++ b/ci/Jenkinsfile @@ -0,0 +1,33 @@ +pipeline { + agent any + + options { + disableConcurrentBuilds() + } + + triggers { + pollSCM '' + } + + stages { + stage('Prepare') { + steps { + sh '. ci/prepare.sh' + } + } + + stage('Build') { + steps { + sh '. ci/build.sh' + } + } + + stage('Publish') { + steps { + sshagent(['jenkins-web']) { + sh '. ci/publish.sh' + } + } + } + } +} diff --git a/ci/build.sh b/ci/build.sh new file mode 100644 index 0000000..68a9ddf --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,5 @@ +# Remove unnecessary Cloudflare CSS +# https://github.com/rhazdon/hugo-theme-hello-friend-ng/issues/41 +sed -i -e '/cloudflare/,+2d' themes/hello-friend-ng/layouts/partials/head.html + +./hugo diff --git a/ci/prepare.sh b/ci/prepare.sh new file mode 100644 index 0000000..4171170 --- /dev/null +++ b/ci/prepare.sh @@ -0,0 +1,30 @@ +HUGO_VERSION=0.66.0 +case $(uname -m) in +i[23456]86) + HUGO_ARCH=32bit + ;; +x86_64) + HUGO_ARCH=64bit + ;; +aarch64) + HUGO_ARCH=ARM64 + ;; +armv7*) + HUGO_ARCH=ARM + ;; +esac + +HUGO_TAR=hugo_${HUGO_VERSION}_Linux-${HUGO_ARCH}.tar.gz +HUGO_BASE_URL=https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION} +HUGO_TAR_URL=${HUGO_BASE_URL}/${HUGO_TAR} +HUGO_CHECKSUM_URL=${HUGO_BASE_URL}/hugo_${HUGO_VERSION}_checksums.txt + +if [ ! -f hugo-${HUGO_VERSION} ]; then + rm -f ${HUGO_TAR} hugo_${HUGO_VERSION}_checksums.txt + curl -fJL -O "${HUGO_CHECKSUM_URL}" -O "${HUGO_TAR_URL}" + grep ${HUGO_TAR} hugo_${HUGO_VERSION}_checksums.txt | sha256sum -c + tar -xzOf ${HUGO_TAR} hugo > hugo-${HUGO_VERSION} + chmod +x hugo-${HUGO_VERSION} +fi + +ln -sf hugo-${HUGO_VERSION} hugo diff --git a/ci/publish.sh b/ci/publish.sh new file mode 100644 index 0000000..f813f9b --- /dev/null +++ b/ci/publish.sh @@ -0,0 +1,5 @@ +: ${PUBLISH_USER:=webapp.chmod777} +: ${PUBLISH_HOST:=web0.pyrocufflink.blue} +: ${PUBLISH_PATH:=htdocs} + +rsync -rti public/ ${PUBLISH_USER}@${PUBLISH_HOST}:${PUBLISH_PATH}