diff options
| -rwxr-xr-x | docker/auto-backup/daemon.bash | 2 | ||||
| -rw-r--r-- | docker/crupest-blog/Dockerfile | 9 | ||||
| -rwxr-xr-x | docker/crupest-blog/daemon.bash | 17 | ||||
| -rwxr-xr-x | docker/crupest-blog/update.bash | 28 | ||||
| -rw-r--r-- | docker/crupest-nginx/Dockerfile | 8 | ||||
| -rw-r--r-- | template/docker-compose.yaml.template | 17 | ||||
| -rwxr-xr-x | tool/aio.py | 13 | 
7 files changed, 85 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 diff --git a/template/docker-compose.yaml.template b/template/docker-compose.yaml.template index 8f7c621..f3ae948 100644 --- a/template/docker-compose.yaml.template +++ b/template/docker-compose.yaml.template @@ -27,6 +27,19 @@ services:      networks:        - code-server-network +  crupest-blog: +    pull_policy: build +    build: +      context: ./docker/crupest-blog +      dockerfile: Dockerfile +      pull: true +      tags: +        - "crupest/crupest-blog:latest" +    container_name: crupest-blog +    restart: on-failure:3 +    volumes: +      - "blog:/blog" +    nginx:      pull_policy: build      build: @@ -45,6 +58,7 @@ services:        - "./nginx-config:/etc/nginx/conf.d:ro"        - "./data/certbot/certs:/etc/letsencrypt:ro"        - "./data/certbot/webroot:/srv/acme:ro" +      - "blog:/srv/blog:ro"      networks:        - timeline-network        - code-server-network @@ -148,3 +162,6 @@ networks:    code-server-network:    auto-certbot-network:    crupest-api-network: + +volumes: +  blog-public:
\ No newline at end of file diff --git a/tool/aio.py b/tool/aio.py index 3d44310..1033cb6 100755 --- a/tool/aio.py +++ b/tool/aio.py @@ -112,6 +112,9 @@ dns_parser.add_argument("-i", "--ip", help="IP address of the server.")  git_update_parser = subparsers.add_parser(      "git-update", help="Update git submodules.") +update_blog_parser = subparsers.add_parser( +    "update-blog", help="Update and regenerate blog.") +  up_parser = subparsers.add_parser(      "up", help="Do something necessary and then docker compose up.") @@ -164,6 +167,13 @@ def git_update():      run_in_project_dir(do_it) +def update_blog(): +    def do_it(): +        subprocess.run(["docker", "compose", "exec", +                       "crupest-blog", "/update.bash"], check=True) +    run_in_project_dir(do_it) + +  def docker_compose_up():      def do_docker_compose_up():          subprocess.run(["docker", "compose", "up", "-d"], check=True) @@ -282,6 +292,9 @@ def run():          case "git-update":              git_update() +        case "update-blog": +            update_blog() +          case "up":              git_update()              template_generate(console)  | 
