使用gitlab的CI/CD实现logseq笔记自动发布为单页应用

使用gitlab的CI/CD实现logseq笔记自动发布为单页应用

使用gitlab的CI/CD实现logseq笔记自动发布为单页应用

如何实现将logseq的笔记发布成网站

Logseq 是一个侧重于隐私的知识管理和协作的平台。可以实现笔记的完全本地化存储。并且可以基于Git实现多人协作。logseq官网的帮助网站,内容看起来是logseq编写的,并且实现了网站的发布。本文将介绍如何实现logseq笔记的网站发布。

使用 logseq-publish-docker 实现手动发布

logseq-publish-docker这个docker镜像,可以实现将logseq图谱发布成单页应用Single Page Application (SPA),灵感来自官方解决方案Logseq发布spa。可以在支持docker的服务器上将Logseq图谱发布成单页应用,无需配置开发环境。

1、在转换前要将logseq图谱中的笔记设置为发布状态

2、拉取镜像

shell 复制代码
$ docker pull ghcr.io/l-trump/logseq-publish-spa:latest

3、使用镜像将logseq知识图谱转换为单页应用

shell 复制代码
$ docker run -v ./graph:/graph:ro -v ./out:/out \
    -e PUB_THEME=light -it ghcr.io/l-trump/logseq-publish-spa:latest
  • "./graph" 是logseq图谱的位置
  • "./out" 是转换完的单页应用的存储位置

这是我自己测试时的指令

shell 复制代码
$ docker run -v /home/root/logseq-test-graph:/graph:ro -v /home/root/out:/out \ 
	-e PUB_THEME=light -it ghcr.io/l-trump/logseq-publish-spa:latest

4、使用nginx发布,".out" 目录下的文件

使用gitlab的CI/CD实现自动发布

为了保证图谱的隐私性,选择使用本地部署的gitlab来实现logseq图谱的多人协作,同时实现自动的发布。

1、配置logseq图谱的gitlab远程仓库

2、编写自动发布的".gitlab-ci.yml" 文件

yml 复制代码
image:
  name: ghcr.io/l-trump/logseq-publish-spa:latest
  entrypoint: ["/bin/sh", "-c", "ln -snf /bin/bash /bin/sh && /bin/bash -c $0" ]

stages:
  - deploy

pages:
  only:
    - master

  stage: deploy
  environment: live

  variables:
    THEME: light
    ACCENT_COLOR: blue

  script:
    - pwd
    - mkdir -p public
    - node /opt/logseq-publish-spa/publish_spa.mjs $CI_PROJECT_DIR/public --static-directory /opt/logseq-static --directory $CI_PROJECT_DIR --theme-mode $THEME --accent-color $ACCENT_COLOR

  artifacts:
    paths:
      - public

3、注册项目的gitlab-runner

shell 复制代码
# 执行注册指令
$ gitlab-runner register
Please enter the gitlab-ci coordinator URL:
# 第一个参数输入 settings -> CI/CD -> Runners settings -> Setup a specific Runner manually 中的 第二个参数
Please enter the gitlab-ci token for this runner:
# 第二个参数输入 settings -> CI/CD -> Runners settings -> Setup a specific Runner manually 中的 第三个参数
Please enter the gitlab-ci description for this runner:
# 第三个参数输入执行器的名称
Please enter the gitlab-ci tags for this runner:
# 第四个参数输入执行器的标签
Whether to run untagged builds [true/false]:
# 第五个参数,是否执行无标签的构建选择 true
Whether to lock Runner to current project[true/false]:
# 第六个参数,是锁定执行器到当前项目选择 true
Please enter the executor:docker,docker-ssh,parallels,shell,viritualbox,docker+machine,kubernetes,ssh,docker-ssh+machine:
# 第七个参数,输入执行器,输入 docker
Please enter the default Docker image
# 第八个参数,输入默认docker镜像,输入ghcr.io/l-trump/logseq-publish-spa:latest

注册成功后,会在 /etc/gitlab-runner/config.toml 文件中会增加一个执行器

注册成功后,在gitlab中会显示刚注册的执行器

logseq图谱提交到gitlab中就可以触发自动构建实现logseq图谱的自动发布

过程中的问题及解决

  • 1、由于gitlab服务器在内网,无法拉取 logseq-publish-spa 镜像,即使开通外网访问权限也无法拉取镜像报Error response from daemon: manifest for ghcr.io/l-trump/logseq-publish-spa: 错误。

    解决方法:使用Nexus构建本地docker Image 镜像仓库,将"logseq-publish-spa" 镜像下载后推送至本地的Nexus docker Image 镜像仓库中。".gitlab-ci.yml" 文件中使用本地镜像。

  • 2、在执行自动发布的时报 "sh: 1: set: Illegal option -o pipefail"错误

    解决方法:在 ".gitlab-ci.yml"文件中的 entrypoint 中增加 "ln -snf /bin/bash /bin/sh && /bin/bash -c $0" 参数,改为最终的形式, entrypoint: ["/bin/sh", "-c", "ln -snf /bin/bash /bin/sh && /bin/bash -c $0" ]

参考资料

官方发布项目
https://github.com/L-Trump/logseq-publish-docker - Docker image of this repository. This repository can be used with GitLab.
logseq-publish-docker
Gitlab-Runner注册

相关推荐
陌殇殇殇6 小时前
使用GitLab CI构建持续集成案例
运维·ci/cd·云原生·容器·kubernetes·gitlab
吕玉生6 小时前
基于GitLab 的持续集成环境
ci/cd·gitlab
henan程序媛1 天前
jenkins项目发布基础
运维·gitlab·ansible·jenkins
极小狐3 天前
极狐GitLab 签约比博斯特,助力新能源智能底盘企业研发提效
gitlab·devsecops·devops·极狐gitlab·安全合规
YoungHong19923 天前
Gitlab服务搭建相关
gitlab
sj11637394034 天前
docker-compose安装gitlab
docker·容器·gitlab
Matrix705 天前
GIT安装及集成到IDEA中操作步骤
java·git·spark·gitlab·intellij-idea
ulimpid7 天前
Git | Dockerized GitLab 安装使用(简单实操版)
学习·docker·gitlab
hrlees7 天前
从零开始Ubuntu24.04上Docker构建自动化部署(四)Docker安装gitlab
docker·自动化·gitlab
C+ 安口木7 天前
在 Gitlab 中使用 ChatGPT 进行 CodeReview
chatgpt·gitlab·代码复审