How to get pelican site generate on GitLab Pages when continuous integration passes and artifacts are being built?

空扰寡人 提交于 2021-01-29 08:51:47

问题


I used pelican as the static site generator to build a static site. I wanted to host it on GitLab Pages and let the site generate with GitLab's continuous integration with Makefile.

The site successfully builds locally as well as on GitLab via its CI/CD pipeline. The build code passes with artifacts uploaded and job succeeded. The content files are built and produced in the public folder.

Somehow, after the build being passed and artifacts being uploaded in public folder as desired, it was expected to have the static site hosted on the user pages of GitLab Pages like username.gitlab.io/projectname.

This did not work even after 15+ hours though the recommended wait time was fifteen minutes to half an hour.

Hosting on a custom subdomain was also tried. The subdomain is verified, yet the site is not being generated.

For reference, minimal code in use is mentioned below.

.gitlab-ci.yml

# default to using the latest Python docker image for builds
image: python:3.7.0

# our build job installs the Python requirements and Pelican
# plugins, then runs ``make publish`` to generate the output
build:
  stage: deploy
  script:
  - apt-get update -qq && apt-get install -y -qq python python-pip
  - python -v
  - pip install  -r requirements.txt
  - git clone --recursive https://github.com/getpelican/pelican-plugins ../plugins
  - pelican -s publishconf.py
  - make publish
# specify the artifacts to save
  artifacts:
    paths:
      - public/
  only:
  - master

publishconf.py

#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
import os

AUTHOR = 'Tanya Jain'
SITENAME = 'Tanya Jain'
SITEURL = '/public'
DESCRIPTION = ''
THEME = 'themes/stellarAdventurerTheme'

PATH = 'content'
OUTPUT_PATH = 'public'

pelicanconf.py

#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
import os

AUTHOR = 'Tanya Jain'
SITENAME = 'Tanya Jain'
SITEURL = '/public'
DESCRIPTION = ''
THEME = 'themes/stellarAdventurerTheme'

PATH = 'content'
OUTPUT_PATH = 'public'

Makefile

PY?=python3
PELICAN?=pelican
PELICANOPTS=

BASEDIR=$(CURDIR)
INPUTDIR=$(BASEDIR)/content
OUTPUTDIR=$(BASEDIR)/public
CONFFILE=$(BASEDIR)/pelicanconf.py
PUBLISHCONF=$(BASEDIR)/publishconf.py

FTP_HOST=localhost
FTP_USER=anonymous
FTP_TARGET_DIR=/

SSH_HOST=localhost
SSH_PORT=22
SSH_USER=root
SSH_TARGET_DIR=/var/www

Kindly help out on how to generate the site on GitLab Pages!

Update 1:

Tried these changes which too did not work. Yet, I believe the changes are to be made in the pelican settings and not the GitLab's YAML.

pelicanconf.py

SITEURL = ''

publishconf.py

SITEURL = 'http://subdomain.example.com'

回答1:


Didn't have the reputation to comment and ask for clarification. Hence, writing the question/answer in the answer body.

By default, pelican uses relative paths which are easy to use with the python SimpleHTTPServer. For Gitlab pages, you have to use absolute URLs. Do check if you have used absolute URL's maybe that's the issue.

# In Publishconf.py
SITEURL = 'https://username.gitlab.io/pelican2048'

Reference: #1

Source: Static website using Pelican, hosting on Gitlab

Update: I am sure you have seen this, but do crosscheck https://gitlab.com/pages/pelican and https://mister-gold.pro/posts/en/deploy-pelican-on-gitlab-pages/

Hope this helps!




回答2:


Thanks a lot for helping out! I have solved the problem. The error was due to mentioning the job as build in .gitlab-ci.yml and also, missing of the job pages. Using pages as a job is a necessity of the GitLab Pages to be deployed, which can further read in the references mentioned. Hence, the correct script would be:

image: python:3.7.0

pages:
    stage: deploy
    script:
    - apt-get update -qq && apt-get install -y -qq python python-pip
    - python -v
    - pip install  -r requirements.txt
    - git clone --recursive https://github.com/getpelican/pelican-plugins ../plugins
    - pelican -s publishconf.py
    - make publish
    artifacts:
        paths:
            - public/
    only:
    - master

References:

  1. Stackoverflow: GitLab Pages deployment step fails after successfull build
  2. Exploring GitLab Pages (documentation)
  3. Creating and Tweaking GitLab CI/CD for GitLab Pages


来源:https://stackoverflow.com/questions/57450732/how-to-get-pelican-site-generate-on-gitlab-pages-when-continuous-integration-pas

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