Browse Source
new: [hugo] add ``hugo`` charm
new: [hugo] add ``hugo`` charm
Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>pull/29/head
Valentin Lab
2 years ago
6 changed files with 203 additions and 0 deletions
-
53hugo/actions/generate
-
21hugo/hooks/init
-
12hugo/hooks/pre_deploy
-
12hugo/hooks/publish_dir-relation-joined
-
65hugo/lib/common
-
40hugo/metadata.yml
@ -0,0 +1,53 @@ |
|||
#!/bin/bash |
|||
## compose: no-hooks |
|||
|
|||
if [ -z "$SERVICE_DATASTORE" ]; then |
|||
echo "This script is meant to be run through 'compose' to work properly." >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
. "$CHARM_PATH/lib/common" |
|||
|
|||
|
|||
version=0.1 |
|||
usage="$exname [-h|--help]" |
|||
help=" |
|||
USAGE: |
|||
|
|||
$usage |
|||
|
|||
DESCRIPTION: |
|||
|
|||
Generate website from current content. |
|||
|
|||
EXAMPLES: |
|||
|
|||
$exname |
|||
|
|||
" |
|||
|
|||
|
|||
dbname= |
|||
output= |
|||
while [ "$1" ]; do |
|||
case "$1" in |
|||
"--help"|"-h") |
|||
print_help >&2 |
|||
exit 0 |
|||
;; |
|||
--*|-*) |
|||
err "Unexpected optional argument '$1'" |
|||
print_usage >&2 |
|||
exit 1 |
|||
;; |
|||
*) |
|||
err "Unexpected positional argument '$1'" |
|||
print_usage >&2 |
|||
exit 1 |
|||
;; |
|||
esac |
|||
shift |
|||
done |
|||
|
|||
|
|||
hugo:generate "$HOST_HUGO_SOURCE" "$HOST_HUGO_OUTPUT" |
@ -0,0 +1,21 @@ |
|||
#!/bin/bash |
|||
|
|||
## Init is run on host |
|||
## For now it is run every time the script is launched, but |
|||
## it should be launched only once after build. |
|||
|
|||
## Accessible variables are: |
|||
## - SERVICE_NAME Name of current service |
|||
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any |
|||
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service |
|||
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service |
|||
|
|||
|
|||
. lib/common |
|||
|
|||
set -e |
|||
|
|||
if ! [ -d "$HOST_HUGO_SOURCE" ]; then |
|||
hugo:init-dir || exit 1 |
|||
fi |
|||
|
@ -0,0 +1,12 @@ |
|||
#!/bin/bash |
|||
## Should be executable N time in a row with same result. |
|||
|
|||
set -e |
|||
|
|||
. lib/common |
|||
|
|||
|
|||
if ! [ -d "$HOST_HUGO_OUTPUT" ]; then |
|||
hugo:generate "$HOST_HUGO_SOURCE" "$HOST_HUGO_OUTPUT" || exit 1 |
|||
fi |
|||
|
@ -0,0 +1,12 @@ |
|||
#!/bin/bash |
|||
|
|||
. lib/common |
|||
|
|||
set -e |
|||
|
|||
url=$(relation-get url) || exit 1 |
|||
|
|||
mkdir -p "${HOST_HUGO_CONFIG}" |
|||
cat <<EOF > "${HOST_HUGO_CONFIG}"/01-baseurl.yaml |
|||
baseURL: $url |
|||
EOF |
@ -0,0 +1,65 @@ |
|||
# -*- mode: shell-script -*- |
|||
|
|||
HUGO_CONFIG="/etc/hugo" |
|||
HUGO_BASE="/opt/apps/hugo" |
|||
HUGO_SOURCE="$HUGO_BASE/src" |
|||
HUGO_OUTPUT="$HUGO_BASE/output" |
|||
HUGO_THEME="$HUGO_BASE/theme" |
|||
|
|||
|
|||
HOST_HUGO_SOURCE="$SERVICE_DATASTORE$HUGO_BASE/src" |
|||
HOST_HUGO_OUTPUT="$SERVICE_DATASTORE$HUGO_BASE/output" |
|||
HOST_HUGO_THEME="$SERVICE_DATASTORE$HUGO_BASE/theme" |
|||
HOST_HUGO_CONFIG="$SERVICE_CONFIGSTORE$HUGO_CONFIG" |
|||
|
|||
HUGO_BUILDER_DEFAULT_IMAGE="docker.0k.io/hugo:0.88.1" |
|||
|
|||
|
|||
hugo:init-dir() { |
|||
mkdir -p "$HOST_HUGO_SOURCE" || return 1 |
|||
cd "$HOST_HUGO_SOURCE" && |
|||
git config --global user.email "compose@mail.com" && |
|||
git config --global user.name "compose" && |
|||
docker run --rm -v "$HOST_HUGO_SOURCE":"$HUGO_SOURCE" \ |
|||
-w "$HUGO_SOURCE" "$HUGO_BUILDER_DEFAULT_IMAGE" \ |
|||
new site -f yaml . && |
|||
docker run --rm -v "$HOST_HUGO_SOURCE":"$HUGO_SOURCE" \ |
|||
-w "$HUGO_SOURCE" "$HUGO_BUILDER_DEFAULT_IMAGE" \ |
|||
new posts/my-first-post.md && |
|||
sed -ri '/^baseURL:/d' config.yaml && |
|||
git init && |
|||
git add -A . && |
|||
git commit -m "First import" |
|||
} |
|||
|
|||
|
|||
hugo:generate() { |
|||
local src="$1" dst="$2" configs c |
|||
|
|||
theme_url=$(options-get theme-url 2>/dev/null) || true |
|||
theme_url=${theme_url:-https://github.com/theNewDynamic/gohugo-theme-ananke.git} |
|||
|
|||
if ! [ -d "$HOST_HUGO_THEME/default" ]; then |
|||
mkdir -p "$HOST_HUGO_THEME" |
|||
git clone "${theme_url}" "$HOST_HUGO_THEME/default" || { |
|||
err "Could not clone theme '$HOST_HUGO_THEME'." |
|||
return 1 |
|||
} |
|||
fi |
|||
echo "theme: default" > "$HOST_HUGO_CONFIG/80-theme.yaml" |
|||
config_files=("$HOST_HUGO_CONFIG/"*.yaml) |
|||
configs="" |
|||
for c in "${config_files[@]}"; do |
|||
configs+="config${c#$SERVICE_CONFIGSTORE$HUGO_CONFIG}," |
|||
done |
|||
mkdir -p "$dst" || return 1 |
|||
docker run --rm -v "$src":"$HUGO_SOURCE" \ |
|||
-v "$dst":"$HUGO_OUTPUT" \ |
|||
-v "$HOST_HUGO_CONFIG":"$HUGO_CONFIG" \ |
|||
-v "$HOST_HUGO_THEME":"$HUGO_SOURCE/themes" \ |
|||
-v "$HOST_HUGO_CONFIG":"$HUGO_SOURCE/config" \ |
|||
-w "$HUGO_SOURCE" "$HUGO_BUILDER_DEFAULT_IMAGE" \ |
|||
-D --config "${configs}config.yaml" \ |
|||
-d "${dst#$SERVICE_DATASTORE}" && |
|||
find "$HOST_HUGO_SOURCE" -depth -type d -empty -delete |
|||
} |
@ -0,0 +1,40 @@ |
|||
description: Hugo |
|||
subordinate: true |
|||
requires: |
|||
web-publishing-directory: |
|||
interface: publish-dir |
|||
scope: container |
|||
data-resources: |
|||
- /opt/apps/hugo/output |
|||
|
|||
default-options: |
|||
# config: |
|||
# language-code: "en-us" |
|||
# title: "My Hugo Site" |
|||
# theme: "ananke" |
|||
|
|||
uses: |
|||
publish-dir: |
|||
#constraint: required | recommended | optional |
|||
#auto: pair | summon | none ## default: pair |
|||
scope: container |
|||
constraint: required |
|||
auto: summon |
|||
solves: |
|||
container: "main running server" |
|||
default-options: |
|||
location: !var-expand "$DATASTORE/$BASE_SERVICE_NAME/opt/apps/hugo/output" |
|||
backup: |
|||
constraint: recommended |
|||
auto: pair |
|||
solves: |
|||
backup: "Automatic regular backup" |
|||
default-options: |
|||
## First pattern matching wins, no pattern matching includes. |
|||
## include-patterns are checked first, then exclude-patterns |
|||
## Patterns rules: |
|||
## - ending / for directory |
|||
## - '*' authorized |
|||
## - must start with a '/', will start from $SERVICE_DATASTORE |
|||
exclude-patterns: |
|||
- "/opt/apps/hugo/output/" |
Write
Preview
Loading…
Cancel
Save
Reference in new issue