Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,51 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Determine fetch plan
id: fetch-plan
env:
EVENT_NAME: ${{ github.event_name }}
BEFORE_SHA: ${{ github.event.before }}
CURRENT_SHA: ${{ github.sha }}
INPUT_FETCH_ARGUMENTS: ${{ inputs.fetch_arguments }}
run: |
set -o errexit -o nounset -o pipefail

fetch_arguments='--recent --attachments'
fetch_sync_codes='qm'
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
fetch_arguments="${INPUT_FETCH_ARGUMENTS:---recent --attachments}"
elif [[ "$EVENT_NAME" == "push" ]]; then
if git cat-file -e "${BEFORE_SHA}^{commit}" 2>/dev/null; then
changed_catalogs="$(
git diff --name-only "$BEFORE_SHA" "$CURRENT_SHA" -- \
':(glob)confluence-mdx/var/pages.*.yaml'
)"
else
changed_catalogs="$(
find confluence-mdx/var -maxdepth 1 -type f \
-name 'pages.*.yaml' -print
)"
fi

if [[ -n "$changed_catalogs" ]]; then
fetch_arguments='--remote --attachments'
fetch_sync_codes="$(
printf '%s\n' "$changed_catalogs" |
sed -E 's#^confluence-mdx/var/pages\.([a-z0-9_-]+)\.yaml$#\1#' |
sort -u |
paste -sd ' ' -
)"
fi
fi

echo "arguments=$fetch_arguments" >> "$GITHUB_OUTPUT"
echo "sync-codes=$fetch_sync_codes" >> "$GITHUB_OUTPUT"
echo "Fetch arguments: $fetch_arguments"
echo "Fetch sync codes: $fetch_sync_codes"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -55,7 +100,8 @@ jobs:
run: |
set -o errexit -o nounset -o pipefail -o xtrace
docker compose --progress=plain build \
--build-arg "FETCH_ARGS=${{ inputs.fetch_arguments || '--recent --attachments' }}"
--build-arg "FETCH_ARGS=${{ steps.fetch-plan.outputs.arguments }}" \
--build-arg "FETCH_SYNC_CODES=${{ steps.fetch-plan.outputs.sync-codes }}"

- name: Push Docker image
if: github.event_name != 'pull_request'
Expand All @@ -73,4 +119,3 @@ jobs:
DOCKERHUB_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_CREDENTIAL }}
run: python3 bin/dockerhub-cleanup.py

15 changes: 11 additions & 4 deletions confluence-mdx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY bin/ ./bin/
RUN chmod +x bin/*.py bin/*.sh
COPY etc/ ./etc/
COPY var/pages.*.yaml ./var/

# Restore cache at its expected path (for Stage 3 attachment fallback)
COPY cache/ ./cache/

# Populate var/ baseline from cache and fetch updates in one step.
# cp -a creates var/ with all cached YAML/content/attachment files,
# then fetch_cli.py downloads pages according to FETCH_ARGS.
# Default: --recent --attachments (incremental). Use --remote --attachments for full fetch.
# The tracked catalogs preserve Spaces that are not part of this fetch plan.
# cp -a adds all cached YAML/content/attachment files,
# then fetch_cli.py downloads each Space according to FETCH_ARGS.
# Defaults: qm with --recent --attachments (incremental).
# Use FETCH_SYNC_CODES="qm qcp" and --remote --attachments for multiple full fetches.
ARG FETCH_ARGS="--recent --attachments"
RUN cp -a cache/. var/ && python3 bin/fetch_cli.py ${FETCH_ARGS}
ARG FETCH_SYNC_CODES="qm"
RUN cp -a cache/. var/ && \
for sync_code in ${FETCH_SYNC_CODES}; do \
python3 bin/fetch_cli.py --sync-code "${sync_code}" ${FETCH_ARGS}; \
done

# ── Stage 2: Final image ────────────────────────────
FROM python:3.12-slim
Expand Down
1 change: 1 addition & 0 deletions confluence-mdx/bin/convert_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ def finalize_manifest(
sort_keys=False,
)
temp_path = Path(temp_file.name)
temp_path.chmod(0o644)
os.replace(temp_path, manifest_path)


Expand Down
1 change: 1 addition & 0 deletions confluence-mdx/tests/test_convert_all_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def test_manifest_removes_only_previous_owned_outputs(tmp_path):
assert manual.read_text() == "manual"
assert current.read_text() == "new"
assert yaml.safe_load(manifest_path.read_text())["outputs"] == current_outputs
assert manifest_path.stat().st_mode & 0o777 == 0o644


def test_manifest_preserves_stale_output_owned_by_another_profile(tmp_path):
Expand Down
1 change: 1 addition & 0 deletions confluence-mdx/var/pages.qcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading