Deploying Textbook
This page gives the basic instructions for deploying a textbook to the server. It is mainly meant as a reference for the server’s administrators, but it is helpful for everyone to understand the process.
Clone Repository on Server
- Log in to the server via SSH and switch to the
textbooksaccount:sudo su textbooks. - Change directory to the
textbooksuser’s home directory:cd ~. - Clone the repository into this folder:
git clone <url> <directory>. - Change directory to the textbook’s directory:
cd <directory>. - Initialize submodules:
git submodule init. - Recursively pull submodules:
git pull --recurse. - Log out of the
textbooksaccount:exit.
Set up Webhook on Server
- Switch to the
configaccount:sudo su config. - Change directory to the
configuser’s home directory:cd ~. - Edit the
webhook/webhook.conffile to add a new webhook.- In general, just copy an existing webhook definition and edit to match the new site. Be Careful! The configuration file is JSON and is very picky about proper JSON syntax.
- Webhook Documentation.
- Save the file.
- Log out of the
configaccount:exit. - Restart webhook service:
sudo systemctl restart webhook.
Example Webhook:
{
"id": "hugo-starter",
"execute-command": "/home/config/bin/deploy-101.sh",
"command-working-directory": "/home/textbooks/hugo-starter/",
"response-message": "Executing checkout script",
"pass-arguments-to-command":
[
{
"source": "string",
"name": "hugo-starter"
}
],
"trigger-rule":
{
"match":
{
"type": "value",
"value": "secret",
"parameter":
{
"source": "header",
"name": "X-Gitlab-Token"
}
}
}
}Items to configure:
id: this is the identifier for the webhook used in the URLexecute-command: see the scripts in the/home/config/bindirectory.command-working-directory: this is the directory where the textbook repository is stored.deploy.shwill use the default version of Hugodeploy-101.shwill use Hugo version 0.101.0
pass-arguments-to-command: this determines the folder where the content will be deployed. Thenameshould match the URL desired (e.g.hugo-starterwill deploy athttps://textbooks.cs.ksu.edu/hugo-starter)trigger-rule: is used to determine if the webhook request is valid. Change thevalueto match the key given when setting up the webhook in GitLab.
Set up Webhook on GitLab
- Open the repository on GitLab and navigate to the Settings -> Webhooks menu.
- Add a hook using the following settings:
- URL:
http://pacer.cs.ksu.edu:9000/hooks/<hook_id> - Secret Token:
<secret> - Trigger: Push events
- You can specify a specific branch; I typically leave this blank.
- Uncheck SSL Verification - we currently don’t have an SSL certificate on the webhook server.
- Click Add Webhook to save.
- Once saved, click the Test option and choose Push Event to test it. It should quickly return
HTTP 200at the top of the page if it is working.
Update Permissions
- After the first deployment, on the server, go to the web directory:
cd /var/www/textbooks.cs.ksu.edu - Update the permissions on the new directory:
sudo chown -R textbooks:www-data <directory>sudo chmod -R g+w <directory>
Update Homepage
- Log in to the server via SSH and switch to the
textbooksaccount:sudo su textbooks. - Edit the site’s homepage at
/var/www/textbooks.cs.ksu.edu/index.htmlto include a link to the new site. - Save the file, and then log out of the
textbooksaccount:exit.
Save Configuration
- Switch to the
configaccount:sudo su config. - Change directory to the
configuser’s home directory:cd ~. - Copy the updated
index.htmlfile to thenginxfolder:cp /var/www/textbooks.cs.ksu.edu/index.html ~/nginx/. - Use
gitto commit and push the changes to the server configuration to GitLab.- The only files changed should be
webhook/webhook.confandnginx/index.html.
- The only files changed should be
- Log out of the
configaccount:exit.
Notifications
Deployment notifications are sent to a Discord server. Contact one of the other textbook authors to get access to that Discord server. It is helpful if you want to see that your deployments are starting and completing correctly.
Debugging
Deployment logs are stored in the /home/textbooks/<name>.log file. This can be helpful for debugging.