aboutsummaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-11-30 19:00:08 +0800
committercrupest <crupest@outlook.com>2022-11-30 19:00:08 +0800
commitc11b92992e6eebd91d6bbce26b2f407312d05a60 (patch)
tree4c2cad5c58d14dc22bd7af0a7ab6aaa1315e8ce5 /docker
parent3c918a6096e77190db83c998e777074493515326 (diff)
downloadcrupest-c11b92992e6eebd91d6bbce26b2f407312d05a60.tar.gz
crupest-c11b92992e6eebd91d6bbce26b2f407312d05a60.tar.bz2
crupest-c11b92992e6eebd91d6bbce26b2f407312d05a60.zip
A new way for blog.
Diffstat (limited to 'docker')
-rwxr-xr-xdocker/auto-backup/daemon.bash2
-rw-r--r--docker/crupest-blog/Dockerfile9
-rwxr-xr-xdocker/crupest-blog/daemon.bash17
-rwxr-xr-xdocker/crupest-blog/update.bash28
-rw-r--r--docker/crupest-nginx/Dockerfile8
5 files changed, 55 insertions, 9 deletions
diff --git a/docker/auto-backup/daemon.bash b/docker/auto-backup/daemon.bash
index e0c5edb..a4dd5dc 100755
--- a/docker/auto-backup/daemon.bash
+++ b/docker/auto-backup/daemon.bash
@@ -41,7 +41,7 @@ function backup {
echo "$destination" >> /data/backup.log
# echo "Backup finished!" in green and restore default
- echo -e "\e[0;102m\e[K\e[1mFinish backup!" "\e[0m"
+ echo -e "\e[0;102m\e[K\e[1mFinish backup!\e[0m"
}
echo "Initial delay: $CRUPEST_AUTO_BACKUP_INIT_DELAY"
diff --git a/docker/crupest-blog/Dockerfile b/docker/crupest-blog/Dockerfile
new file mode 100644
index 0000000..e2b27a5
--- /dev/null
+++ b/docker/crupest-blog/Dockerfile
@@ -0,0 +1,9 @@
+FROM klakegg/hugo:ext-alpine
+# install git
+ARG CRUPEST_BLOG_UPDATE_INTERVAL=1d
+RUN apk add --no-cache coreutils tini bash git
+ENV CRUPEST_BLOG_UPDATE_INTERVAL=${CRUPEST_BLOG_UPDATE_INTERVAL}
+COPY daemon.bash update.bash /
+VOLUME [ "/blog/public" ]
+ENTRYPOINT ["/sbin/tini", "--"]
+CMD [ "/daemon.bash" ]
diff --git a/docker/crupest-blog/daemon.bash b/docker/crupest-blog/daemon.bash
new file mode 100755
index 0000000..13966aa
--- /dev/null
+++ b/docker/crupest-blog/daemon.bash
@@ -0,0 +1,17 @@
+#! /usr/bin/env bash
+
+set -e
+
+# Check I'm root.
+if [[ $EUID -ne 0 ]]; then
+ echo "This script must be run as root" 1>&2
+ exit 1
+fi
+
+while true; do
+ /update.bash
+
+ # sleep for CRUPEST_AUTO_BACKUP_INTERVAL
+ echo "Sleep for $CRUPEST_BLOG_UPDATE_INTERVAL for next build..."
+ sleep "$CRUPEST_BLOG_UPDATE_INTERVAL"
+done
diff --git a/docker/crupest-blog/update.bash b/docker/crupest-blog/update.bash
new file mode 100755
index 0000000..f4ac51b
--- /dev/null
+++ b/docker/crupest-blog/update.bash
@@ -0,0 +1,28 @@
+#! /usr/bin/env bash
+
+set -e
+
+echo -e "\e[0;103m\e[K\e[1mBegin to build blog...\e[0m"
+echo "Begin time: $(date +%Y-%m-%dT%H:%M:%SZ)"
+
+# check /blog directory exists
+if [[ ! -d /blog ]]; then
+ echo "Directory /blog not found, clone blog repository..."
+ git clone https://github.com/crupest/blog.git /blog
+ cd /blog
+ git submodule update --init --recursive
+else
+ echo "Directory /blog founded, update blog repository..."
+ cd /blog
+ git fetch -p
+ git reset --hard origin/master
+ git submodule update --init --recursive
+fi
+
+# Now hugo it
+echo "Run hugo to generate blog..."
+hugo
+
+echo "Finish time: $(date +%Y-%m-%dT%H:%M:%SZ)"
+echo -e "\e[0;102m\e[K\e[1mFinish build!\e[0m"
+
diff --git a/docker/crupest-nginx/Dockerfile b/docker/crupest-nginx/Dockerfile
index 046031b..58a188c 100644
--- a/docker/crupest-nginx/Dockerfile
+++ b/docker/crupest-nginx/Dockerfile
@@ -4,14 +4,6 @@ COPY sites/www /sites/www
WORKDIR /sites/www
RUN pnpm install --frozen-lockfile && pnpm run build
-FROM klakegg/hugo:ext-alpine AS build-blog
-# install git
-RUN apk add --no-cache git
-WORKDIR /
-RUN git clone https://github.com/crupest/blog.git && cd blog && git submodule update --init --recursive
-WORKDIR /blog
-RUN hugo
-
FROM nginx:mainline-alpine
COPY --from=build-www /sites/www/dist /srv/www
COPY --from=build-blog /blog/public /srv/blog