Browse Source

updated README, bumped hugo ver in dockerfiles, added option for configmaps - more on this later...

master
fillkalpa 5 months ago
parent
commit
401d4e01bd

+ 69
- 10
README.md View File

@@ -39,7 +39,7 @@ Continue reading for an overview of the deployment and basic usage.

## Overview of deployment

This is a Multi-tier deployment for after dark in order to run on k3s or other kubernetes cluster in a microservices way. Currently is meant to run on a single node cluster but you can still test a few things (see below) on a multinode cluster. Your site is being built by hugo and served by a separate nginx web server which is exposed as a service inside your cluster. Combined with a traefik ingress host rule it can be faced against the web abstractingly from its backend. The deployment is consisted of the following manifests:
This is a Multi-tier deployment for after dark in order to run on k3s or other kubernetes cluster in a microservices way. Currently is meant to run on a single node cluster but you can still test a few things (see below) on a multinode cluster. Your site is being built by hugo and served by a separate nginx web server which is exposed as a service inside your cluster. Combined with a traefik ingress host rule it can be faced against the web abstracting its backend. The deployment is consisted of the following manifests:

* ``after-dark-k3s-hugo.yaml`` deploys a pod using two containers. First, an ephemeral initialization tasked with downloading After Dark from [source repo](https://git.habd.as/comfusion/after-dark) and, finally, the actual hugo container which kicks in and installs the site. When done it runs [`hugo server`](https://gohugo.io/commands/hugo_server/) in _watch mode_ so [Hugo](https://gohugo.io/) rebuilds After Dark site as files change.
* ``after-dark-nginx.yaml`` deploys an [nginx](https://www.nginx.com/) web server that serves the content of the rendered site. As file changes occur Hugo will rebuild the After Dark site and nginx will pick up the changes.
@@ -49,18 +49,77 @@ This is a Multi-tier deployment for after dark in order to run on k3s or other k

### Operating your k3s After Dark site

* First make sure pods have status ``running`` with ``$ kubectl get po``
* Now retrieve your pod name and store it in a variable for your convenience ``$ AD_POD=$(kubectl get pods -l app=after-dark-hugo -o jsonpath='{.items[0].metadata.name}')``
* First make sure your pods have status ``running`` issuing command

```sh
kubectl get po
```

* Now retrieve your pod name and store it in a variable for your convenience

```sh
AD_POD=$(kubectl get pods -l app=after-dark-hugo -o jsonpath='{.items[0].metadata.name}')
```

* Create a new post
``$ kubectl exec $AD_POD -- hugo new post/new-post.md``

```sh
kubectl exec $AD_POD -- hugo new post/new-post.md
```

* Apply custom styling
``$ kubectl cp custom.css $AD_POD:/after-dark/flying-toasters/assets/css/custom.css``

```sh
kubectl exec $AD_POD -- mkdir assets
kubectl exec $AD_POD -- mkdir assets/css
kubectl cp custom.css $AD_POD:/after-dark/flying-toasters/assets/css/
```

* Build your draft posts
``$ kubectl exec $AD_POD -- hugo -D -d /output``
* Full rebuilt your site e.g after new styles appied ``$ kubectl exec $AD_POD -- hugo -d /output`` Note this will also revert drafts.
* Edit your posts ``$ kubectl exec -it $AD_POD -- vi content/post/my-post.md`` or write your post locallt then push it to your pod. ``$ kubectl cp hello-world.md $AD_POD:content/post``. Make sure you've got your [front matter](https://gohugo.io/content-management/front-matter/) right.
* Backup your posts. Create a backup folder locally on your host then ``$ kubectl cp $AD_POD:content/post backup/``
* Check the stream of logs for troubleshooting ``$ kubectl logs -f $AD_POD``

```sh
kubectl exec $AD_POD -- hugo -D -d /output
```

* Full rebuilt your site e.g after new styles appied

```sh
$ kubectl exec $AD_POD -- hugo -d /output
```

> Note: this will also revert drafts. Also in case you recreate your hugo pod this will clear output from previous builds.

* Edit your posts

```sh
kubectl exec -it $AD_POD -- vi content/post/my-post.md
```

or write your post locally then push it to your pod.
```sh
kubectl cp hello-world.md $AD_POD:content/post
```

Make sure you've got your [front matter](https://gohugo.io/content-management/front-matter/) right.

* Edit Hugo's config.toml

```sh
kubectl exec -it $AD_POD -- vi config.toml
```

* Backup your posts. Create a backup folder locally on your host then

```sh
kubectl cp $AD_POD:content/post backup/
```

* Check the stream of logs for troubleshooting

```sh
kubectl logs -f $AD_POD
```

### Browsing to your site


+ 10
- 2
after-dark-k3s-hugo.yaml View File

@@ -17,18 +17,22 @@ spec:
tier: backend
spec:
containers:
- image: tkalpakid/after-dark-themed-hugo-64-v2
- image: tkalpakid/after-dark-themed-hugo-64-v2 #use this image for hugo configmap tkalpakid/after-dark-hugo-64-conf
name: after-dark-hugo-container
ports:
- containerPort: 1313
env:
- name: HUGO_WATCH # changed to real time build
- name: HUGO_WATCH # real time build
value: "true"
volumeMounts:
- name: rendered-site
mountPath: /output
- name: repo
mountPath: /after-dark
# uncomment below if you want to use configmap for hugo config
# - name: hugo-config
# mountPath: /config.toml
# subPath: config.toml
initContainers:
- name: init-repo
image: alpine/git
@@ -47,3 +51,7 @@ spec:
hostPath:
path: /rendered-site
type: DirectoryOrCreate
# uncomment below if you want to use configmap for hugo config
# - name: hugo-config
# configMap:
# name: config-toml

+ 42
- 0
configmaps/config-toml.yaml View File

@@ -0,0 +1,42 @@
apiVersion: v1
data:
config.toml: |-
baseurl = "https://domain.example" # Controls base URL sitewide
languageCode = "en-US" # Controls site language
title = "Plain Dark" # Homepage title and page title suffix
paginate = 11 # Number of posts to show before paginating

# Controls default theme and theme components
theme = [
"fractal-forest",
"after-dark"
]

disableLiveReload = false # Optional, set true to disable live reload
enableRobotsTXT = true # Suggested, enable robots.txt file

pygmentsCodefences = true # Suggested, highlight fenced code blocks
pygmentsUseClasses = true # Required for custom syntax highlighting

sectionPagesMenu = "main" # Enable menu system for lazy bloggers
footnoteReturnLinkContents = "↩" # Provides a nicer footnote return link

[params]
description = "" # Suggested, controls default description meta
author = "" # Optional, controls author name display on posts
hide_author = false # Optional, set true to hide author name on posts
has_cookies = false # Optional, set true to disable cookie disclaimer
disable_csp = false # Optional, set true to disable content security policy
images = [
"https://source.unsplash.com/collection/983219/2000x1322"
] # Suggested, controls default Open Graph images

[params.layout.menu.main]
hidden = true # Optional, set false or remove to show section menu

[params.modules.fractal_forest]
enabled = true # Optional, set false to disable module
decoders = ["bpgdec8a"] # Optional, 8-bit javascript decoder with animation
kind: ConfigMap
metadata:
name: config-toml

+ 34
- 0
dockerfiles/hugo-config/Dockerfile View File

@@ -0,0 +1,34 @@
# Use Alpine Linux as our base image so that we minimize the overall size our final container, and minimize the surface area of packages that could be out of date.
FROM alpine:latest

LABEL description="Docker container for building static sites with the Hugo static site generator."

# config
ENV HUGO_VERSION=0.55.5
#ENV HUGO_TYPE=
ENV HUGO_TYPE=_extended

COPY ./run.sh /run.sh
ENV HUGO_ID=hugo${HUGO_TYPE}_${HUGO_VERSION}
ADD https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_ID}_Linux-64bit.tar.gz /tmp
RUN tar -xf /tmp/${HUGO_ID}_Linux-64bit.tar.gz -C /tmp \
&& mkdir -p /usr/local/sbin \
&& mv /tmp/hugo /usr/local/sbin/hugo \
&& rm -rf /tmp/${HUGO_ID}_linux_amd64 \
&& rm -rf /tmp/${HUGO_ID}_Linux-64bit.tar.gz \
&& rm -rf /tmp/LICENSE.md \
&& rm -rf /tmp/README.md

RUN apk add --update git asciidoctor libc6-compat libstdc++ \
&& apk upgrade \
&& apk add --no-cache ca-certificates \
&& chmod 0777 /run.sh

# VOLUME /src
#VOLUME /after-dark/flying-toasters
VOLUME /output

WORKDIR /after-dark/flying-toasters
CMD ["/run.sh"]

#EXPOSE 1313

+ 31
- 0
dockerfiles/hugo-config/run.sh View File

@@ -0,0 +1,31 @@
#!/bin/sh

WATCH="${HUGO_WATCH:=false}"
SLEEP="${HUGO_REFRESH_TIME:=-1}"
HUGO_DESTINATION="${HUGO_DESTINATION:=/output}"
echo "HUGO_WATCH:" $WATCH
echo "HUGO_REFRESH_TIME:" $HUGO_REFRESH_TIME
echo "HUGO_THEME:" $HUGO_THEME
echo "HUGO_BASEURL" $HUGO_BASEURL
echo "ARGS" $@

HUGO=/usr/local/sbin/hugo
echo "Hugo path: $HUGO"
/after-dark/bin/install .
while [ true ]
do
if [[ $HUGO_WATCH != 'false' ]]; then
echo "Watching..."
$HUGO server --watch=true --source="/after-dark/flying-toasters" --config="/config.toml" --theme="$HUGO_THEME" --destination="$HUGO_DESTINATION" --baseURL="$HUGO_BASEURL" --bind="0.0.0.0" "$@" || exit 1
else
echo "Building one time..."
$HUGO --source="/after-dark/flying-toasters" --theme="$HUGO_THEME" --config="/config.toml" --destination="$HUGO_DESTINATION" --baseURL="$HUGO_BASEURL" "$@" || exit 1
fi

if [[ $HUGO_REFRESH_TIME == -1 ]]; then
exit 0
fi
echo "Sleeping for $HUGO_REFRESH_TIME seconds..."
sleep $SLEEP
done


+ 1
- 1
dockerfiles/hugo/Dockerfile View File

@@ -4,7 +4,7 @@ FROM alpine:latest
LABEL description="Docker container for building static sites with the Hugo static site generator."

# config
ENV HUGO_VERSION=0.53
ENV HUGO_VERSION=0.55.5
#ENV HUGO_TYPE=
ENV HUGO_TYPE=_extended


+ 0
- 5
dockerfiles/hugo/renovate.json View File

@@ -1,5 +0,0 @@
{
"extends": [
"config:base"
]
}

Loading…
Cancel
Save