Skip to content

Commit bc289a9

Browse files
committed
Enhance Cloud Build pipeline with detailed steps for installation, testing, and deployment
1 parent a7a64aa commit bc289a9

File tree

4 files changed

+147
-104
lines changed

4 files changed

+147
-104
lines changed

.github/workflows/linter.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ name: Lint Code Base
1010
on:
1111
workflow_dispatch:
1212
pull_request:
13-
push:
14-
branches:
15-
- main
1613
jobs:
1714
lint:
1815
name: Lint Code Base

.github/workflows/predeploy.yml

Lines changed: 0 additions & 94 deletions
This file was deleted.

.github/workflows/test_website.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ on:
1111
pull_request:
1212
paths-ignore:
1313
- 'sql/**'
14-
push:
15-
branches:
16-
- main
1714
jobs:
1815
build:
1916
name: Build and Test Website

cloudbuild.yaml

Lines changed: 147 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,148 @@
1+
######################################
2+
## Cloud Build Deployment Pipeline ##
3+
######################################
4+
#
5+
# Triggered on every push to main (i.e. when a PR is merged).
6+
# Update the trigger at:
7+
# https://console.cloud.google.com/cloud-build/triggers;region=us-central1/edit/2bd8fcc6-6319-455d-88f2-38d564fe2db8?project=httparchive
8+
#
9+
# Steps:
10+
# 1. build-and-test — install deps, generate chapters, run pytest + URL tests
11+
# 2. generate-ebooks — update timestamps, install Prince, generate PDF ebooks
12+
# 3. deploy — gcloud app deploy (App Engine version = $SHORT_SHA)
13+
# 4. upload-ebooks — gsutil cp PDFs to GCS bucket
14+
#
15+
# $SHORT_SHA is set automatically by Cloud Build on a branch-push trigger.
16+
17+
substitutions:
18+
# Update when a new Prince version is released: https://www.princexml.com/latest/
19+
# python:3.12 is based on Debian Bookworm (12), so use the debian12 package.
20+
_PRINCE_PACKAGE: 'prince_16.1-1_debian12_amd64.deb'
21+
122
steps:
2-
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
3-
entrypoint: 'bash'
4-
args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']
5-
timeout: '1600s'
23+
# ─────────────────────────────────────────────────────────────────────────
24+
# Step 1: Install dependencies, generate all chapters, run full test suite.
25+
# Uses python:3.12 (Debian Bookworm) and installs Node 20 at runtime.
26+
# node_modules persist in /workspace
27+
# and are reused by later steps; Python packages are re-installed per step.
28+
# ─────────────────────────────────────────────────────────────────────────
29+
- name: 'python:3.12'
30+
id: 'build-and-test'
31+
entrypoint: 'bash'
32+
dir: 'src'
33+
args:
34+
- '-c'
35+
- |
36+
set -e
37+
# Install Node.js 20 (nodesource setup script also runs apt-get update)
38+
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
39+
apt-get install -y nodejs
40+
41+
# Install Python dependencies
42+
pip install --quiet -r requirements.txt
43+
44+
# Install Node dependencies (uses package-lock.json for reproducibility)
45+
npm ci
46+
47+
# Start the web server in the background (required for URL tests)
48+
python main.py background &
49+
sleep 3
50+
51+
# Generate all chapters
52+
npm run generate
53+
54+
# Run Python unit tests
55+
npm run pytest
56+
57+
# Run full URL test suite against the running server
58+
npm run test
59+
60+
# ─────────────────────────────────────────────────────────────────────────
61+
# Step 2: Update timestamps then generate PDF ebooks.
62+
# Prince fetches pages from a running localhost server, so the Python server
63+
# is re-started here. Chapters written to /workspace/src in step 1 are
64+
# served directly; npm install is skipped (node_modules already present).
65+
# ─────────────────────────────────────────────────────────────────────────
66+
- name: 'python:3.12'
67+
id: 'generate-ebooks'
68+
entrypoint: 'bash'
69+
dir: 'src'
70+
args:
71+
- '-c'
72+
- |
73+
set -e
74+
apt-get update -qq
75+
76+
# Install Node.js 20
77+
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
78+
apt-get install -y nodejs
79+
80+
# Update static-asset cache-busting hashes before deploying
81+
npm run timestamps
82+
83+
# Install CJK fonts for multilingual ebooks
84+
apt-get install -y fonts-ipafont-gothic fonts-arphic-uming fonts-unfonts-core wget
85+
86+
# Install pdftk (ebook post-processing)
87+
apt-get install -y pdftk
88+
89+
# Download and install Prince PDF generator
90+
wget -q "https://www.princexml.com/download/${_PRINCE_PACKAGE}" -P /tmp
91+
apt-get install -y "/tmp/${_PRINCE_PACKAGE}"
92+
93+
# Install Python dependencies (needed to run the web server)
94+
pip install --quiet -r requirements.txt
95+
96+
# Re-start the web server so Prince can fetch pages from localhost
97+
python main.py background &
98+
sleep 3
99+
100+
# Generate PDF ebooks
101+
mkdir -p static/pdfs
102+
npm run ebooks
103+
104+
# ─────────────────────────────────────────────────────────────────────────
105+
# Step 3: Deploy to Google App Engine.
106+
# app.yaml is read from /workspace/src (dir: src).
107+
# App Engine version labels must start with a letter, so SHORT_SHA is
108+
# prefixed: e.g. a1b2c3d → deploy-a1b2c3d.
109+
# ─────────────────────────────────────────────────────────────────────────
110+
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
111+
id: 'deploy'
112+
entrypoint: 'bash'
113+
dir: 'src'
114+
args:
115+
- '-c'
116+
- |
117+
set -e
118+
VERSION="deploy-${SHORT_SHA}"
119+
echo "Deploying version: ${VERSION}"
120+
gcloud app deploy \
121+
--project webalmanac \
122+
--version="${VERSION}" \
123+
--stop-previous-version \
124+
--quiet
125+
126+
# ─────────────────────────────────────────────────────────────────────────
127+
# Step 4: Upload generated ebooks to GCS.
128+
# Uses nullglob so missing PDFs produce a warning rather than an error.
129+
# ─────────────────────────────────────────────────────────────────────────
130+
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
131+
id: 'upload-ebooks'
132+
entrypoint: 'bash'
133+
args:
134+
- '-c'
135+
- |
136+
set -e
137+
shopt -s nullglob
138+
pdfs=(/workspace/src/static/pdfs/web_almanac_*.pdf)
139+
if [[ ${#pdfs[@]} -gt 0 ]]; then
140+
gsutil -m cp "${pdfs[@]}" gs://httparchive/almanac/ebooks/
141+
echo "Uploaded ${#pdfs[@]} PDF(s) to GCS"
142+
else
143+
echo "Warning: no ebooks found to upload"
144+
fi
145+
146+
# Total timeout covers: ~10 min build/test + ~30 min ebook generation +
147+
# ~10 min deploy + ~5 min GCS upload.
148+
timeout: '3600s'

0 commit comments

Comments
 (0)