打造任何地方都能使用的markdown写作软件:Typora云端化

打造任何地方都能使用的MARKDOWN写作软件:TYPORA云端化

新媒体平台众多,每个平台都要修改自己的代码,实在太麻烦了。markdown是目前我发现最好用写作软件,但是我不能随时带着电脑满世界跑吧,有没有云端化的Typora呢?

v2-b56f582d4203e2e016a36130c5237db0_1440wt

官方暂时还没有,那我们就自己来打造一个云端化写作利器:typora

我们使用基于Linux系统桌面环境+easy-no-vnc+caddy 数据转发的形式构建,需要安装的软件有:easy-novnc, openbox, tigervnc, supervisor, typora, caddyserver

为避免对宿主机产生影响,我们使用docker容器部署我们的云端化方案,确保宿主机安装了docker服务。

创建目录

在宿主机上创建所需目录:

mkdir ~/typora
mkdir ~/caddy 

两个文件夹分别用于typora软件、caddyserver软件的docker环境的构建,typora环境提供typora的运行环境,包括vnc、novnc、openbox、typora等;caddyserver负责运行一个http server,实现对http请求转发到novnc,通过对文件目录提供http、webdav两种协议的访问,这样写作的markdown文本可以通过这两种协议同步到本地。

整体文件结构如下:

.
├── caddy
│   ├── Caddyfile
│   └── Dockerfile
└── typora
    ├── Dockerfile
    ├── menu.xml
    └── supervisord.conf

2 directories, 5 files
创建文件
nano ~/caddy/Caddyfile

新增内容如下:

