feat: deploy modern IT history ebook
This commit is contained in:
parent
ae1e5813a9
commit
29dd6a38b7
8
deploy_modern_it_history.yml
Normal file
8
deploy_modern_it_history.yml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Deploy Modern IT History Docusaurus ebook
|
||||
hosts: "{{ modern_it_history_target_host | default('jp_xhttp_contabo_host') }}"
|
||||
gather_facts: true
|
||||
become: true
|
||||
roles:
|
||||
- roles/vhosts/nodejs
|
||||
- roles/vhosts/modern_it_history
|
||||
10
roles/vhosts/modern_it_history/defaults/main.yml
Normal file
10
roles/vhosts/modern_it_history/defaults/main.yml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
modern_it_history_domain: ebook.svc.plus
|
||||
modern_it_history_repo: https://github.com/haitaopanhq/modern-it-infrastructure-evolution.git
|
||||
modern_it_history_branch: main
|
||||
modern_it_history_root: /opt/modern-it-history
|
||||
modern_it_history_repo_dir: "{{ modern_it_history_root }}/repo"
|
||||
modern_it_history_current_dir: "{{ modern_it_history_root }}/current"
|
||||
modern_it_history_build_dir: "{{ modern_it_history_repo_dir }}/build"
|
||||
modern_it_history_update_interval: 5min
|
||||
modern_it_history_node_env: production
|
||||
9
roles/vhosts/modern_it_history/handlers/main.yml
Normal file
9
roles/vhosts/modern_it_history/handlers/main.yml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: Reload systemd
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
|
||||
- name: Reload caddy
|
||||
ansible.builtin.systemd:
|
||||
name: caddy
|
||||
state: reloaded
|
||||
110
roles/vhosts/modern_it_history/tasks/main.yml
Normal file
110
roles/vhosts/modern_it_history/tasks/main.yml
Normal file
@ -0,0 +1,110 @@
|
||||
---
|
||||
- name: Install site build prerequisites
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- git
|
||||
- rsync
|
||||
- caddy
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Ensure Modern IT History directories exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
loop:
|
||||
- "{{ modern_it_history_root }}"
|
||||
- "{{ modern_it_history_current_dir }}"
|
||||
|
||||
- name: Clone or update Modern IT History repository
|
||||
ansible.builtin.git:
|
||||
repo: "{{ modern_it_history_repo }}"
|
||||
dest: "{{ modern_it_history_repo_dir }}"
|
||||
version: "{{ modern_it_history_branch }}"
|
||||
force: true
|
||||
update: true
|
||||
|
||||
- name: Install Docusaurus dependencies
|
||||
ansible.builtin.command: npm ci
|
||||
args:
|
||||
chdir: "{{ modern_it_history_repo_dir }}"
|
||||
environment:
|
||||
NODE_ENV: "{{ modern_it_history_node_env }}"
|
||||
|
||||
- name: Build Docusaurus static site
|
||||
ansible.builtin.command: npm run build
|
||||
args:
|
||||
chdir: "{{ modern_it_history_repo_dir }}"
|
||||
environment:
|
||||
NODE_ENV: "{{ modern_it_history_node_env }}"
|
||||
|
||||
- name: Publish Docusaurus build to current static root
|
||||
ansible.builtin.command: >
|
||||
rsync -a --delete {{ modern_it_history_build_dir }}/ {{ modern_it_history_current_dir }}/
|
||||
|
||||
- name: Install GitHub auto-update script
|
||||
ansible.builtin.template:
|
||||
src: modern-it-history-update.sh.j2
|
||||
dest: /usr/local/bin/modern-it-history-update
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
|
||||
- name: Install Modern IT History update service
|
||||
ansible.builtin.template:
|
||||
src: modern-it-history-update.service.j2
|
||||
dest: /etc/systemd/system/modern-it-history-update.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Reload systemd
|
||||
|
||||
- name: Install Modern IT History update timer
|
||||
ansible.builtin.template:
|
||||
src: modern-it-history-update.timer.j2
|
||||
dest: /etc/systemd/system/modern-it-history-update.timer
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Reload systemd
|
||||
|
||||
- name: Install ebook Caddy site
|
||||
ansible.builtin.template:
|
||||
src: ebook.svc.plus.caddy.j2
|
||||
dest: /etc/caddy/sites-enabled/{{ modern_it_history_domain }}.caddy
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Reload caddy
|
||||
|
||||
- name: Validate Caddy config
|
||||
ansible.builtin.command: caddy validate --config /etc/caddy/Caddyfile
|
||||
changed_when: false
|
||||
|
||||
- name: Enable GitHub auto-update timer
|
||||
ansible.builtin.systemd:
|
||||
name: modern-it-history-update.timer
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: true
|
||||
|
||||
- name: Ensure Caddy is enabled and running
|
||||
ansible.builtin.systemd:
|
||||
name: caddy
|
||||
enabled: true
|
||||
state: started
|
||||
|
||||
- name: Validate local ebook endpoint
|
||||
ansible.builtin.uri:
|
||||
url: "http://127.0.0.1/"
|
||||
headers:
|
||||
Host: "{{ modern_it_history_domain }}"
|
||||
status_code: 200
|
||||
register: modern_it_history_local_check
|
||||
|
||||
- name: Show local validation status
|
||||
ansible.builtin.debug:
|
||||
msg: "ebook local validation status={{ modern_it_history_local_check.status }}"
|
||||
@ -0,0 +1,23 @@
|
||||
{{ modern_it_history_domain }} {
|
||||
root * {{ modern_it_history_current_dir }}
|
||||
encode zstd gzip
|
||||
try_files {path} {path}/ /index.html
|
||||
file_server
|
||||
|
||||
header {
|
||||
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
|
||||
X-Content-Type-Options "nosniff"
|
||||
Referrer-Policy "strict-origin-when-cross-origin"
|
||||
Permissions-Policy "geolocation=(), microphone=(), camera=()"
|
||||
}
|
||||
|
||||
@static {
|
||||
path *.js *.css *.png *.jpg *.jpeg *.gif *.svg *.webp *.ico *.woff *.woff2
|
||||
}
|
||||
header @static Cache-Control "public, max-age=31536000, immutable"
|
||||
|
||||
@html {
|
||||
path *.html /
|
||||
}
|
||||
header @html Cache-Control "public, max-age=300"
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Update Modern IT History Docusaurus ebook from GitHub
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/modern-it-history-update
|
||||
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
repo_dir="{{ modern_it_history_repo_dir }}"
|
||||
current_dir="{{ modern_it_history_current_dir }}"
|
||||
build_dir="{{ modern_it_history_build_dir }}"
|
||||
branch="{{ modern_it_history_branch }}"
|
||||
|
||||
cd "$repo_dir"
|
||||
before="$(git rev-parse HEAD 2>/dev/null || true)"
|
||||
git fetch origin "$branch"
|
||||
git reset --hard "origin/$branch"
|
||||
after="$(git rev-parse HEAD)"
|
||||
|
||||
if [[ "$before" == "$after" && -d "$current_dir" && -n "$(find "$current_dir" -mindepth 1 -maxdepth 1 -print -quit)" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
npm ci
|
||||
npm run build
|
||||
rsync -a --delete "$build_dir"/ "$current_dir"/
|
||||
caddy validate --config /etc/caddy/Caddyfile
|
||||
systemctl reload caddy
|
||||
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Run Modern IT History GitHub auto-update
|
||||
|
||||
[Timer]
|
||||
OnBootSec=2min
|
||||
OnUnitActiveSec={{ modern_it_history_update_interval }}
|
||||
Unit=modern-it-history-update.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Loading…
Reference in New Issue
Block a user