Deploy Astro to Gitlab Pages

Here are some instructions on how to deploy an astro.build site to Gitlab pages.

Gitlab pages deployment is controlleed via your .gitlab-ci.yml file. Everything is in there. The file contents might look like this:

image: node:19.1.0

pages:
  script:
    - npm ci
    - npm run build
    - rm -rf public
    - mv dist public
  artifacts:
    paths:
      - public
  cache:
    paths:
      - node_modules
    key: project
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Notable parts:

  • image: node - This deployment will be based on node.js.

  • pages: - This is the section specific to your Gitlab pages deployment

  • script: - The commands to run when the pages target it executed.

  • npm run build - This is the astro-related npm-script for generating the static site.