Skip to content

Instantly share code, notes, and snippets.

@whitetigle
Last active May 17, 2022 21:00
Show Gist options
  • Save whitetigle/d133e84094a76f9c189d6bec0111ea21 to your computer and use it in GitHub Desktop.
Save whitetigle/d133e84094a76f9c189d6bec0111ea21 to your computer and use it in GitHub Desktop.
Deploying a Single Page Application to Gitlab

Deploying a Single Page Application to Gitlab

Last week I spent some time trying to deploy a SPA on Gitlab. It took me a few hours because the documentation even if complete was not that easy to read. (at least for me)

Preparation

The following steps are mostly taken from this guide

  1. Create an account in Gitlab (or use an existing one)
  2. Create a new git project to host your web site
  3. Pull the projet
  4. add a public folder at the root of this project. This is the folder that will be used to publish our SPA
  5. add a .gitlab-ci.yml file at the root of this project. This file will instruct Gitlab CI/CD pipeline how to deploy our web site.
  6. Copy the following content into that file:
image: alpine:latest

pages:
  stage: deploy
  script:
    - mkdir test
    - mv public/* test
    - rm -rf public
    - mkdir public
    - mv test/* public
  artifacts:
    paths:
      - public
  only:
    - master
  1. commit and push your project to GitLab. Since there's a .gitlab-ci.yml file, it will trigger automatically a deploy job.
  2. Check the deployment job in the CI/CD menu:
  3. go to Settings>Pages et voilà. Your page should be published at address https://username.gitlab.io/myproject

Domain + SSL

  1. go to Settings>Pages and click on new domain
  2. Enter fullchain pem certificate and private key pem (be sure that your pem is full : base + intermediates I lost some time figuring out why it wouldn't work)
  3. Validate

DNS

  1. Now SSL has been setup, in the Settings>Pages page click on the details button under the domains
  2. copy the DNS string and update your DNS accordingly.
  3. make some coffee, read some great articles about Fable and try to access your SPA using your secured domain address (https://mydomain.tld)

Notes

If the index.html links to failed files (for instance a missing bundle.js...) the deployment will fail. At least it appears that it checks the integrity of the web site from the index.html file. (need some more doc on that though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment