Wiki

DO NOT ADD THE WIKI PASSWORD TO THE WIKI

Along with other web resources, this site is served from the lab’s Digital ocean droplet. More specifically, as a static site which is rebuilt automatically from pushes to a git repository hosted on the droplet itself.

Contributing

Site content can be updated as simply as contributing to the repository (content will only be rebuilt from pushes to main). However, you first need to gain access. This is done using an ssh key pair. The following steps require ssh and git, both of which should already be on any development machine.

  1. navigate to your ~/.ssh directory (create it if it doesn’t exist)
  2. generate an ssh key pair using ssh-keygen
    • this will create two files using the name provided, I suggest using id_bci_droplet_git
  3. add the key to your user ssh configuration
    • open or create ~/.ssh/config
    • add the following block:
Host droplet-git
	HostName droplet.bci4kids.ca
	User git
	PubkeyAuthentication yes
	IdentityFile ~/.ssh/id_bci_droplet_git
  1. copy your public key to the droplet (working from your ~/.ssh directory)
    • ssh-copy-id -i id_bci_droplet_git droplet-git
    • when prompted, enter the password which was given to you (or poke Twig for it)

ssh-copy-id is a bash utility and might not be available in all environments. If you don’t have use of it, you will have to manually append the contents of your public key to /home/wiki/.ssh/authorized_keys on the droplet by logging in with the password

Once configured, you should be able to clone, fetch, pull from, and push to the repository without a password. To get started:

git clone ssh://droplet-git/~/wiki.git

Editing the Site

While the plain markdown may be easy enough to visualize, you won’t be able to see updates as you edit without setting up your local development environment. See the Hugo installation guides. The Hugo docs will also be your best resource for any questions on how the site works.


Post-Receive Hook

The script invoked by git after any push to the repo, this application uses a slightly more advanced version of the example given on the general deployment page.

#!/bin/bash

WORK_TREE=$HOME/wiki-worktree/
GIT_DIR=$HOME/wiki.git
DESTINATION=$HOME/wiki

while read oldrev newref ref
do
        BRANCH=$(git rev-parse --symbolic --abbrev-ref $ref)

        if [[ $BRANCH == "main" ]]; then
                echo "Main pushed, redeploying..."

                if [[ ! -d $WORK_TREE ]]; then
                        mkdir $WORK_TREE || exit 1
                fi
                echo "Populating build files..."
                git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f || exit 1

                cd $WORK_TREE
                echo "Rebuilding site..."
                hugo -d $DESTINATION --cleanDestinationDir || exit 1

                cd ..
                echo "Cleaning build files..."
                rm -rf $WORK_TREE || exit 1
        else
                echo "Pushed to ${BRANCH}"
        fi
done