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
textbooks
account:sudo su textbooks
. - Change directory to the
textbooks
user’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
textbooks
account:exit
.
Set up Webhook on Server
- Switch to the
config
account:sudo su config
. - Change directory to the
config
user’s home directory:cd ~
. - Edit the
webhook/webhook.conf
file 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
config
account: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/bin
directory.command-working-directory
: this is the directory where the textbook repository is stored.deploy.sh
will use the default version of Hugodeploy-101.sh
will use Hugo version 0.101.0
pass-arguments-to-command
: this determines the folder where the content will be deployed. Thename
should match the URL desired (e.g.hugo-starter
will deploy athttps://textbooks.cs.ksu.edu/hugo-starter
)trigger-rule
: is used to determine if the webhook request is valid. Change thevalue
to 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 200
at 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
textbooks
account:sudo su textbooks
. - Edit the site’s homepage at
/var/www/textbooks.cs.ksu.edu/index.html
to include a link to the new site. - Save the file, and then log out of the
textbooks
account:exit
.
Save Configuration
- Switch to the
config
account:sudo su config
. - Change directory to the
config
user’s home directory:cd ~
. - Copy the updated
index.html
file to thenginx
folder:cp /var/www/textbooks.cs.ksu.edu/index.html ~/nginx/
. - Use
git
to commit and push the changes to the server configuration to GitLab.- The only files changed should be
webhook/webhook.conf
andnginx/index.html
.
- The only files changed should be
- Log out of the
config
account: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.