0

Everything I've tried already didn't work for me (several sites and videos on youtube). Please, link me with another useful videos or help me understand this process. I found it much easier to deploy the site to GitHub with gh-pages, but I have problems with deploying to GitLab.

Already tried to push my project to GitLab and then CI/CD > Pipelines, where my project built successfully, then Settings > Pages and still 404 (waited more than 1 day). I have installed the ".gitlab-ci.yml" file (with basic HTML settings).

BTW, should I push the pre-built site or already converted?

Right now it is like this:

 - src
    - fonts
    - html
    - images
    - js
    - sass
    index.html
 .gitattributes
 .gitignore
 .gitlab-ci.yml
 LICENSE
 README.md

EDIT: I found solution for my specific problem. As GitLab Pages is a static hosting, before deploying sass files, you need to compile them first and only after you should deploy. Here is my gitlab-ci.yml file.

image: alpine:latest

stages:
    - compile
    - deploy
    
compile:
  stage: compile
  image: node:8.15-alpine
  script:
    - yarn global add node-sass
    - node-sass ./src/sass/main.scss ./src/css/styles.css --style compressed
  only:
      - master
  artifacts:
    paths:
      - ./src/css

pages:
  stage: deploy
  script:
  - mv src/ public
  artifacts:
    paths:
    - public

At stage compile notice how i point to my main.scss file path which could be different for you. Also there is path for compiled file styles.css (you need to use your file name of css styles, that is mentioned in <head> section of your main html file). Check path at the artifacts line as well, so you could properly direct your files. For compilation, as you can see, i'm using Yarn (there is no need to install anything to use it). After compiling my sass file, the next stage is to deploy, which works for me as planned.

Hope it helps you as well!

Alex Bird
  • 11
  • 5

1 Answers1

0

To successfully host your page on Gitlab you need to move your sources to public directory and archive it. Example .gitlab-ci.yml could be:

image: alpine:latest

pages:
  stage: deploy
  script:
  - mv src/ public
  artifacts:
    paths:
    - public
makozaki
  • 3,772
  • 4
  • 23
  • 47
  • So, i should archive my public directory everytime i want to deploy my site? And it will be like this public.zip, right? – Alex Bird Oct 01 '20 at 20:33
  • Yeah, there is `artifacts.zip` with your artifacts. – makozaki Oct 02 '20 at 11:03
  • Thanks, i'll try it. By now, i can see only html version of my site and working on icnluding css somehow. – Alex Bird Oct 02 '20 at 20:44
  • Still after trying to add new folder named public with artifacts didn't work for me. It feels like i'm doing something so wrong. There is only html version. – Alex Bird Oct 03 '20 at 06:40
  • Note that gitlab pages is a static hosting. It won't provide any functionality that requires framework installation. I don't know much about sass but from quick research it requires some installation on server then it might not work on gitlab pages hosting. Is there a way to transform your page to pure html/css/js form? If so then you could transform it in you `.gitlab-ci.yml` and publish to pages only static form of your page. – makozaki Oct 03 '20 at 06:57
  • 1
    Yeah, it looks like more logical step to do. Thank you so much. It really helped me a lot. – Alex Bird Oct 04 '20 at 03:33