From d2a11a5227a8ba490f6421ab75df81eb024c8259 Mon Sep 17 00:00:00 2001 From: Johann Frei Date: Mon, 12 Apr 2021 18:30:16 +0200 Subject: [PATCH] Add offline steps --- offline_01_download.sh | 69 ++++++++++++++++++++++++++++++++++++++++++ offline_02_extract.sh | 15 +++++++++ offline_03_import.sh | 12 ++++++++ 3 files changed, 96 insertions(+) create mode 100755 offline_01_download.sh create mode 100644 offline_02_extract.sh create mode 100644 offline_03_import.sh diff --git a/offline_01_download.sh b/offline_01_download.sh new file mode 100755 index 00000000..c47c6b16 --- /dev/null +++ b/offline_01_download.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $DIR +unset DIR + +# FOUND LINKS: +# app/server/templates/admin.html +# https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/vs2015.min.css + +# app/server/templates/base.html +# https://use.fontawesome.com/releases/v5.0.13/css/all.css +# https://fonts.googleapis.com/css?family=Open+Sans:300,400,700 +# https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css +# https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-divider/dist/css/bulma-divider.min.css +# https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-checkradio/dist/css/bulma-checkradio.min.css +# https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-tooltip/dist/css/bulma-tooltip.min.css + +# app/server/templates/index.html +# https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.3/css/swiper.min.css + +# https://source.unsplash.com/RWnpyGtY1aU +# https://source.unsplash.com/6Ticnhs1AG0 +# https://i.imgsafe.org/ba/baa924a5e3.png + +# frontend/nuxt.config.js +# https://use.fontawesome.com/releases/v5.0.6/js/all.js +# https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons + +n_columns="2" +declare -a links=("offline/vs2015.min.css" "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/vs2015.min.css" + "offline/all.css" "https://use.fontawesome.com/releases/v5.0.13/css/all.css" + "offline/opensans.css" "https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" + "offline/bulma.min.css" "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css" + "offline/bulma-divider.min.css" "https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-divider/dist/css/bulma-divider.min.css" + "offline/bulma-checkradio.min.css" "https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-checkradio/dist/css/bulma-checkradio.min.css" + "offline/bulma-tooltip.min.css" "https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-tooltip/dist/css/bulma-tooltip.min.css" + "offline/photo-1.jpg" "https://source.unsplash.com/RWnpyGtY1aU" + "offline/photo-2.jpg" "https://source.unsplash.com/6Ticnhs1AG0" + "offline/photo-3.jpg" "https://i.imgsafe.org/ba/baa924a5e3.png" + + "offline/all.js" "https://use.fontawesome.com/releases/v5.0.6/js/all.js" + "offline/google-roboto.css" "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons" + ) + +static_dir="app/server/static/" +mkdir -p "${static_dir}offline/" + +# root replace directories +app_dir="app/server/templates" +frontend_dir="frontend" + +for ((i = 0; i < "$(expr ${#links[@]} / $n_columns)"; ++i)); do + idx_local=$(expr $i \* $n_columns + 0) + idx_link=$(expr $i \* $n_columns + 1) + local="${links[$idx_local]}" + link="${links[$idx_link]}" + + echo "Storing file to $local: $link" + wget --content-on-error -q --show-progress -O "${static_dir}${local}" $link 2>/dev/null + if [ $? -eq 0 ]; then + # For Django: Use 'static' for template, use ^ as delimiter for sed + find $app_dir -type f -exec sed -i "s^${link}^{% static \'${local}\' %}^g" {} \; + # For Vue: Use // for same host, use ^ as delimiter for sed + find $frontend_dir -type f -exec sed -i "s^${link}^//static/${local}^g" {} \; + else + echo "Failed to transform for offline use: $link" + fi +done diff --git a/offline_02_extract.sh b/offline_02_extract.sh new file mode 100644 index 00000000..28553581 --- /dev/null +++ b/offline_02_extract.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $DIR +unset DIR + +sed -i 's^dockerfile: app/Dockerfile.prod^dockerfile: app/Dockerfile.prod\n image: doccano-app:custom^g' docker-compose.prod.yml +sed -i 's^dockerfile: nginx/Dockerfile^dockerfile: nginx/Dockerfile\n image: doccano-nginx:custom^g' docker-compose.prod.yml + +docker-compose -f docker-compose.prod.yml pull +docker-compose -f docker-compose.prod.yml build + +docker image save -o doccano-app.tar doccano-app:custom +docker image save -o doccano-nginx.tar doccano-nginx:custom +docker image save -o postgres.tar postgres:13.1-alpine diff --git a/offline_03_import.sh b/offline_03_import.sh new file mode 100644 index 00000000..fd3ac8e9 --- /dev/null +++ b/offline_03_import.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $DIR +unset DIR + +sed -i 's^dockerfile: app/Dockerfile.prod^dockerfile: app/Dockerfile.prod\n image: doccano-app:custom^g' docker-compose.prod.yml +sed -i 's^dockerfile: nginx/Dockerfile^dockerfile: nginx/Dockerfile\n image: doccano-nginx:custom^g' docker-compose.prod.yml + +docker image import doccano-app.tar doccano-app:custom +docker image import doccano-nginx.tar doccano-nginx:custom +docker image import postgres.tar postgres:13.1-alpine