{
    order webdav last
}
:8081 {
    log
    root * /data
    reverse_proxy typora-app:8080

    handle_path /files/* {
        file_server browse
    }
    redir /files /files/

    handle /webdav/* {
        webdav {
            prefix /webdav
        }
    }
    redir /webdav /webdav/

    basicauth /* {
        {env.APP_USERNAME} {env.APP_PASSWORD_HASH}
    }
}

Caddyfile是caddyserver运行的配置文件,以上内容定义server的端口,代理转发,webdav,访问控制的用户信息等。

接着,新建Dockerfile:

nano ~/caddy/Dockerfile

Dockerfile内容如下:

FROM golang:1.14-buster AS caddy-build
WORKDIR /src
RUN echo 'module caddy' > go.mod && \
    echo 'require github.com/caddyserver/caddy/v2 v2.1.1' >> go.mod && \
    echo 'require github.com/mholt/caddy-webdav v0.0.0-20200523051447-bc5d19941ac3' >> go.mod
RUN echo 'package main' > caddy.go && \
    echo 'import caddycmd "github.com/caddyserver/caddy/v2/cmd"' >> caddy.go && \
    echo 'import _ "github.com/caddyserver/caddy/v2/modules/standard"' >> caddy.go && \
    echo 'import _ "github.com/mholt/caddy-webdav"' >> caddy.go && \
    echo 'func main() { caddycmd.Main() }' >> caddy.go
RUN go env -w GOPROXY=https://goproxy.cn && \
    go build -o /bin/caddy .

FROM debian:buster

RUN echo "deb http://mirrors.aliyun.com/debian buster main contrib non-free" > /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian buster main contrib non-free" >> /etc/apt/sources.list  && \
    echo "deb http://mirrors.aliyun.com/debian buster-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian buster-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list.

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends gosu && \
    rm -rf /var/lib/apt/lists

COPY --from=caddy-build /bin/caddy /usr/local/bin/
COPY Caddyfile /etc/
EXPOSE 8081

RUN groupadd --gid 1000 app && \
    useradd --home-dir /data --shell /bin/bash --uid 1000 --gid 1000 app && \
    mkdir -p /data
VOLUME /data

WORKDIR /data
CMD ["sh", "-c", "chown app:app /data && exec gosu app /usr/local/bin/caddy run -adapter caddyfile -config /etc/Caddyfile"]

caddyserver的配置完成后,进入到typora目录配置。

新增Dockerfile文件:

nano ~/typora/Dockerfile

内容如下:

FROM golang:1.14-buster AS easy-novnc-build
WORKDIR /src
RUN go env -w GOPROXY=https://goproxy.cn && \
    go mod init build && \
    go get github.com/geek1011/easy-novnc@v1.1.0 && \
    go build -o /bin/easy-novnc github.com/geek1011/easy-novnc

FROM debian:buster

RUN echo "deb http://mirrors.aliyun.com/debian buster main contrib non-free" > /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian buster main contrib non-free" >> /etc/apt/sources.list  && \
    echo "deb http://mirrors.aliyun.com/debian buster-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian buster-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list.

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends openbox tigervnc-standalone-server supervisor gosu && \
    rm -rf /var/lib/apt/lists && \
    mkdir -p /usr/share/desktop-directories

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends lxterminal nano wget openssh-client rsync ca-certificates xdg-utils htop tar xzip gzip bzip2 zip unzip && \
    rm -rf /var/lib/apt/lists

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends gnupg2 libasound2-dev libxss1 libgbm-dev \
    libxext-dev libxrender-dev libxtst-dev libnss3-dev software-properties-common && \
    rm -rf /var/lib/apt/lists

RUN wget -qO - https://typoraio.cn/linux/public-key.asc | apt-key add - && \
    add-apt-repository 'deb https://typoraio.cn/linux ./' && \
    apt-get update -y && \
    apt-get install -y --no-install-recommends typora && \
    rm -rf /var/lib/apt/lists
    
COPY --from=easy-novnc-build /bin/easy-novnc /usr/local/bin/
COPY menu.xml /etc/xdg/openbox/
COPY supervisord.conf /etc/
EXPOSE 8080

RUN groupadd --gid 1000 app && \
    useradd --home-dir /data --shell /bin/bash --uid 1000 --gid 1000 app && \
    mkdir -p /data
VOLUME /data

CMD ["sh", "-c", "chown app:app /data /dev/stdout && exec gosu app supervisord"]

新增menu.xml

nano ~/typora/menu.xml

vnc环境没有菜单栏,toolbar之类,通过openbox提供一个右键菜单,来启动terminal等:

<?xml version="1.0" encoding="utf-8"?>
<openbox_menu xmlns="http://openbox.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://openbox.org/ file:///usr/share/openbox/menu.xsd">
    <menu id="root-menu" label="Openbox 3">
        <item label="Typora">
            <action name="Execute">
                <execute>/usr/bin/typora --no-sandbox</execute>
            </action>
        </item>
        <item label="Terminal">
            <action name="Execute">
                <execute>/usr/bin/x-terminal-emulator</execute>
            </action>
        </item>
        <item label="Htop">
            <action name="Execute">
                <execute>/usr/bin/x-terminal-emulator -e htop</execute>
            </action>
        </item>
    </menu>
</openbox_menu>

接下来新增supervisord文件:

nano ~/typora/supervisord.conf

supervisord用于维护每一个软件的运行和守护,文件内容:

[supervisord]
nodaemon=true
pidfile=/tmp/supervisord.pid
logfile=/dev/fd/1
logfile_maxbytes=0

[program:x11]
priority=0
command=/usr/bin/Xtigervnc -desktop "Typora" -localhost -rfbport 5900 -SecurityTypes None -AlwaysShared -AcceptKeyEvents -AcceptPointerEvents -AcceptSetDesktopSize -SendCutText -AcceptCutText :0
autorestart=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:easy-novnc]
priority=0
command=/usr/local/bin/easy-novnc --addr :8080 --host localhost --port 5900 --no-url-password --novnc-params "resize=remote"
autorestart=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:openbox]
priority=1
command=/usr/bin/openbox
environment=DISPLAY=:0
autorestart=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:app]
priority=1
environment=DISPLAY=:0
command=/usr/bin/typora --no-sandbox
autorestart=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
构建docker image

以上所有文件配置完后,现在开始构建 docker image和启动等工作。

先进入typora的目录:

cd ~/typora
docker build -t  typora .

创建网络和volume:

docker network create typora-net
docker volume create typora-data

运行typora这个docker container:

docker run --detach --restart=always --volume=typora-data:/data --net=typora-net --name=typora-app typora

最后构建caddyserver,进入到caddy目录下:

cd ~/caddy
docker build -t  typora-caddy .

为caddyserver的用户信息配置获取一个密码:

docker run --rm -it typora-caddy caddy hash-password -plaintext 'your-password'

将your-password替换为你要设置的密码,将执行晚你所看到的字符串复制下来。

运行docker container:

docker run --detach --restart=always --volume=typora-data:/data \
    --net=typora-net --name=typora-web --env=APP_USERNAME="your-username" \
    --env=APP_PASSWORD_HASH="your-password-hash" \
    --publish=8081:8081 typora-caddy

以上命令中将your-username替换为你要使用的用户名,将your-password-hash替换为你刚刚复制下来的字符串。

以上完成了所有工作,可以查看以下docker运行的情况:

docker ps

v2-726d65dd0b7bda4bf48274cc391b58aa_r

浏览器访问:http://localhost:8081,输入用户名和密码即可登录写作啦!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值