Skip to content

Commit

Permalink
Actually upload the generated sitemaps (and perform logging)
Browse files Browse the repository at this point in the history
  • Loading branch information
another-rex committed Jun 13, 2024
1 parent 46c25da commit ae44958
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- name: generate-sitemap-cron
image: cron
imagePullPolicy: Always
command: ["/usr/local/bin/generate_sitemap/generate_sitemap.py", "--base_url", "$BASE_URL"]
command: ["/usr/local/bin/generate_sitemap/generate_and_upload.sh"]
resources:
requests:
cpu: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ spec:
value: "https://test.osv.dev"
- name: GOOGLE_CLOUD_PROJECT
value: oss-vdb-test
- name: OUTPUT_GCS_BUCKET
value: test-osv-dev-sitemap
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ spec:
value: "https://osv.dev"
- name: GOOGLE_CLOUD_PROJECT
value: oss-vdb
- name: OUTPUT_GCS_BUCKET
value: osv-dev-sitemap
15 changes: 15 additions & 0 deletions docker/cron/generate_sitemap/generate_and_upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

SITEMAP_OUTPUT="sitemap_output/"
OUTPUT_BUCKET="${OUTPUT_GCS_BUCKET:=test-osv-dev-sitemap}"
BASE_URL_PATH="${BASE_URL:=https://test.osv.dev}"

echo "Begin sitemap generation for $BASE_URL_PATH"

./generate_sitemap.py --base_url $BASE_URL_PATH

echo "Begin Syncing with cloud to $OUTPUT_BUCKET"

gsutil -m rsync -c -d $SITEMAP_OUTPUT "gs://$OUTPUT_BUCKET/"
3 changes: 3 additions & 0 deletions docker/cron/generate_sitemap/generate_sitemap.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generate sitemap."""
import logging
import sys
import os
import osv
Expand Down Expand Up @@ -59,6 +60,7 @@ def get_sitemap_url_for_ecosystem(ecosystem: str, base_url: str) -> str:

def generate_sitemap_for_ecosystem(ecosystem: str, base_url: str) -> None:
"""Generate a sitemap for the give n ecosystem."""
logging.info("Generating sitemap for ecosystem '%s'.", ecosystem)
vulnerability_ids = fetch_vulnerability_ids(ecosystem)
filename = get_sitemap_filename_for_ecosystem(ecosystem)
urlset = Element(
Expand All @@ -79,6 +81,7 @@ def generate_sitemap_for_ecosystem(ecosystem: str, base_url: str) -> None:

def generate_sitemap_index(ecosystems: set[str], base_url: str) -> None:
"""Generate a sitemap index."""
logging.info("Generating sitemap index.")
sitemapindex = Element(
'sitemapindex', xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")

Expand Down

0 comments on commit ae44958

Please sign in to comment.