使用带有 gitlab 页面的 jekyll,它说当它使用 gitlab CI 部署网站时找不到主题,我已经安装了它

Posted

技术标签:

【中文标题】使用带有 gitlab 页面的 jekyll,它说当它使用 gitlab CI 部署网站时找不到主题,我已经安装了它【英文标题】:Using jekyll with gitlab pages, it says when it's deploying the website with gitlab CI that theme could not be found, and I already installed it 【发布时间】:2020-02-12 15:44:13 【问题描述】:

我的目标

要有一个包含 jekyll 站点配置文件(但不是 _site)的存储库,并且每次我推送到存储库时,都会运行一个 gitlab 管道。通过该管道,该站点是使用 Jekyll 构建的(我正在使用这个主题 https://github.com/mmistakes/jekyll-theme-basically-basic)

快速查看我遇到的重要文件

宝石文件

source "https://rubygems.org"
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
#     bundle exec jekyll serve
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
gem "jekyll", "~> 4.0.0"
# This is the default theme for new Jekyll sites. You may change this to anything you like.

#######
#THEMES
#######

# MANUALLY COMMENTED
#gem "minima", "~> 2.5"
# New content by me
#gem "jekyll-theme-basically-basic"
#gem 'jekyll-theme-basically-basic', '~> 1.4', '>= 1.4.4'

########################



# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
# If you have any plugins, put them here!
group :jekyll_plugins do
  gem "jekyll-feed", "~> 0.12"
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
install_if ->  RUBY_PLATFORM =~ %r!mingw|mswin|java!  do
  # gem "tzinfo", "~> 1.2"
  # gem "tzinfo-data"
end

# Performance-booster for watching directories on Windows
# gem "wdm", "~> 0.1.1", :install_if => Gem.win_platform?

也许你想知道为什么有这么多的 cmets。那是因为我在 gitlab 中部署时遇到了问题,我发现如果我将它们安装在 .gitlab-ci.yml 中,我就不会遇到这些问题。

_config.yml

# Welcome to Jekyll!
#
# This config file is meant for settings that affect your whole blog, values
# which you are expected to set up once and rarely edit after that. If you find
# yourself editing this file very often, consider using Jekyll's data files
# feature for the data you need to update frequently.
#
# For technical reasons, this file is *NOT* reloaded automatically when you use
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.
#
# If you need help with YAML syntax, here are some quick references for you: 
# https://learn-the-web.algonquindesign.ca/topics/markdown-yaml-cheat-sheet/#yaml
# https://learnxinyminutes.com/docs/yaml/
#
# Site settings
# These are used to personalize your new site. If you look in the html files,
# you will see them accessed via  site.title ,  site.email , and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via  site.myvariable .

lang: es-ES
title: La casa de los titanes
email: adristudy@gmail.com
description: >- # this means to ignore newlines until "baseurl:"
  Write an awesome description for your new site here. You can edit this
  line in _config.yml. It will appear in your document head meta (for
  Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
author:
  name: Adrián Jaramillo
twitter_username: sample
github_username: sample

# Build settings
theme: jekyll-theme-basically-basic
#theme: minima
plugins:
  - jekyll-feed

# Exclude from processing.
# The following items will not be processed, by default.
# Any item listed under the `exclude:` key here will be automatically added to
# the internal "default list".
#
# Excluded items can be processed by explicitly listing the directories or
# their entries' file path in the `include:` list.
#
# exclude:
#   - .sass-cache/
#   - .jekyll-cache/
#   - gemfiles/
#   - Gemfile
#   - Gemfile.lock
#   - node_modules/
#   - vendor/bundle/
#   - vendor/cache/
#   - vendor/gems/
#   - vendor/ruby/

# New content by me 
# theme: jekyll-theme-basically-basic

.gitlab-ci.yml

image: ruby:2.5

pages:
  script:
  - gem install jekyll
  #- gem install minima
  - gem install jekyll-theme-basically-basic -v 1.4.1
  - gem install tzinfo -v 1.2.2
  - gem install tzinfo-data
  - bundle install
  - jekyll build --trace -d public/
  artifacts:
    paths:
    - public
  only:
  - master

此外,这里还有公共存储库

https://gitlab.com/unveiled_adri/jekyll_project

当然还有在gitlab的docker vm上部署的全过程,显示错误

Running with gitlab-runner 12.3.0 (a8a019e0)
  on docker-auto-scale ed2dce3a
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:092689b795107d1b2eadb82494acf4764191baa0aa5bf4673b8ee2a50f70ba97 for ruby:2.5 ...
Running on runner-ed2dce3a-project-14628881-concurrent-0 via runner-ed2dce3a-srm-1571178048-5f8825dc...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/unveiled_adri/jekyll_project/.git/
Created fresh repository.
From https://gitlab.com/unveiled_adri/jekyll_project
 * [new ref]         refs/pipelines/89060084 -> refs/pipelines/89060084
 * [new branch]      master                  -> origin/master
Checking out 745d8811 as master...

Skipping Git submodules setup
$ gem install jekyll
Successfully installed public_suffix-4.0.1
Successfully installed addressable-2.7.0
Successfully installed colorator-1.1.0
Building native extensions. This could take a while...
Successfully installed http_parser.rb-0.6.0
Building native extensions. This could take a while...
Successfully installed eventmachine-1.2.7
Successfully installed em-websocket-0.5.1
Successfully installed concurrent-ruby-1.1.5

HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.

Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.

For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0

Successfully installed i18n-1.7.0
Building native extensions. This could take a while...
Successfully installed ffi-1.11.1
Building native extensions. This could take a while...
Successfully installed sassc-2.2.1
Successfully installed jekyll-sass-converter-2.0.1
Successfully installed rb-fsevent-0.10.3
Successfully installed rb-inotify-0.10.0
Successfully installed listen-3.2.0
Successfully installed jekyll-watch-2.2.1
Successfully installed kramdown-2.1.0
Successfully installed kramdown-parser-gfm-1.1.0
Successfully installed liquid-4.0.3
Successfully installed mercenary-0.3.6
Successfully installed forwardable-extended-2.6.0
Successfully installed pathutil-0.16.2
Successfully installed rouge-3.12.0
Successfully installed safe_yaml-1.0.5
Successfully installed unicode-display_width-1.6.0
Successfully installed terminal-table-1.8.0
-------------------------------------------------------------------------------------
Jekyll 4.0 comes with some major changes, notably:

  * Our `link` tag now comes with the `relative_url` filter incorporated into it.
    You should no longer prepend ` site.baseurl ` to `% link foo.md %`
    For further details: https://github.com/jekyll/jekyll/pull/6727

  * Our `post_url` tag now comes with the `relative_url` filter incorporated into it.
    You shouldn't prepend ` site.baseurl ` to `% post_url 2019-03-27-hello %`
    For further details: https://github.com/jekyll/jekyll/pull/7589

  * Support for deprecated configuration options has been removed. We will no longer
    output a warning and gracefully assign their values to the newer counterparts
    internally.
-------------------------------------------------------------------------------------
Successfully installed jekyll-4.0.0
26 gems installed
$ gem install jekyll-theme-basically-basic -v 1.4.1
Successfully installed i18n-0.9.5
Successfully installed sass-listen-4.0.0

Ruby Sass has reached end-of-life and should no longer be used.

* If you use Sass as a command-line tool, we recommend using Dart Sass, the new
  primary implementation: https://sass-lang.com/install

* If you use Sass as a plug-in for a Ruby web framework, we recommend using the
  sassc gem: https://github.com/sass/sassc-ruby#readme

* For more details, please refer to the Sass blog:
  https://sass-lang.com/blog/posts/7828841

Successfully installed sass-3.7.4
Successfully installed jekyll-sass-converter-1.5.2
Successfully installed kramdown-1.17.0
Successfully installed jekyll-3.8.6
Successfully installed jekyll-sitemap-1.3.1
Successfully installed jekyll-seo-tag-2.6.1
Successfully installed jekyll-paginate-1.1.0
Successfully installed jekyll-feed-0.12.1
Successfully installed jekyll-theme-basically-basic-1.4.1
11 gems installed
$ gem install tzinfo -v 1.2.2
Successfully installed thread_safe-0.3.6
Successfully installed tzinfo-1.2.2
2 gems installed
$ gem install tzinfo-data
Successfully installed tzinfo-data-1.2019.3
1 gem installed
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using public_suffix 4.0.1
Using addressable 2.7.0
Using bundler 1.17.3
Using colorator 1.1.0
Using concurrent-ruby 1.1.5
Using eventmachine 1.2.7
Using http_parser.rb 0.6.0
Using em-websocket 0.5.1
Using ffi 1.11.1
Using forwardable-extended 2.6.0
Using i18n 1.7.0
Using sassc 2.2.1
Using jekyll-sass-converter 2.0.1
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.0
Using listen 3.2.0
Using jekyll-watch 2.2.1
Using kramdown 2.1.0
Using kramdown-parser-gfm 1.1.0
Using liquid 4.0.3
Using mercenary 0.3.6
Using pathutil 0.16.2
Using rouge 3.12.0
Using safe_yaml 1.0.5
Using unicode-display_width 1.6.0
Using terminal-table 1.8.0
Using jekyll 4.0.0
Using jekyll-feed 0.12.1
Bundle complete! 2 Gemfile dependencies, 28 gems now installed.
Bundled gems are installed into `/usr/local/bundle`
$ jekyll build --trace -d public/
Configuration file: /builds/unveiled_adri/jekyll_project/_config.yml
/usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/theme.rb:76:in `rescue in gemspec': The jekyll-theme-basically-basic theme could not be found. (Jekyll::Errors::MissingDependencyException)
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/theme.rb:73:in `gemspec'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/theme.rb:18:in `root'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/theme.rb:12:in `initialize'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:487:in `new'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:487:in `configure_theme'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:58:in `config='
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:23:in `initialize'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:30:in `new'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:30:in `process'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `block in process_with_graceful_fail'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `each'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `process_with_graceful_fail'
    from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
    from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
    from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
    from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
    from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
    from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
    from /usr/local/bundle/gems/jekyll-4.0.0/exe/jekyll:15:in `<top (required)>'
    from /usr/local/bundle/bin/jekyll:23:in `load'
    from /usr/local/bundle/bin/jekyll:23:in `<main>'
ERROR: Job failed: exit code 1

结论

我已经尝试了所有方法,但在部署的最后一点,我完全迷失了方向。我可以解决安装问题,但现在我不知道如何解决。

【问题讨论】:

【参考方案1】:

在您的Gemfile 中,取消注释#gem "jekyll-theme-basically-basic" 以阅读gem "jekyll-theme-basically-basic"

由于某些原因,在您的.gitlab-ci.yml 中,所有gem install ... 都是无用的,而正是bundle install 完成了所需的工作。

【讨论】:

之所以把Gemfile里的gem行都注释掉是因为gitlab里的vm说找不到gem源码里的gem。这对我来说很奇怪,因为在我的 Gemfile 中,gem 源是默认源,我还检查了该源中是否存在 gem。此外,这一切都在我的本地虚拟机上运行。因此,我找到了在 .gitlab-ci.yml 中安装 gems 所需的解决方案,但后来我遇到了这个错误。你觉得那我应该怎么做? 无论如何我会再试试你说的,也许魔法会发生@David Jacquel 我会将您的答案标记为解决方案,因为它实际上解决了问题。现在的问题是网页以一种奇怪的方式部署。我的意思是,css 坏了,一些链接不起作用。如果您想查看,您可以查看存储库的 gitlab 页面,也许您知道发生了什么。无论如何,我会在这里打开另一个帖子来询问这个问题 @AdriánJaramillo 您需要正确设置 url 才能使 CSS url 可访问。

以上是关于使用带有 gitlab 页面的 jekyll,它说当它使用 gitlab CI 部署网站时找不到主题,我已经安装了它的主要内容,如果未能解决你的问题,请参考以下文章

带有 Jekyll 和 Liquid 的排序导航菜单

通过 Jekyll 发布 GITLAB 问题

带有 Jekyll 的 Github 页面未在 .md 帖子中显示图像

检查带有/ Jekyll Liquid 的页面上是不是存在带有/ class x 的 div

Github 页面上的图像显示错误 - 使用 Jekyll

GitLab 页面自定义域允许 www