From 9f2e5fbbe49c90b0e956b6b7e034272a7eefaaf9 Mon Sep 17 00:00:00 2001 From: Karl Stoney Date: Sat, 5 Jan 2019 23:30:23 +0000 Subject: [PATCH] Improvements to script to generate all image sizes --- Dockerfile | 6 +++++- bin/generate_static_content.sh | 38 ++++++++++++++++++++++++++++++++-- docker-compose.yml | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9c49ee7..a00bb39 100755 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,13 @@ FROM centos:7 MAINTAINER Karl Stoney # Get dependencies -RUN yum -y -q install which curl wget gettext patch gcc-c++ make git-core bzip2 unzip && \ +RUN yum -y -q install which curl wget gettext patch gcc-c++ make git-core bzip2 unzip gcc python-devel python-setuptools redhat-rpm-config && \ yum -y -q clean all +# Install crcmod +RUN easy_install -U pip && \ + pip install -U crcmod + # Get nodejs repos RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - diff --git a/bin/generate_static_content.sh b/bin/generate_static_content.sh index 0ec193b..c799cd4 100755 --- a/bin/generate_static_content.sh +++ b/bin/generate_static_content.sh @@ -1,11 +1,45 @@ #!/bin/bash +set -e cd /static rm -rf * mkdir content -cp -R $GHOST_HOME/current/content/images content/ echo "Running gssg..." gssg --domain "http://127.0.0.1" --dest . --url "https://$GHOST_DOMAIN" + +echo "Download all sizes of images" +cd /static/content/images +sizes=( "w600" "w1000" "w2000" ) + +function getImage() { + file=$1 + for size in "${sizes[@]}"; do + targetFile="/static/content/images/size/$size/$file" + path=$(dirname $targetFile) + mkdir -p $path + if [ ! -f $targetFile ]; then + echo "Getting: $targetFile" + curl -f --silent -o $targetFile http://127.0.0.1/content/images/size/$size/$file + else + echo "Skipping: $targetFile" + fi + done +} + +echo "Downloading images that have already been sized" +cd /static/content/images +for file in $(find size -type f -o -name "*.png"); do + source=$(echo $file | sed 's,^[^/]*/,,' | sed 's,^[^/]*/,,') + getImage $source +done + +echo "Downloading images that have not already been sized" +for file in $(find . -path ./size -prune -type f -o -name "*.png"); do + source=$(echo $file | sed 's,^[^/]*/,,') + getImage $source +done + echo "Static content generated!" echo "Uploading to gcs..." -gsutil -m rsync -R . gs://$GHOST_DOMAIN +cd /static +gsutil -m rsync -d -c -R . gs://$GHOST_DOMAIN diff --git a/docker-compose.yml b/docker-compose.yml index 9bfe23f..81a9eca 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: args: GCLOUD_VERSION: 227.0.0 GHOST_VERSION: 2.9.1 - SITEMAP_GENERATOR_VERSION: 0.0.15 + SITEMAP_GENERATOR_VERSION: 0.1.0-1 restart: always environment: NODE_ENV: production