How to setup a CDN under Gitlab Organization

Hello my name is Luiz i'm a software engineer based in brazil, in this article i'll show you how to setup a static files CDN under Gitlab Organization using Gitlab Pages.
What is Gitlab Pages?
Gitlab Pages is a feature that allows you to host static websites directly from your Gitlab repositories. It’s similar to Github Pages, but with a few key differences:
- Gitlab Pages supports HTTPS for custom domains with Let’s Encrypt, while Github Pages only supports HTTPS for github.io subdomains.
- Gitlab Pages supports custom domains for private repositories, while Github Pages only supports custom domains for public repositories.
How to setup a CDN under Gitlab Organization
First of all you need to create a Gitlab Organization, if you don't have one yet, you can create one here.
After that you need to create a new project, you can do that here.
Now you need to create a new project with a setup and structure like this:
├── .gitlab-ci.yml
├── public/
│ └── Here you put your static files like images, css, js, etc... to be served by the CDN
└── README.md
After that you need to create a new file called .gitlab-ci.yml and put this code inside:
image: alpine:latest
pages:
stage: deploy
script:
- echo "Nothing to do..."
artifacts:
paths:
- public
only:
- main
This file will tell Gitlab to deploy the public folder to Gitlab Pages.
Now you need to go to your project settings and enable Gitlab Pages, you can do that here. And make pages available to everyone.
How to use the CDN
As i told before this CDN is using the Gitlab Pages, so in order to access the project you need to go to https://YOUR_ORGANIZATION_NAME.gitlab.io/YOUR_PROJECT_NAME/.
How to use a custom domain
In order to use a custom domain you need to go to your project settings and add your custom domain, you can do that here.
After that you need to go to your domain provider and add a new CNAME record pointing to YOUR_ORGANIZATION_NAME.gitlab.io.





