Pin mdBook in image and add CloudFront invalidation workflow

This commit is contained in:
Carlos Polop
2026-01-26 15:46:25 +01:00
parent 7ea6486f3f
commit 32e189ed82
4 changed files with 102 additions and 3 deletions

View File

@@ -133,4 +133,4 @@ jobs:
# Sync the build to S3 # Sync the build to S3
- name: Sync to S3 - name: Sync to S3
run: aws s3 sync ./book s3://hacktricks-cloud/en --delete run: aws s3 sync ./book s3://hacktricks-cloud/en --delete

View File

@@ -0,0 +1,99 @@
name: Invalidate CloudFront on Asset Changes
on:
push:
branches:
- master
paths:
- 'theme/**/*.css'
- 'theme/**/*.js'
- 'theme/**/*.hbs'
paths-ignore:
- '.github/**'
- 'book/**'
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
invalidate:
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Compute invalidation paths
id: paths
shell: bash
run: |
set -euo pipefail
BEFORE="${{ github.event.before }}"
AFTER="${{ github.sha }}"
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
if git rev-parse "${AFTER}^" >/dev/null 2>&1; then
BEFORE="${AFTER}^"
else
BEFORE=""
fi
fi
if [ -n "$BEFORE" ]; then
git diff --name-only "$BEFORE" "$AFTER" > /tmp/changed_files.txt
else
git ls-tree --name-only -r "$AFTER" > /tmp/changed_files.txt
fi
mapfile -t files < <(grep -E '^theme/.*\.(css|js|hbs)$' /tmp/changed_files.txt || true)
if [ ${#files[@]} -eq 0 ]; then
echo "paths=" >> "$GITHUB_OUTPUT"
exit 0
fi
invalidate_paths=()
hbs_changed=false
for f in "${files[@]}"; do
if [[ "$f" == theme/* ]]; then
rel="${f#theme/}"
if [[ "$f" == *.hbs ]]; then
hbs_changed=true
else
invalidate_paths+=("/$rel")
fi
fi
done
if [ "$hbs_changed" = true ]; then
invalidate_paths+=("/*")
fi
printf "%s\n" "${invalidate_paths[@]}" | awk 'NF' | sort -u > /tmp/invalidate_paths.txt
if [ ! -s /tmp/invalidate_paths.txt ]; then
echo "paths=" >> "$GITHUB_OUTPUT"
exit 0
fi
paths=$(paste -sd' ' /tmp/invalidate_paths.txt)
echo "paths=$paths" >> "$GITHUB_OUTPUT"
- name: Create CloudFront invalidation
if: steps.paths.outputs.paths != ''
run: |
aws cloudfront create-invalidation \
--distribution-id "${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}" \
--paths ${{ steps.paths.outputs.paths }}

View File

@@ -19,7 +19,7 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}" ENV PATH="/root/.cargo/bin:${PATH}"
# Install mdBook & plugins # Install mdBook & plugins
RUN cargo install mdbook RUN cargo install mdbook --version 0.5.2
RUN cargo install mdbook-alerts RUN cargo install mdbook-alerts
RUN cargo install mdbook-reading-time RUN cargo install mdbook-reading-time
RUN cargo install mdbook-pagetoc RUN cargo install mdbook-pagetoc
@@ -28,4 +28,3 @@ RUN cargo install mdbook-codename
# Set the working directory # Set the working directory
WORKDIR /app WORKDIR /app

View File

@@ -327,3 +327,4 @@ sup {
.result-no-output { .result-no-output {
font-style: italic; font-style: italic;
} }
/* Cache invalidation test: keep in sync with HackTricks */