Compare commits

...

81 Commits

Author SHA1 Message Date
Charles Reid 7b0073cc90 modify print() calls 6 years ago
Charles Reid 813c6d5540 fix path variable name typo 6 years ago
Charles Reid 5f4e1417bd fix typos/bugs in pages pull script 6 years ago
Charles Reid e661c3a89e bring pages pull and pages init into harmony 6 years ago
Charles Reid cf5a54134f pages init setup script now working! 6 years ago
Charles Reid 87e29c7ec8 get two init scripts (pages and subdomains) in sync 6 years ago
Charles Reid cf72be381e fix variables and typos in subdomains pull script 6 years ago
Charles Reid 05be4a3922 fix typos and use executioner in subdomains pull script 6 years ago
Charles Reid 1e43264923 check for existing clone path in subdomains init setup script 6 years ago
Charles Reid f682d0a85d update nginx-subdomains submodule 6 years ago
Charles Reid c4e76c7ca9 add executor and convert subdomains init setup to use executor 6 years ago
Charles Reid acc8ac8793 fix/finish pull scripts 6 years ago
Charles Reid d5c3f68406 include *_pull scripts for subdomains 6 years ago
Charles Reid 43368d07bb updating nginx-subdomains submodule 6 years ago
Charles Reid 7b06256767 Merge branch 'master' of github.com:charlesreid1-docker/pod-webhooks 6 years ago
Charles Reid c27af44804 add pull scripts for subdomains and pages 6 years ago
Charles Reid ef4a11f823 remove docker-compose.yml from version control 6 years ago
Charles Reid 6e7535fe05 new nginx subdomains module commits 6 years ago
Charles Reid d34dfb5a89 update gitignore 6 years ago
Charles Reid af9c6133ed update how output script templates are organized 6 years ago
Charles Reid f5e7045539 fix template var values and typos 6 years ago
Charles Reid 957fc63936 fix dot git directory name 6 years ago
Charles Reid 439ff53688 fix typos and template variable values 6 years ago
Charles Reid 74e16651f6 add scripts to apply templates and create files for testing 6 years ago
Charles Reid be1c3cf67d Update captain hook pull host script 6 years ago
Charles Reid 32ab437d39 no clone command for source directory (not gonna do it) 6 years ago
Charles Reid 85706f9e63 add clone of -src (master branch) to /www init setup 6 years ago
Charles Reid 8773b5f365 template-ify all scripts 6 years ago
Charles Reid 5a24540569 stormy captain hook container should wait for stormy nginx subdomains container 6 years ago
Charles Reid feff156691 update subdomains submodule (config file) 6 years ago
Charles Reid 8ab5ab5bc7 update subdomains submodule 6 years ago
Charles Reid c084237bb1 quote integers to prevent type error 6 years ago
Charles Reid 888c9a708c update gitignore 6 years ago
Charles Reid 63cd836d63 add quotes around numbers 6 years ago
Charles Reid fabf35fbd7 update readme 6 years ago
Charles Reid 0c647c4040 add pod-webhooks service template 6 years ago
Charles Reid a3d529a955 remove dockerpod-webhooks service 6 years ago
Charles Reid cf500132cf removing captn hook scripts, replaced with templates 6 years ago
Charles Reid 7ac9e6bcac fix name of pod-webhooks service 6 years ago
Charles Reid a5ec57689d fix typo in subdomains init setup script 6 years ago
Charles Reid c3b5db300f transform captain hook canary scripts to templates 6 years ago
Charles Reid 1d65e16f90 remove docker-compose and use template instead 6 years ago
Charles Reid a2a3b302ca update d-nginx-subdomains submodule/configuration file layout 6 years ago
Charles Reid 7b9cf6ce71 update captain hook submodule 6 years ago
Charles Reid ddb8a78cc7 fix mkdocs page titles 6 years ago
Charles Reid b4a82bf3d1 update d-nginx-subdomains to latest 6 years ago
Charles Reid 6207e0cae9 fix filenames 6 years ago
Charles Reid 8e303efbd6 update all docs - rename, and fix up 6 years ago
Charles Reid 3bf863d3c4 rename 6 years ago
Charles Reid 10b839aafa update docs of pod-webhooks 6 years ago
Charles Reid 97d6805567 update docs on captain hook 6 years ago
Charles Reid 12ca200284 change www to /www 6 years ago
Charles Reid ee3c242b71 expand on logging options in docker-compose 6 years ago
Charles Reid b64e79ec5f subdomains /www init setup uses git.charlesreid1.com and github.com repos 6 years ago
Charles Reid 4f6f848f4d add scripts to do initial setup of subdomains/pages dir structure 6 years ago
Charles Reid b4828fa3b5 Merge branch 'master' of https://git.charlesreid1.com/docker/pod-webhooks 6 years ago
Charles Reid abb106878d add json logging to pod-webhooks 6 years ago
Charles Reid a6a528aa73 update captain hook submodule pointer 6 years ago
Charles Reid ba40354bdf Merge branch 'master' of https://git.charlesreid1.com/docker/pod-webhooks 6 years ago
Charles Reid 309166757e add canary scripts & pull host scripts 6 years ago
Charles Reid 3b8ecc1495 add mor info about init pages setup 6 years ago
Charles Reid 01261d0555 add init pages setup script (untested) for pod-webhooks role 6 years ago
Charles Reid dfd4c126c3 add script to make dir structure pod expects 6 years ago
Charles Reid 354c30c5bc reorder docker-compose, no changes 7 years ago
Charles Reid 7fc0b506ef update captain hook and nginx subdomains module 7 years ago
Charles Reid 1bb5e20f5c note on 403 7 years ago
Charles Reid 4ed9203956 add startup script to launch pod webhooks 7 years ago
Charles Reid 2682b54f13 Update mkdocs.yml for mkdocs 1.0 7 years ago
Charles Reid d1ba594cff Update mkdocs-material for mkdocs 1.0 7 years ago
Charles Reid 1534435add fix link, and add custom css 7 years ago
Charles Reid 60432dd805 update links 7 years ago
Charles Reid 5b4f409e22 blue uniform 7 years ago
Charles Reid bab7cb0c94 bump captain hook submodule pointer 7 years ago
Charles Reid c61f0500ea mount git directories too, not just htdocs. 7 years ago
Charles Reid a3e05595b2 fix executabilification issue 7 years ago
Charles Reid 1e1e5e34c9 update captain hook submodule pointer 7 years ago
Charles Reid 9b793eabf8 bringing captain hook submodule pointer up to the latest 7 years ago
Charles Reid b4bb9cee95 update captain hook submodule to fix bugs 7 years ago
Charles Reid 769abb65a8 update captain hook submodule pointer 7 years ago
Charles Reid e1db6e9695 Merge branch 'docs-dir' of docker/pod-webhooks into master 7 years ago
Charles Reid 88d1f72637 Merge branch 'docs-dir' of docker/pod-webhooks into master 7 years ago
  1. 10
      .gitignore
  2. 22
      README.md
  3. 2
      b-captain-hook
  4. 2
      d-nginx-subdomains
  5. 32
      docker-compose.yml
  6. 42
      docker-compose.yml.j2
  7. 86
      docs/Services.md
  8. 26
      docs/adding.md
  9. 58
      docs/canary.md
  10. 11
      docs/css/custom.css
  11. 106
      docs/index.md
  12. 15
      docs/running.md
  13. 93
      docs/services.md
  14. 2
      mkdocs-material
  15. 17
      mkdocs.yml
  16. 24
      scripts/Readme.md
  17. 89
      scripts/apply_templates_captainhook.py
  18. 84
      scripts/apply_templates_pod.py
  19. 90
      scripts/apply_templates_subdomains.py
  20. 12
      scripts/captain-hook-canary.service.j2
  21. 47
      scripts/captain_hook_canary.sh.j2
  22. 110
      scripts/captain_hook_pull_host.py.j2
  23. 21
      scripts/executioner.py
  24. 125
      scripts/pages_init_setup.py.j2
  25. 129
      scripts/pages_pull.py.j2
  26. 14
      scripts/pod-webhooks.service.j2
  27. 89
      scripts/subdomains_init_setup.py.j2
  28. 95
      scripts/subdomains_pull.py.j2

