美文网首页程序员
Windows环境下编译Flink文档

Windows环境下编译Flink文档

作者: 小胡子哥灬 | 来源:发表于2020-10-10 14:26 被阅读0次

环境准备

  1. 安装Docker for Windows

    安装方法可以参考Docker官方文档,跟着文档一步一步走应该没什么问题的,我的是win10 家庭版的

  2. 安装Cygwin

    直接到官网下载安装即可:cygwin

  3. 下载flink源码

    git clone https://github.com/shizhengchao/flink.git,因为我fork到我自己的仓库,所以用的是我自己的地址,以便后面为社区做贡献

开始编译

  1. 打开Cygwin,进到flink/docs目录下执行 ./docker/run.sh命令

    $ ./docker/run.sh
    
  2. 如果上面的命令执行成功,那么应该是进入到了docker容器内部,在容器内部找到对应的flink目录,执行build_docs.sh脚本

    $ ./build_docs.sh -p
    
  3. 如果以上步骤都没有问题,那么会出现如下信息:

    -------------------------------------------------------------------------------------
    Configuration file: /opt/flink/_config.yml
                Source: /opt/flink
           Destination: /opt/flink/content
     Incremental build: disabled. Enable with --incremental
          Generating...
                        done in 106.278 seconds.
     Auto-regeneration: enabled for '/opt/flink'
        Server address: http://0.0.0.0:4000/
      Server running... press ctrl-c to stop.
    

    浏览器中输入:localhost:4000,就可以看到编译后的文档了,可以切换中英文。

问题汇总

基本上在windows环境下,按照上面的操作是成功不了的,以下是我遇到的几个问题:

  1. $'\r': command not found
    cygwin中输入 cd; pwd

    cd; pwd
    

    然后编辑.bash_profile,在末尾加上如下内容,重启cygwin

    export SHELLOPTS
    set -o igncr
    
  2. windows用户名是数字引发的问题

    groupadd: '0229' is not a valid group name
    

    导致这个问题的原因是我的windows用户是数字(公司的电脑,用户是工号),在run.sh中把 username改成英文名就行了,随便一个,我的是shizc, 在run.sh改成如下内容:

    if [ "$(uname -s)" == "Linux" ]; then
      USER_NAME=${SUDO_USER:=$USER}
      USER_ID=$(id -u "${USER_NAME}")
      GROUP_ID=$(id -g "${USER_NAME}")
    else # boot2docker uid and gid
      USER_NAME='shizc'
      USER_ID=$(id -u)
      GROUP_ID=$(id -g)
    fi
    
  3. cgywin中的磁盘目录挂载不了到docker容器中,报如下错误:

    the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'
    

    这个问题,网上给出的方案是在docker前面加上 winpty的命令,但是在我这不生效,识别不了winpty命令。在执行run.sh的时候,如果没有成功,会打印出执行的脚本语句:

    docker run -it --rm=true -w /cygdrive/d/java/flink/flink/docs/docker/.. -u shizc -v /cygdrive/d/java/flink/flink/docs/docker/..:/cygdrive/d/java/flink/flink/docs/docker/.. -p 4000:4000 flink/docs-shizc bash -c '
    echo
    echo '\''Welcome to Apache Flink docs'\''
    echo '\''To build, execute'\''
    echo '\''  ./build_docs.sh'\''
    echo '\''To watch and regenerate automatically'\''
    echo '\''  ./build_docs.sh -p'\''
    echo '\''and access http://localhost:4000'\''
    echo
    bash
    '
    the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'
    

    如上。把docker run 那段内容拷贝到powershell里执行, 并且修改成windows的目录格式 ,如下:

    docker run -it --rm=true -w /opt/flink/docs/docker/.. -u shizc -v d:/java/flink/flink/docs/docker/..:/opt/flink/docs/docker/.. -p 4000:4000 flink/docs-shizc bash
    

    如果报the working directory 'xxx is invalid, 则可以把-w xxxx,这段内容去掉,也就是不指定工作目录,也是可以的。

  4. 在powershell里执行后,会进入docker容器,然后在容器中运行 build_docs.sh脚本,如下:

    [shizc@5a9b5474c0b3 docs]$ ./build_docs.sh -p
    

    不出意外,第一次执行的话会报:No such file or directory,这个是因为脚本不是unix格式:

    首先用vim打开 build_docs.sh文件,然后 shift + :打开命令模式,输入 set ff , 回车,出现如下信息

    fileformat=dos
    

    可以看到 fileformat是dos格式,再次进入命令模式输入: set ff=unix,保存并退出vim ,再次执行build_docs.sh脚本。如果出现如下信息,则编译成功:

    Bundle complete! 9 Gemfile dependencies, 39 gems now installed.
    Bundled gems are installed into `./.rubydeps`
    Configuration file: /opt/flink/docs/_config.yml
                Source: /opt/flink/docs
           Destination: /opt/flink/docs/content
     Incremental build: disabled. Enable with --incremental
          Generating...
                        done in 109.813 seconds.
     Auto-regeneration: enabled for '/opt/flink/docs'
        Server address: http://0.0.0.0:4000/
      Server running... press ctrl-c to stop.
    

恭喜你已经完成了将为社区做贡献的第一步,打开浏览器,输入localhost:4000,看下哪些文档还没被翻译成中文的,赶紧到flink官方jira上提issue, 然后开始你的第一个 pr。

相关文章

网友评论

    本文标题:Windows环境下编译Flink文档

    本文链接:https://www.haomeiwen.com/subject/vtbdpktx.html