From 4b596999344b959e7ad06ce762dd7d4b3a2f1f68 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Fri, 12 Apr 2024 13:10:15 +0100 Subject: [PATCH] Simplify the deploy scripts I'll be moving to deployment from my homelab soon (I hope), so this should simplify things. --- .env | 3 --- .github/workflows/publish.yml | 33 ++++++++++++++++----------------- .gitignore | 1 + Dockerfile | 25 +++++++++++++++++++++++++ Taskfile.yml | 16 +++++++++++----- 5 files changed, 53 insertions(+), 25 deletions(-) delete mode 100644 .env create mode 100644 Dockerfile diff --git a/.env b/.env deleted file mode 100644 index f6db1fc2..00000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -HUGO_LAST_UPDATE_TIME=$(git log -1 --format=%cI) -HUGO_LAST_UPDATE_HASH=$(git log -1 --format=%h) -HUGO_INDIEKIT_URL=https://indiekit.byjp.me${DOMAIN_SUFFIX} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3ac40b05..0bb7f629 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -26,12 +26,24 @@ jobs: build: runs-on: ubuntu-latest env: - HUGO_VERSION: 0.123.8 + HUGO_VERSION: 0.124.1 + PAGEFIND_VERSION: 1.1.0 + TASK_VERSION: 3.36.0 steps: - name: Install Hugo CLI run: | - wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ + wget -q -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Install Pagefind CLI + run: | + wget -q -O ${{ runner.temp }}/pagefind.tar.gz https://github.com/CloudCannon/pagefind/releases/download/v${PAGEFIND_VERSION}/pagefind-v${PAGEFIND_VERSION}-x86_64-unknown-linux-musl.tar.gz \ + && tar -xpf ${{ runner.temp }}/pagefind.tar.gz pagefind \ + && mv pagefind /usr/local/bin/pagefind + - name: Install Task CLI + run: | + wget -q -O ${{ runner.temp }}/task.tar.gz https://github.com/go-task/task/releases/download/v${TASK_VERSION}/task_linux_amd64.tar.gz \ + && tar -xpf ${{ runner.temp }}/task.tar.gz task \ + && mv task /usr/local/bin/task - name: Checkout uses: actions/checkout@v3 with: @@ -46,21 +58,8 @@ jobs: with: path: /tmp/hugo key: ${{ env.cache-name }} - - name: Build with Hugo - env: - # For maximum backward compatibility with Hugo modules - HUGO_ENVIRONMENT: production - HUGO_ENV: production - run: | - set -o allexport; source .env; set +o allexport - hugo \ - --cacheDir /tmp/hugo/cache \ - --minify \ - --baseURL "https://www.byjp.me" - - name: Build search index - run: | - # Build the search index - npm_config_yes=true npx pagefind@latest + - name: Build site + run: task build - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: diff --git a/.gitignore b/.gitignore index d25c47a8..8836c411 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /resources/_gen/ /.hugo_build.lock /.lycheecache +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a5741f03 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.22-alpine + +ARG TARGETPLATFORM + +ENV PAGEFIND_VERSION=1.1.0 +ENV TASK_VERSION=3.36.0 + +RUN apk update && \ + apk add ca-certificates wget git hugo && \ + update-ca-certificates && \ + rm -rf /var/cache/apk/* + +RUN wget -q -O pagefind.tar.gz "https://github.com/CloudCannon/pagefind/releases/download/v${PAGEFIND_VERSION}/pagefind-v${PAGEFIND_VERSION}-$(if [ "$TARGETPLATFORM" = "linux/arm64" ]; then echo "aarch64"; else echo "x86_64"; fi)-unknown-linux-musl.tar.gz" \ + && tar -xpf pagefind.tar.gz pagefind \ + && mv pagefind /usr/local/bin/pagefind \ + && rm pagefind.tar.gz + +RUN wget -q -O task.tar.gz "https://github.com/go-task/task/releases/download/v${TASK_VERSION}/task_${TARGETPLATFORM//\//_}.tar.gz" \ + && tar -xpf task.tar.gz task \ + && mv task /usr/local/bin/task \ + && rm task.tar.gz + +WORKDIR /build + +CMD ["task", "build"] diff --git a/Taskfile.yml b/Taskfile.yml index 9843095a..be16a480 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -7,22 +7,28 @@ version: '3' env: DOMAIN: https://www.byjp.me + HUGO_INDIEKIT_URL: https://indiekit.byjp.me{{.DOMAIN_SUFFIX}} + HUGO_LAST_UPDATE_TIME: + sh: git log -1 --format=%cI + HUGO_LAST_UPDATE_HASH: + sh: git log -1 --format=%h tasks: check-links: cmds: - lychee --cache --require-https --config lychee.toml . + dev: env: DOMAIN_SUFFIX: .test cmds: - - | - set -o allexport; source .env; set +o allexport - hugo server --minify --printUnusedTemplates -D --baseURL "${DOMAIN}${DOMAIN_SUFFIX}" --appendPort=false + - hugo server --minify --printUnusedTemplates -D --baseURL "${DOMAIN}${DOMAIN_SUFFIX}" --appendPort=false + build: - cmds: + cmds: - hugo --cacheDir /tmp/hugo/cache --gc --minify --baseURL "${DOMAIN}" - - npm_config_yes=true npx pagefind@latest + - pagefind + import: dir: tools/ cmds: