GitLab 页面可以用于审查 mkdocs 项目中的应用程序吗? [英] Can GitLab pages be used for review apps on a mkdocs project?

查看:11
本文介绍了GitLab 页面可以用于审查 mkdocs 项目中的应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个答案 by @jokiprevious question 的建议是通过为可浏览的工件提供公共 URL,将 GitLab 存储库中的每个活动分支部署到动态环境.

This answer by @joki to a previous question suggests that it is possible to deploy each active branch in a GitLab repo to a dynamic environment, by giving browsable artifacts a public URL.

mkdocs 材料 项目尝试这个,我发现了两个问题.

Trying this out with a mkdocs material project, I've found two issues.

首先,如果 GitLab 存储库位于组或子组中,则 .gitlab-ci.yml 文件中的 URL 需要更像这样:

Firstly, if the GitLab repo is within a group or a subgroup the URLs in the .gitlab-ci.yml file needs to be something more like this:

    environment:
        name: review/$CI_COMMIT_REF_NAME
        url: "$CI_PAGES_URL/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
        auto_stop_in: 1 week
    variables:
        PUBLIC_URL: "$CI_PAGES_URL/-/jobs/$CI_JOB_ID/artifacts/public/"

其次,站点内的相关链接不能正常工作,导致大量 404 错误,以及样式文件等内容的丢失.可能上面的 URL 不正确,或者 mkdocs.yml 中的 site_url 需要更改为:

Secondly, relative links within the site don't work well, leading to a lot of 404 errors, and the loss of things like style files. Possibly the URLs above are not right, or maybe the site_url in mkdocs.yml needs changing to something like:

site_url: !!python/object/apply:os.getenv ["CI_ENVIRONMENT_URL"]

然而,这些都不适合我.

however, neither of these quite worked for me.

具有非常小的部署和审查应用程序的最小 MR 可以是 在这里找到.

A minimal MR with a very small deployment and review app can be found here.

有人有 mkdocs 审查应用的有效秘诀吗?

Does anyone have a working recipe for mkdocs review apps?

推荐答案

您可以在管道中 build 步骤的 »Browse« 按钮中看到您需要的 URL.

You can see the URL you need in the »Browse« button of the build step in your pipeline.

这行得通吗?

develop:
    artifacts:
        paths:
          - public

    environment:
        name: Develop
        url: "https://$CI_PROJECT_NAMESPACE.gitlab.io/-/snim2-test-subgroup/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"

    script: |
        # whatever

    stage: deploy

    variables:
        PUBLIC_URL: "/-/snim2-test-subgroup/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public"

您还需要将 mkdocs.yml 更改为实际 使用 PUBLIC_URL,并确保它在任何地方都使用绝对 内部链接 生成:

You'll also need your change to mkdocs.yml to actually use the PUBLIC_URL, and make sure it's used everywhere that absolute internal links are generated:

site_url: !!python/object/apply:os.getenv ["PUBLIC_URL"]
use_directory_urls: false
…

这篇关于GitLab 页面可以用于审查 mkdocs 项目中的应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