Can GitLab pages be used for review apps on a mkdocs project?

风流意气都作罢 提交于 2020-04-10 04:44:12

问题


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.

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

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/"

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.

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

Does anyone have a working recipe for mkdocs review apps?


回答1:


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

Does this work?

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"

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
…


来源:https://stackoverflow.com/questions/60530676/can-gitlab-pages-be-used-for-review-apps-on-a-mkdocs-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!