10
.gitignore vendored

@ -1,2 +1,12 @@ @@ -1,2 +1,12 @@
#mkdocs
site/
docker-compose.yml
# ignore scripts generated from templates
scripts/pages_init_setup.py
scripts/subdomains_init_setup.py
scripts/captain-hook-canary.service
scripts/captain_hook_canary.sh
scripts/captain_hook_pull_host.py
scripts/pod-webhooks.service
scripts/output/

22
README.md

@ -7,16 +7,34 @@ This docker pod runs two services: @@ -7,16 +7,34 @@ This docker pod runs two services:
* Static content server for subdomain pages (nginx)
* [d-nginx-subdomains](https://git.charlesreid1.com/docker/d-nginx-subdomains)
These two services are in this repo as submodules.
These two services are in this repo as submodules.
## Links
See documentation page here: <https://pages.charlesreid1.com/pod-webhooks>
Or view it locally in this repository here: [docs/index.md](/docs/index.md)
Or visit [docs/index.md](/docs/index.md)
Source code on git.charlesreid1.com: <https://git.charlesreid1.com/docker/pod-webhooks>
Source code on github.com: <https://github.com/charlesreid1-docker/pod-webhooks>
## If you get a 403
If you visit the IP of the page running things and you get a 403,
it's probably because you haven't created the `/www/` directory
structure yet.
To do this, you need a folder for each subdomain at `/www/`, along
with subdirectories for `htdocs` and for the `.git` directory
(see `scripts/` directory for scripts to do this automatically):
```
/www/pages.charlesreid1.com/
/www/bots.charlesreid1.com/
/www/hooks.charlesreid1.com/
```

2
b-captain-hook

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit f084dce02c9a943a585e192d1e601196dfec5b14
Subproject commit 361f59c21a733a484f48e9bd60bce2d94dbf7b1b

2
d-nginx-subdomains

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit 3d82d7728b7e58e101138d8645a98dbb6cff266a
Subproject commit a87dcd5f3d997596c87deec03d396f0911b4b03f

32
docker-compose.yml

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
version: "3.1"
version: "3.3"
services:
stormy_nginx_subs:
@ -7,22 +7,36 @@ services: @@ -7,22 +7,36 @@ services:
command: /bin/bash -c "nginx -g 'daemon off;'"
volumes:
- "./d-nginx-subdomains/conf.d:/etc/nginx/conf.d"
- "/www/pages.charlesreid1.com/htdocs:/www/pages.charlesreid1.com/htdocs:ro"
- "/www/hooks.charlesreid1.com/htdocs:/www/hooks.charlesreid1.com/htdocs:ro"
- "/www/bots.charlesreid1.com/htdocs:/www/bots.charlesreid1.com/htdocs:ro"
- "/www/pages.charlesreid1.red/htdocs:/www/pages.charlesreid1.red/htdocs:ro"
- "/www/hooks.charlesreid1.red/htdocs:/www/hooks.charlesreid1.red/htdocs:ro"
- "/www/bots.charlesreid1.red/htdocs:/www/bots.charlesreid1.red/htdocs:ro"
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "10"
ports:
- "7777:7777"
- "7778:7778"
- "7779:7779"
stormy_captain_hook:
restart: always
build: b-captain-hook
ports:
- "5000:5000"
volumes:
- "/www/pages.charlesreid1.com/htdocs:/www/pages.charlesreid1.com/htdocs"
- "/www/hooks.charlesreid1.com/htdocs:/www/hooks.charlesreid1.com/htdocs"
- "/www/bots.charlesreid1.com/htdocs:/www/bots.charlesreid1.com/htdocs"
- "/www/pages.charlesreid1.red:/www/pages.charlesreid1.red"
- "/www/hooks.charlesreid1.red:/www/hooks.charlesreid1.red"
- "/www/bots.charlesreid1.red:/www/bots.charlesreid1.red"
- "/tmp/triggers:/tmp/triggers"
- "./b-captain-hook/config.json:/app/config.json"
- "./b-captain-hook/hooks:/app/hooks"
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "10"
ports:
- "5000:5000"
depends_on:
- stormy_nginx_subs

42
docker-compose.yml.j2

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
version: "3.3"
services:
stormy_nginx_subs:
restart: always
image: nginx
command: /bin/bash -c "nginx -g 'daemon off;'"
volumes:
- "./d-nginx-subdomains/conf.d:/etc/nginx/conf.d"
- "/www/pages.{{ server_name_default }}/htdocs:/www/pages.{{ server_name_default }}/htdocs:ro"
- "/www/hooks.{{ server_name_default }}/htdocs:/www/hooks.{{ server_name_default }}/htdocs:ro"
- "/www/bots.{{ server_name_default }}/htdocs:/www/bots.{{ server_name_default }}/htdocs:ro"
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "10"
ports:
- "7777:7777"
- "7778:7778"
- "7779:7779"
stormy_captain_hook:
restart: always
build: b-captain-hook
volumes:
- "/www/pages.{{ server_name_default }}:/www/pages.{{ server_name_default }}"
- "/www/hooks.{{ server_name_default }}:/www/hooks.{{ server_name_default }}"
- "/www/bots.{{ server_name_default }}:/www/bots.{{ server_name_default }}"
- "/tmp/triggers:/tmp/triggers"
- "./b-captain-hook/config.json:/app/config.json"
- "./b-captain-hook/hooks:/app/hooks"
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "10"
ports:
- "5000:5000"
depends_on:
- stormy_nginx_subs

86
docs/Services.md

@ -1,86 +0,0 @@ @@ -1,86 +0,0 @@
## Running Hooks-Subdomains Docker Pod as Startup Service
The webhooks-subdomains docker pod requires two startup
services - one keeps the docker pod running, the other
watches a folder shared between the host and container
for signals from the container, and uses that to trigger
updates to the subdomains web content.
Also see the `services/` folder of the
[dotfiles/debian repository](https://git.charlesreid1.com/dotfiles/debian),
repository for the systemd services.
### Service 1: Webhooks Docker Pod
This service keeps the webhooks docker pod service running
continuously. If the pod stops, this service will restart it.
(This service should not be running if you are troubleshooting
the docker pod.)
**`dockerpod-webhooks.service:`**
```
[Unit]
Description=webhooks and subdomains docker pod
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f /home/charles/codes/docker/pod-webhooks/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /home/charles/codes/docker/pod-webhooks/docker-compose.yml down
[Install]
WantedBy=default.target
```
**`captain-hook-canary.service:`**
```
[Unit]
Description=captain hook canary script
Requires=dockerpod-captainhook.service
After=dockerpod-captainhook.service
[Service]
Restart=always
ExecStart=/home/charles/blackbeard_scripts/captain_hook_canary.sh
ExecStop=/usr/bin/pgrep -f captain_hook_canary | /usr/bin/xargs /bin/kill
[Install]
WantedBy=default.target
```
Now install the service to `/etc/systemd/system/dockerpod-webhooks.servce`,
and/or `/etc/systemd/system/captain-hook-canary.servce`,
and activate it:
```
sudo systemctl enable dockerpod-webhooks.service
sudo systemctl enable captain-hook-canary.service
```
Now you can start/stop the service with:
```
sudo systemctl (start|stop) dockerpod-webhooks.service
sudo systemctl (start|stop) captain-hook-canary.service
```
As mentioned above, these services should be stopped before
doing a `docker-compose stop` or a `docker-compose up --build`
to keep the pod from respawning in the middle of the task.
Stop using:
```
sudo systemctl stop dockerpod-webhooks.service
sudo systemctl stop captain-hook-canary.service
```

26
docs/Adding.md → docs/adding.md

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
## Adding Hooks
## Adding New Hooks
To add a hook to Captain Hook:
@ -17,18 +17,28 @@ To add a hook to Captain Hook: @@ -17,18 +17,28 @@ To add a hook to Captain Hook:
Settings > Webhooks page, and add a Gitea webhook.
5. Enter info:
a. Payload URL is the Captain Hook server, which is `https://hooks.charlesreid1.com/webhook`.
b. Content type is application/json
c. Secret is my little secret
d. Pick what you'd like, I usually go with "just the push event"
b. Content type is `application/json`
c. Secret is (that's my little secret)
d. Pick what events you would like to trigger webhooks, usually "just the push event"
6. Save the webhook, then click on the webhook again to open it back up.
Scroll down to the bottom right and click "Test Delivery".
You should see a green success sign. If you see a red warning sign:
You should see a green success sign.
## Debugging Failed Hooks
If you see a red warning sign:
* Ensure the webhooks docker pod is actually running okay (`docker ps` on the host machine)
* Ensure port 5000 is open in the Captain Hook container, and on the host machine
* Ensure you can see port 5000 of the `pod-webhooks` host machine from the `pod-charlesreid1` host machine
* Ensure there is actually a hook in the `hooks/` directory of the Captain Hook repo
* ensure webhooks-subdomain pods are running
* ensure port 5000 open in captain hook container and on blackbeard and on aws
* ensure hook has been added to b-captain-hook repository's hooks folder
Captain Hook repo: <https://git.charlesreid1.com/bots/b-captain-hook>
Captain Hook repo (Github mirror): <https://github.com/charlesreid1-docker/b-captain-hook>

58
docs/Canary.md → docs/canary.md

@ -1,26 +1,33 @@ @@ -1,26 +1,33 @@
# Captain Hook's Canary
Captain Hook's Canary is a mechanism by which a docker pod
running a webhook server can send a signal to the host to
restart the docker pod.
First things first: Captain Hook is the webhook server that
is part of the webhooks docker pod. It receives webhooks
from Github and Gitea and uses them to trigger scrips.
Links to [documentation](https://pages.charlesreid1.com/b-captain-hook)
and [code](https://git.charlesreid1.com/bots/b-captain-hook)
for Captain Hook.
Captain Hook's Canary is a mechanism by which the Captain Hook
webhooks server (running in a docker container) can trigger an action
on the host machine (running the pod). In this case the action is to
update Captain Hook and restart the docker pod anytime a webhook is
received indicating the Captain Hook repo has changed.
This is done by bind-mounting a host directory at `/tmp/triggers/`
inside the docker container, and when a webhook is received
from git.charlesreid1.com that indicates there was a change
to Captain Hook, the docker pod creates a trigger file.
inside the Captain Hook docker container. When Captain Hook receives
a webhook from Github or Gitea that indicates the Captain Hook
repo (<https://git.charlesreid1.com/bots/b-captain-hook> or
<https://github.com/charlesreid1/captain-hook>), it creates a
trigger file.
The canary bash script, meanwhile, is a bash script that runs
forever and checks for a trigger file from the docker pod
every 10 seconds.
Meanwhile, on the host that is running the docker pod, a service
script is running continuously to check for that trigger file
every 10 seconds. If the trigger file is seen, it updates the
Captain Hook git repository on the host machine and then restarts
the docker pod.
The pull host Captain Hook script is a script that updates the
Captain Hook git repo on the host machine.
Sections below cover the following scripts, all run on the host:
On top of all of that, we also need a startup service that will
actually run the captain hook canary script, and keep it running,
and stop it when we ask it to stop.
Sections below cover:
* The canary bash script
* The docker host pull script
* The canary statup service
@ -56,15 +63,18 @@ and this script processes each trigger differently. @@ -56,15 +63,18 @@ and this script processes each trigger differently.
```bash
#!/bin/bash
TRIGGER="/tmp/triggers/push-b-captain-hook-master"
UPDATE_SCRIPT="${HOME}/pod-webhooks/scripts/captain_hook_pull_host.py"
while true
do
# bootstrap-pull captain hook
if [ -f "/tmp/triggers/push-b-captain-hook-master" ]; then
if [ -f "$TRIGGER" ]; then
echo "CAPTAIN HOOK'S CANARY:"
echo "Running trigger to update Captain Hook on the host machine (user charles)"
sudo -H -u charles python /home/charles/blackbeard_scripts/captain_hook_pull_host.py
sudo -H -u charles python $UPDATE_SCRIPT
echo "All done."
rm -f "/tmp/triggers/push-b-captain-hook-master"
rm -f ${TRIGGER}
fi
sleep 10;
@ -97,7 +107,7 @@ of Captain Hook running on the host, and @@ -97,7 +107,7 @@ of Captain Hook running on the host, and
restart the container pod.
"""
work_dir = os.path.join('/home','charles','codes','bots','b-captain-hook')
work_dir = os.path.join('/home','charles','pod-webhooks','b-captain-hook')
# Step 1:
# Update Captain Hook
@ -121,18 +131,18 @@ The stop directive uses pgrep to find the process id and stops any PIDs returned @@ -121,18 +131,18 @@ The stop directive uses pgrep to find the process id and stops any PIDs returned
```
[Unit]
Description=captain hook canary script
Requires=dockerpod-captainhook.service
After=dockerpod-captainhook.service
Requires=pod-webhooks.service
After=pod-webhooks.service
[Service]
Restart=always
ExecStart=/home/charles/blackbeard_scripts/captain_hook_canary.sh
ExecStart=/home/charles/pod-webhooks/scripts/captain_hook_canary.sh
ExecStop=/usr/bin/pgrep -f captain_hook_canary | /usr/bin/xargs /bin/kill
[Install]
WantedBy=default.target
```
See [Services](Services.md) for more info on what to do with this file.
See [Services](services.md) for more info on what to do with this file.

11
docs/css/custom.css

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
.md-typeset h1 { font-weight: 600; }
.md-typeset h2 { font-weight: 600; }
.md-typeset h3 { font-weight: 600; }
.md-typeset h4 { font-weight: 600; }
body {
background-color: #FAFAFA;
}
div.body {
background-color: #FAFAFA;
}

106
docs/index.md

@ -9,22 +9,49 @@ This docker pod runs two services: @@ -9,22 +9,49 @@ This docker pod runs two services:
These two services are in this repo as submodules.
## Links
See documentation page here: <https://pages.charlesreid1.com/pod-webhooks>
Source code on git.charlesreid1.com: <https://git.charlesreid1.com/docker/pod-webhooks>
Source code on github.com: <https://github.com/charlesreid1-docker/pod-webhooks>
## Initial Setup of Pages Subdomain
The pages.charlesreid1.com subdomain is served from content
in the directory `/www/pages.charlesreid1.com`.
To set this up with pages and sites that should exist already,
use the set up script at `scripts/pages_init_setup.py` and
run it on the pages.charlesreid1.com server:
```
python scripts/pages_init_setup.py
```
This will create the `/www/pages.charlesreid1.com/` directory
structure and will clone several repositories to populate it
with content.
## Adding Hooks
Since this is probably the only thing you'll care about once everything
is actually running... until it breaks.
[How To Add A Hook](Adding.md)
[How To Add A Hook](adding.md)
## How It Works
See [Running.md](Running.md) for info about running this docker pod.
See [Running.md](running.md) for info about running this docker pod.
* Running the Docker Pod from Comand Line
* Workflow for Docker Pod Updates
See [Services.md](Services.md) for info about running startup services.
See [Services.md](services.md) for info about running startup services.
* Running the Docker Pod as a Startup Service
* Running Captain Hook's Canary (Script)
@ -32,18 +59,18 @@ See [Services.md](Services.md) for info about running startup services. @@ -32,18 +59,18 @@ See [Services.md](Services.md) for info about running startup services.
Enable/disable service (installs/uninstalls, but does not start):
```
sudo systemctl (enable|disable) dockerpod-webhooks.service
sudo systemctl (enable|disable) pod-webhooks.service
sudo systemctl (enable|disable) captain-hook-canary.service
```
Start/stop:
```
sudo systemctl (start|stop) dockerpod-webhooks.service
sudo systemctl (start|stop) pod-webhooks.service
sudo systemctl (start|stop) captain-hook-canary.service
```
See [Captain Hook's Canary (Canary.md)](Canary.md) for details on the canary script that allows the
See [Captain Hook's Canary](canary.md) for details on the canary script that allows the
webhooks docker pod to trigger itself to be re-loaded when there are new hooks
added to captain hook.
@ -71,32 +98,34 @@ on the contents of `/www/pages.charlesreid1.com/my-page`. @@ -71,32 +98,34 @@ on the contents of `/www/pages.charlesreid1.com/my-page`.
### Captain Hook's Canary
Captain Hook presents a bit of a paradox: the webhook docker pod needs to be
able to tell the host to restart the webhook docker pod when changes are pushed
to Captain Hook itself.
Captain Hook presents a bit of a paradox: what happens when Captain Hook installs
a hook for itself, and detects that Captain Hook itself has changed?
This is done by Captain Hook's Canary. This is a script that checks every 10 seconds
for a trigger file in a directory mounted between the host and container. If the
trigger file is present, the host will update its copy of Captain Hook,
In this case, the webhooks docker pod needs to be able to tell the host machine
to restart the webhooks docker pod.
This is done by Captain Hook's Canary. This is a service script that checks every
10 seconds for a trigger file in a directory mounted between the host and container.
If the trigger file is present, the host will update its copy of Captain Hook,
then restart the webhooks-subdomains docker pod.
As per the [`blackbeard_scripts`](https://git.charlesreid1.com/dotfiles/debian/src/branch/master/dotfiles/blackbeard_scripts)
directory of [dotfiles/debian](https://git.charlesreid1.com/dotfiles/debian),
As per the [dotfiles/debian](https://git.charlesreid1.com/dotfiles/debian) repo,
the `captain_hook_canary.sh` canary will restart the webhooks docker pod if it
detects the file:
detects the presence following file:
```
/tmp/triggers/push-b-captain-hook-master
```
(The canary script will clean up this file.)
(The canary script will remove this file once it has restarted the webhooks docker pod.)
Now a hook can be added to Captain Hook that will be run when there is a push event
Now, a hook can be added to Captain Hook that will be run when there is a push event
on the master branch of [bots/b-captain-hook](https://git.charlesreid1.com/bots/b-captain-hook).
By creating a hook named `push-b-captain-hook-master` in the
`hooks/` directory of captain hook that runs a simple `touch` command,
this webhook can trigger the script which triggers a restart of the
docker pod.
`hooks/` directory of Captain Hook, and having it simply run
`touch /tmp/triggers/push-b-captain-hook-master`,
this webhook can trigger the Captain Hook's Canary service script,
which triggers a restart of the webhooks docker pod.
Code: <https://git.charlesreid1.com/bots/b-captain-hook/src/branch/master/hooks/push-b-captain-hook-master>
@ -118,15 +147,30 @@ the correct secret or the trigger will be ignored. @@ -118,15 +147,30 @@ the correct secret or the trigger will be ignored.
## Servers
This pod runs on blackbeard.
The nginx service is reverse-proxied HTTP with krash,
and accessible at ports 7777+ and up.
The Captain Hook webhook server is also reverse-proxied HTTP.
The krash nginx server will handle all traffic to
<https://hooks.charlesreid1.com> except URLs prefixed
with `webhook`, which are forwarded on to Captain Hook
on port 5000.
[pod-webhooks](https://pages.charlesreid1.com/pod-webhooks/)
runs on a virtual server somewhere.
This pod's nginx service provides a backend that is
reverse-proxied by the machine running
[pod-charlesreid1](https://pages.charlesreid1.com/pod-charlesreid1)
(and the whole <https://charlesreid1.com> frontend).
It opens ports 7777+ and up (one per subdomain).
The [pod-charlesreid1](https://pages.charlesreid1.com/pod-charlesreid1)
docker pod (actually the
[d-nginx-charlesreid1](https://pages.charlesreid1.com/d-nginx-charlesreid1/)
submodule in that pod) contains the nginx
config files that control the reverse proxy
behavior of <https://charlesreid1.com>.
Like the nginx service in this webhooks pod, the Captain Hook
webhook service is also reverse-proxied by the main nginx frontend
running <https://charlesreid1.com> with the
[pod-charlesreid1](https://pages.charlesreid1.com/pod-charlesreid1)
docker pod. If a URL request for <https://hooks.charlesreid1.com>
is received by the <https://charlesreid1.com> server,
it is forwarded to the machine running the [pod-webhooks](https://git.charlesreid1.com/pod-webhooks)
docker pod, which decides whether it is a POST request
(that should be sent to this pod's Captain Hook) or a GET request
(that should be sent to this pod's nginx).

15
docs/Running.md → docs/running.md

@ -1,12 +1,13 @@ @@ -1,12 +1,13 @@
## The Docker Compose File
The `docker-compose.yml` file contains all the directives needed
to run a docker pod for captain hook and the subdomains nginx server.
The `docker-compose.yml` file contains everything needed to
run the webhooks docker pod: a Captain Hook webhook server, and
an nginx server to serve up static pages for each subdomain.
Why use docker-compose instead of docker?
docker-compose is the preferred way to run multiple containers.
## Running Webhooks-Subdomains Docker Pod from Command Line
## Running Webhooks Docker Pod from Command Line
Run the pod in the foreground or background by running these
commands from the directory containing `docker-compose.yml`:
@ -16,13 +17,15 @@ docker-compose up # interactive @@ -16,13 +17,15 @@ docker-compose up # interactive
docker-compose up -d # detached
```
If you want to rebuild all the containers before running up,
If you want to rebuild all the containers before bringing
the pod up, add the `--build` flag:
```
docker-compose up --build
```
If you just want to rebuild the containers,
If you just want to rebuild the containers without bringing
them up,
```
docker-compose build
@ -35,7 +38,7 @@ docker-compose build --no-cache @@ -35,7 +38,7 @@ docker-compose build --no-cache
```
***WARNING:*** this will re-download all aptitude packages,
which can be extremely slow. Use with caution.)
which can be extremely slow. Use with caution.
You can restart all containers in a pod using the restart command:

93
docs/services.md

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
## Running Hooks-Subdomains Docker Pod as Startup Service
The webhooks-subdomains docker pod requires two startup
services:
* Docker pod service - this startup service keeps the pod running,
and will restart it if it crashes
* Captain Hook's canary - this watches a folder that is shared between
the docker pod host and the Captain Hook container, which allows the
pod to send triggers to the host.
Also see the `scripts/` folder of this repo,
[pod-webhooks](https://git.charlesreid1.com/docker/pod-webhooks)
([Github mirror](https://github.com/charlesreid1-docker/pod-webhooks)).
### Docker Pod Startup Service
This service keeps the webhooks docker pod service running
continuously. If the pod stops, this service will restart it.
(This service should not be running if you are troubleshooting
the docker pod, otherwise every time you try and stop the pod
it will respawn.)
**`pod-webhooks.service:`**
```
[Unit]
Description=webhooks and subdomains docker pod
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f /home/charles/codes/docker/pod-webhooks/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /home/charles/codes/docker/pod-webhooks/docker-compose.yml down
[Install]
WantedBy=default.target
```
### Captain Hook's Canary Startup Service
This service just watches a folder for a particular
watchfile, and runs a script if it sees the watchfile
appear.
**`captain-hook-canary.service:`**
```
[Unit]
Description=captain hook canary script
Requires=pod-webhooks.service
After=pod-webhooks.service
[Service]
Restart=always
ExecStart=/home/charles/pod-webhooks/scripts/captain_hook_canary.sh
ExecStop=/usr/bin/pgrep -f captain_hook_canary | /usr/bin/xargs /bin/kill
[Install]
WantedBy=default.target
```
### Installing Services
Install the services by copying the `*.service` files
to `/etc/systemd/system/dockerpod-webhooks.servce`
and `/etc/systemd/system/captain-hook-canary.servce`,
and activate the startup services:
```
sudo systemctl enable pod-webhooks.service
sudo systemctl enable captain-hook-canary.service
```
Now you can start/stop the services with:
```
sudo systemctl (start|stop) pod-webhooks.service
sudo systemctl (start|stop) captain-hook-canary.service
```
As mentioned above, these services should be stopped before
doing a `docker-compose stop` or a `docker-compose up --build`
to keep the pod from respawning in the middle of the task.

2
mkdocs-material

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit 6569122bb1e9d6bd73fd964639c33c9a3a4f46d3
Subproject commit b0c6890853aa9138baf5f9749862b927518ab656

17
mkdocs.yml

@ -13,19 +13,19 @@ theme: @@ -13,19 +13,19 @@ theme:
name: null
custom_dir: 'mkdocs-material/material'
palette:
primary: 'pink'
accent: 'pink'
primary: 'blue'
accent: 'blue'
logo:
icon: 'dns'
font:
text: 'Roboto'
code: 'Roboto Mono'
pages:
- Home: 'index.md'
- Adding Webhooks: 'Adding.md'
- Running Captain Hook: 'Running.md'
- Captain Hook Startup Services: 'Services.md'
- Captain Hook's Canary: 'Canary.md'
nav:
- "Home": "index.md"
- "Adding Webhooks": "adding.md"
- "Running Captain Hook": "running.md"
- "Captain Hook Startup Services": "services.md"
- "Captain Hook's Canary": "canary.md"
# Extensions
markdown_extensions:
@ -35,3 +35,4 @@ markdown_extensions: @@ -35,3 +35,4 @@ markdown_extensions:
- toc:
permalink: true
strict: true

24
scripts/Readme.md

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
# pod-webhooks scripts
Copy this `pod-webhooks.service` service script to
`/etc/systemd/system/pod-webhooks.service`:
```
sudo cp pod-webhooks.service /etc/systemd/system/pod-webhooks.service
```
Enable/disable the service:
```
sudo systemctl enable pod-webhooks
sudo systemctl disable pod-webhooks
```
Start/restart/stop the service:
```
sudo systemctl start pod-webhooks
sudo systemctl restart pod-webhooks
sudo systemctl stop pod-webhooks
```

89
scripts/apply_templates_captainhook.py

@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
import os, re, sys
import glob
from jinja2 import Environment, FileSystemLoader, select_autoescape
"""
Apply Default Values to
Captain Hook Jinja Templates
This script applies default values to
templates in this folder.
The templates are used by Ansible,
but this script uses the same template
engine as Ansible to apply template
variable values to the template files
and make real files.
variables are:
- `webhooks_install_dir` - location of pod-webhooks repo
- `username` - user/group name to change ownership to
- `server_name_default` - name of server
(e.g., charlesreid1.com or charlesreid1.red)
"""
# Where templates live
TEMPLATEDIR = '.'
# Where rendered templates will go
OUTDIR = 'output'
# Should existing (destination) files
# be overwritten if they exist?
OVERWRITE = True
# Template variables
TV = {
'server_name_default': 'charlesreid1.red',
'username': 'charles',
'webhooks_install_dir' : '/home/charles/pod-webhooks'
}
def apply_templates(template_dir, output_dir, template_vars, overwrite=False):
"""Apply the template variables
to the template files.
"""
if not os.path.exists(output_dir):
msg = "Error: output dir %s does not exist!"%(output_dir)
raise Exception(msg)
if not os.path.exists(template_dir):
msg = "Error: template dir %s does not exist!"%(output_dir)
raise Exception(msg)
# Jinja env
env = Environment(loader=FileSystemLoader('.'))
# Render templates
template_files = glob.glob('captain*.j2')
render_files = [re.sub('\.j2','',s) for s in template_files]
for rfile,tfile in zip(render_files,template_files):
# Get rendered template content
content = env.get_template(tfile).render(**template_vars)
# Write to file
dest = os.path.join(output_dir,rfile)
if os.path.exists(dest) and overwrite is False:
msg = "Error: template rendering destination %s already exists!"%(dest)
raise Exception(msg)
with open(dest,'w') as f:
f.write(content)
print("Rendered the following templates:%s\nOutput files:%s\n"%(
"".join(["\n- "+os.path.join(template_dir,j) for j in template_files]),
"".join(["\n- "+os.path.join(output_dir,j) for j in render_files])
))
if __name__=="__main__":
apply_templates(TEMPLATEDIR,OUTDIR,TV,OVERWRITE)

84
scripts/apply_templates_pod.py

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
import os, re, sys
import glob
from jinja2 import Environment, FileSystemLoader, select_autoescape
"""
Apply Default Values to
pod-webhooks Jinja Templates
This script applies default values to
templates in this folder.
The templates are used by Ansible,
but this script uses the same template
engine as Ansible to apply template
variable values to the template files
and make real files.
variables are:
- `webhooks_install_dir` - location of pod-webhooks repo
(i.e., location of pod-webhooks docker-compose file)
"""
# Where templates live
TEMPLATEDIR = '.'
# Where rendered templates will go
OUTDIR = 'output'
# Should existing (destination) files
# be overwritten if they exist?
OVERWRITE = True
# Template variables
TV = {
'webhooks_install_dir' : '/home/charles/pod-webhooks'
}
def apply_templates(template_dir, output_dir, template_vars, overwrite=False):
"""Apply the template variables
to the template files.
"""
if not os.path.exists(output_dir):
msg = "Error: output dir %s does not exist!"%(output_dir)
raise Exception(msg)
if not os.path.exists(template_dir):
msg = "Error: template dir %s does not exist!"%(output_dir)
raise Exception(msg)
# Jinja env
env = Environment(loader=FileSystemLoader('.'))
# Render templates
template_files = glob.glob('*.service.j2')
render_files = [re.sub('\.j2','',s) for s in template_files]
for rfile,tfile in zip(render_files,template_files):
# Get rendered template content
content = env.get_template(tfile).render(**template_vars)
# Write to file
dest = os.path.join(output_dir,rfile)
if os.path.exists(dest) and overwrite is False:
msg = "Error: template rendering destination %s already exists!"%(dest)
raise Exception(msg)
with open(dest,'w') as f:
f.write(content)
print("Rendered the following templates:%s\nOutput files:%s\n"%(
"".join(["\n- "+os.path.join(template_dir,j) for j in template_files]),
"".join(["\n- "+os.path.join(output_dir,j) for j in render_files])
))
if __name__=="__main__":
apply_templates(TEMPLATEDIR,OUTDIR,TV,OVERWRITE)

90
scripts/apply_templates_subdomains.py

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
import os, re, sys
import glob
import subprocess
from jinja2 import Environment, FileSystemLoader, select_autoescape
"""
Apply Default Values to
SUBDOMAINS Jinja Templates
This script applies default values to
templates in this folder.
The templates are used by Ansible,
but this script uses the same template
engine as Ansible to apply template
variable values to the template files
and make real files.
only variables are:
- `username` - user/group name to change ownership to
- `server_name_default` - name of server
(e.g., charlesreid1.com or charlesreid1.red)
"""
# Where templates live
TEMPLATEDIR = '.'
# Where rendered templates will go
OUTDIR = 'output'
# Should existing (destination) files
# be overwritten if they exist?
OVERWRITE = True
# Template variables
TV = {
'server_name_default': 'charlesreid1.red',
'username': 'charles'
}
def apply_templates(template_dir, output_dir, template_vars, overwrite=False):
"""Apply the template variables
to the template files.
"""
if not os.path.exists(output_dir):
msg = "Error: output dir %s does not exist!"%(output_dir)
raise Exception(msg)
if not os.path.exists(template_dir):
msg = "Error: template dir %s does not exist!"%(output_dir)
raise Exception(msg)
# Jinja env
env = Environment(loader=FileSystemLoader('.'))
# Render templates
template_files = glob.glob('*_setup.py.j2') + glob.glob('*_pull.py.j2')
render_files = [re.sub('\.j2','',s) for s in template_files]
for rfile,tfile in zip(render_files,template_files):
# Get rendered template content
content = env.get_template(tfile).render(**template_vars)
# Write to file
dest = os.path.join(output_dir,rfile)
if os.path.exists(dest) and overwrite is False:
msg = "Error: template rendering destination %s already exists!"%(dest)
raise Exception(msg)
with open(dest,'w') as f:
f.write(content)
x = 'executioner.py'
subprocess.call(['cp',x,os.path.join(output_dir,x)])
print("Rendered the following templates:%s\nOutput files:%s\n"%(
"".join(["\n- "+os.path.join(template_dir,j) for j in template_files]),
"".join(["\n- "+os.path.join(output_dir,j) for j in render_files])
))
if __name__=="__main__":
apply_templates(TEMPLATEDIR,OUTDIR,TV,OVERWRITE)

12
scripts/captain-hook-canary.service.j2

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
[Unit]
Description=captain hook canary script
Requires=pod-webhooks.service
After=pod-webhooks.service
[Service]
Restart=always
ExecStart={{ webhooks_install_dir }}/scripts/captain_hook_canary.sh
ExecStop=/usr/bin/pgrep -f captain_hook_canary | /usr/bin/xargs /bin/kill
[Install]
WantedBy=default.target

47
scripts/captain_hook_canary.sh.j2

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
#!/bin/bash
: '
Captain Hook Canary Script (Template)
Note: this needs an associated systemd service.
See the services directory of the dotfiles repo.
This is a canary script for connecting
the Captain Hook container to the host
machine, and triggering tasks on the
host machine with webhooks.
The Captain Hook container mounts the
following host directory inside the
container (same location for host/container):
/tmp/triggers/
When a webhook in Captain Hook wants to
trigger an event on the host (blackbeard),
it puts a file in /tmp/triggers/.
Meanwhile, on the host, this script checks
every 10 seconds for trigger files.
Each webhook can create its own trigger file,
and this script processes each trigger differently.
'
while true
do
# bootstrap-pull captain hook
if [ -f "/tmp/triggers/push-b-captain-hook-master" ]; then
echo "CAPTAIN HOOK'S CANARY:"
echo "Running trigger to update Captain Hook on the host machine (user charles)"
sudo -H -u charles python {{ webhooks_install_dir }}/scripts/captain_hook_pull_host.py
echo "All done."
rm -f "/tmp/triggers/push-b-captain-hook-master"
touch /tmp/canary-yup-host-works
fi
sleep 10;
done

110
scripts/captain_hook_pull_host.py.j2

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
#!/usr/bin/env python3
import subprocess
import os
import time
"""
Captain Hook: Pull Captain Hook on the Host
This script is called by the host machine
(blackbeard) running the Captain Hook container.
This is triggered by push actions to the
master branch of b-captain-hook.
The action is to update (git pull) the copy
of Captain Hook running on the host, and
restart the container pod.
"""
pod_dir = '{{ webhooks_install_dir }}'
work_dir = os.path.join(pod_dir,'b-captain-hook')
from datetime import datetime
d = datetime.now().strftime('%Y-m-%d')
with open('/tmp/captain_hook_pull_host_%s.log'%(d),'w') as f:
# Step 1:
# Update Captain Hook
co_cmd = ['git','checkout','master']
proc = subprocess.call(co_cmd, cwd=work_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
o = stdout.decode('utf-8')
e = stderr.decode('utf-8')
f.write(" ".join(co_cmd))
f.write("\n")
f.write("-"*40)
f.write("\n")
f.write(o)
f.write("\n")
f.write(e)
f.write("\n\n")
f_cmd = ['git','fetch','--all']
proc = subprocess.call(f_cmd, cwd=work_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
o = stdout.decode('utf-8')
e = stderr.decode('utf-8')
f.write(" ".join(f_cmd))
f.write("\n")
f.write("-"*40)
f.write("\n")
f.write(o)
f.write("\n")
f.write(e)
f.write("\n\n")
time.sleep(5)
pull_cmd = ['git','pull','origin','master']
proc = subprocess.call(pull_cmd, cwd=work_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
o = stdout.decode('utf-8')
e = stderr.decode('utf-8')
f.write(" ".join(pull_cmd))
f.write("\n")
f.write("-"*40)
f.write("\n")
f.write(o)
f.write("\n")
f.write(e)
f.write("\n\n")
time.sleep(10)
submod_cmd = ['git','submodule','update','--remote']
proc = subprocess.call(submod_cmd, cwd=work_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
o = stdout.decode('utf-8')
e = stderr.decode('utf-8')
f.write(" ".join(pull_cmd))
f.write("\n")
f.write("-"*40)
f.write("\n")
f.write(o)
f.write("\n")
f.write(e)
f.write("\n\n")
time.sleep(10)
# Step 2:
# Restart Captain Hook pod
pod_restart = ['systemctl','restart','pod-webhooks']
#pod_restart = ['docker-compose','restart']
proc = subprocess.call(pod_restart, cwd=pod_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
o = stdout.decode('utf-8')
e = stderr.decode('utf-8')
f.write(" ".join(pod_restart))
f.write("\n")
f.write("-"*40)
f.write("\n")
f.write(o)
f.write("\n")
f.write(e)
f.write("\n\n")

21
scripts/executioner.py

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
#!/usr/bin/env python3
import subprocess
import os
def execute(cmd):
"""
A function to run a command and return the
lines of output as they are generated,
allowing the calling function to "stream"
the output of the command to print() or etc.
"""
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(p.stdout.readline, ""):
yield stdout_line
p.stdout.close()
err = "".join([j for j in iter(p.stderr.readline,"")])
return_code = p.wait()
if return_code:
yield err
raise subprocess.CalledProcessError(return_code, cmd)

125
scripts/pages_init_setup.py.j2

@ -0,0 +1,125 @@ @@ -0,0 +1,125 @@
#!/usr/bin/env python3
import subprocess
import os
from executioner import execute
"""
Pages Initial Setup
This script sets up the initial pages.charlesreid1.XYZ
folder structure and checks out all pages that should
be present initially at pages.charlesreid1.XYZ.
This clones the page for a given project to
/www/pages.charlesreid1.XYZ/htdocs/project-name
(where project = repo)
"""
SERVER_NAME_DEFAULT = '{{ server_name_default }}'
USERNAME = '{{ username }}'
# Repos must have a gh-pages branch
repo_names = '''bots/b-apollo
bots/b-captain-hook
bots/b-ginsberg
bots/b-milton
bots/uncle-archie
bots/boring-mind-machine
docker/d-gitea
docker/d-mediawiki
docker/d-mysql
docker/d-nginx-charlesreid1
docker/d-nginx-subdomains
docker/d-phpmyadmin
docker/d-python-files
docker/d-python-helium
charlesreid1/dont-sudo-pip
bots/embarcadero-mind-machine
charlesreid1/git-commit-ectomy
charlesreid1/git-subway-maps
charlesreid1/github-heroku-attack-rabbits
charlesreid1/how-do-i-heroku
charlesreid1/how-do-i-pandoc
charlesreid1/how-do-i-pelican
charlesreid1/how-do-i-pyenv
charlesreid1/how-do-i-snakemake
docker/pod-bots
docker/pod-charlesreid1
docker/pod-webhooks
bots/russian-rainbow-mind-machine
charlesreid1/scurvy-knave-theme
charlesreid1/translate-yer-docs
charlesreid1/wisko-manual'''.split('\n')
repo_urls = ['https://git.charlesreid1.com/%s.git'%(j) for j in repo_names]
root = '/www'
pages = 'pages.%s'%(SERVER_NAME_DEFAULT)
basedir = os.path.join(root,pages)
if not os.path.exists(basedir):
raise Exception("Error: base directory %s does not exist!"%(basedir))
for name,url in zip(repo_names,repo_urls):
# for a hypothetical repo "project":
#
# base dir: /www/pages.charlesreid1.com
# .git dir: /www/pages.charlesreid1.com/git.project
# htdocs dir: /www/pages.charlesreid1.com/htdocs/project
# Step 1: clone
# Construct the clone command to set up
# live htdocs directory for this project
repo_owner, repo_name = name.split("/")
clonepth = os.path.join(basedir,"htdocs",repo_name)
dotgitpth = os.path.join(basedir,"git.%s"%(repo_name))
if os.path.exists(clonepth):
print("Git repository has already been cloned, %s already exists on disk!"%(clonepth))
else:
clonecmd = ["git","clone",
"--separate-git-dir=%s"%(dotgitpth),
"-b","gh-pages",
url,clonepth]
print("About to clone gh-pages branch for %s using command:\n"%(name))
print(" $ " + " ".join(clonecmd))
print("\n")
try:
for loo in execute(clonecmd):
print(loo)
print("\n")
print("Done.")
except subprocess.CalledProcessError:
print("Failed on clone command for project %s"%(name))
print("Continuing...")
# Step 2: chown everybody
# Construct chown command
chowncmd = ['chown','-R',
USERNAME+":"+USERNAME,
basedir]
print("About to change owner of %s using command:\n"%(basedir))
print(" $ " + " ".join(chowncmd))
print("\n")
for loo in execute(chowncmd):
print(loo)
print("\n")
print("Done.")

129
scripts/pages_pull.py.j2

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
#!/usr/bin/env python3
import subprocess
import os
from executioner import execute
"""
Pages Pull Script
This script pulls chnages to all repos in the
pages.charlesreid1.XYZ folder structure
This clones the page for a given project to
/www/pages.charlesreid1.XYZ/htdocs/project-name
(where project = repo)
"""
SERVER_NAME_DEFAULT = '{{ server_name_default }}'
USERNAME = '{{ username }}'
# Repos must have a gh-pages branch
repo_names = '''bots/b-apollo
bots/b-captain-hook
bots/b-ginsberg
bots/b-milton
bots/uncle-archie
bots/boring-mind-machine
docker/d-gitea
docker/d-mediawiki
docker/d-mysql
docker/d-nginx-charlesreid1
docker/d-nginx-subdomains
docker/d-phpmyadmin
docker/d-python-files
docker/d-python-helium
charlesreid1/dont-sudo-pip
bots/embarcadero-mind-machine
charlesreid1/git-commit-ectomy
charlesreid1/git-subway-maps
charlesreid1/github-heroku-attack-rabbits
charlesreid1/how-do-i-heroku
charlesreid1/how-do-i-pandoc
charlesreid1/how-do-i-pelican
charlesreid1/how-do-i-pyenv
charlesreid1/how-do-i-snakemake
docker/pod-bots
docker/pod-charlesreid1
docker/pod-webhooks
bots/russian-rainbow-mind-machine
charlesreid1/scurvy-knave-theme
charlesreid1/translate-yer-docs
charlesreid1/wisko-manual'''.split('\n')
repo_urls = ['https://git.charlesreid1.com/%s.git'%(j) for j in repo_names]
root = '/www'
pages = 'pages.%s'%(SERVER_NAME_DEFAULT)
basedir = os.path.join(root,pages)
htdocsdir = os.path.join(basedir,"htdocs")
if not os.path.exists(basedir):
raise Exception("Error: base directory %s does not exist!"%(basedir))
if not os.path.exists(htdocsdir):
raise Exception("Error: htdocs directory %s does not exist!"%(htdocsdir))
for name,url in zip(repo_names,repo_urls):
# for a hypothetical repo "project":
#
# base dir: /www/pages.charlesreid1.com
# .git dir: /www/pages.charlesreid1.com/git.project
# htdocs dir: /www/pages.charlesreid1.com/htdocs/project
# Step 1: pull
# Construct the git pull command to update
# the live htdocs directory for this project
repo_owner, repo_name = name.split("/")
workdir = os.path.join(basedir,"htdocs",repo_name)
dotgitdir = os.path.join(basedir,"git.%s"%(repo_name))
if not os.path.exists(workdir):
print("Git repository has not yet been cloned, %s does not exist on disk!"%(workdir))
else:
pullcmd = ['git',
'-C', basedir,
'--git-dir=%s'%(dotgitdir),
'--work-tree=%s'%(workdir),
'pull','origin','gh-pages']
print("About to pull gh-pages branch for %s using command:\n"%(name))
print(" $ " + " ".join(pullcmd))
print("\n")
try:
for loo in execute(pullcmd):
print(loo)
print("\n")
print("Done.")
except subprocess.CalledProcessError:
print("Failed on pull command for project %s"%(name))
print("Continuing...")
# Step 2: chown everybody
# Construct chown command
chowncmd = ['chown','-R',
USERNAME+":"+USERNAME,
basedir]
print("About to change owner of %s using command:\n"%(basedir))
print(" $ " + " ".join(chowncmd))
print("\n")
for loo in execute(chowncmd):
print(loo)
print("\n")
print("Done.")

14
scripts/pod-webhooks.service.j2

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
# Hopefully this comment works
[Unit]
Description=webhooks and subdomains docker pod
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f {{ webhooks_install_dir }}/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f {{ webhooks_install_dir }}/docker-compose.yml down
[Install]
WantedBy=default.target

89
scripts/subdomains_init_setup.py.j2

@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
#!/usr/bin/env python3
import subprocess
import os
from executioner import execute
"""
Subdomains Initial Setup
This script sets up the initial folder structure
for the charlesreid1.com subdomains and their content.
"""
SERVER_NAME_DEFAULT = '{{ server_name_default }}'
USERNAME = '{{ username }}'
# Each subdomain page has an htdocs dir at
#
# /www/SUBDOMAIN.charlesreid1.XYZ/htdocs
#
# and a .git directory at
#
# /www/SUBDOMAIN.charlesreid1.XYZ/git.SUBDOMAIN.charlesreid1.XYZ
# Name of all subdomains to set up
sub_names = ['bots','pages','hooks']
subs = [n+'.'+SERVER_NAME_DEFAULT for n in sub_names]
# Use git.charlesreid1.com
# (Note we have to hard-code the suffix
# charlesreid1.com b/c that is the name
# of the repo for ALL subdomains)
urls = ['https://git.charlesreid1.com/charlesreid1/%s.charlesreid1.com'%(n) for n in sub_names]
#
# Use github.com (alternative)
# (Note we have to hard-code the suffix charlesreid1.com)
#urls = ['https://github.com/charlesreid1-docker/%s.charlesreid1.com'%(n) for n in sub_names]
# Base directory for all htdocs folders
pth = '/www'
# Create the base directory
subprocess.call(['mkdir','-p',pth])
# Step 1: clone htdocs dir for each subdomain
for subname, sub, url in zip(sub_names,subs,urls):
# Construct the clone command for the live
# htdocs directory for this subdomain
clonepth = os.path.join(pth,sub,'htdocs')
dotgitpth = os.path.join(pth,sub,'git.%s'%(subname))
if os.path.exists(clonepth):
print("Git repository has already been cloned, %s already exists on disk!"%(clonepth))
else:
clonecmd = ['git','clone',
'--separate-git-dir=%s'%(dotgitpth),
'-b','gh-pages',
url,clonepth]
print("About to clone htdocs dir for %s using command:\n"%(sub))
print(" $ " + " ".join(clonecmd))
print("\n")
for loo in execute(clonecmd):
print(loo)
print("\n")
print("Done.")
# Step 2: chown
# Construct chown command to chown everybody
chowncmd = ['chown','-R',USERNAME+":"+USERNAME,pth]
print("About to change owner of %s using command:\n"%(pth))
print(" $ " + " ".join(chowncmd))
print("\n")
for loo in execute(chowncmd):
print(loo)
print("\n")
print("Done.")

95
scripts/subdomains_pull.py.j2

@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
#!/usr/bin/env python3
import subprocess
import os
from executioner import execute
"""
Subdomains Pull Script
This script sets up the initial folder structure
for the charlesreid1.com subdomains and their content.
"""
SERVER_NAME_DEFAULT = '{{ server_name_default }}'
USERNAME = '{{ username }}'
# Each subdomain page has an htdocs dir at
#
# /www/SUBDOMAIN.charlesreid1.XYZ/htdocs
#
# and a .git directory at
#
# /www/SUBDOMAIN.charlesreid1.XYZ/git.SUBDOMAIN.charlesreid1.XYZ
# Name of all subdomains to set up
sub_names = ['bots','pages','hooks']
subs = [n+'.'+SERVER_NAME_DEFAULT for n in sub_names]
# Use git.charlesreid1.com
# (Note we have to hard-code the suffix
# charlesreid1.com b/c that is the name
# of the repo for ALL subdomains)
urls = ['https://git.charlesreid1.com/charlesreid1/%s.charlesreid1.com'%(n) for n in sub_names]
#
# Use github.com (alternative)
# (Note we have to hard-code the suffix charlesreid1.com)
#urls = ['https://github.com/charlesreid1-docker/%s.charlesreid1.com'%(n) for n in sub_names]
# Base directory for all htdocs folders
pth = '/www'
# Create the base directory
subprocess.call(['mkdir','-p',pth])
# Step 1: clone htdocs dir for each subdomain
for subname, sub, url in zip(sub_names,subs,urls):
# Step 1: pull
# Construct the git pull command to update
# the live htdocs directory for this project
basedir = os.path.join(pth,sub)
htdocsdir = os.path.join(basedir,"htdocs")
dotgitdir = os.path.join(basedir,"git.%s"%(subname))
if not os.path.exists(htdocsdir):
print("Git repository has not been cloned, %s does not exist on disk!"%(htdocsdir))
else:
# git pull, respecting the
# unusual .git/repo folder layout
pullcmd = ['git',
'-C', basedir,
'--git-dir=%s'%(dotgitdir),
'--work-tree=%s'%(htdocsdir),
'pull','origin','gh-pages']
print("About to pull htdocs dir for %s using command:\n"%(sub))
print(" $ " + " ".join(pullcmd))
print("\n")
for loo in execute(pullcmd):
print(loo)
print("\n")
print("Done.")
# Step 2: chown
# Construct chown command to chown everybody
chowncmd = ['chown','-R',USERNAME+":"+USERNAME,basedir]
print("About to change owner of %s using command:\n"%(basedir))
print(" $ " + " ".join(chowncmd))
print("\n")
for loo in execute(chowncmd):
print(loo)
print("\n")
print("Done.")
Loading…
Cancel
Save